static prop_t * setting_add_cstr(prop_t *parent, const char *title, const char *type, int flags) { prop_t *p = setting_get(parent, flags); prop_set_string(prop_create(prop_create(p, "metadata"), "title"), title); prop_set_string(prop_create(p, "type"), type); return p; }
static prop_t * setting_add(prop_t *parent, prop_t *title, const char *type, int flags) { prop_t *p = setting_get(parent, flags); if(title != NULL) set_title2(p, title); prop_set_string(prop_create(p, "type"), type); return p; }
void load_libs(void) { struct dirent *entry; DIR *extdir; void *lib; initfun initializer; const char *ext; wchar_t path[512] = { 0 }; char *asciipath; _api *a = malloc(sizeof(_api)); chatenv *c = malloc(sizeof(chatenv)); c->get_users = rget_users; if (a == NULL) HANDLE_ERR("Unable to allocate memory for _api"); a->hook_msg = hook_msg; a->hook_join = hook_join; a->hook_part = hook_part; a->unhook = ev_unhook; a->events = ev_get_global(); a->setting_store = setting_store; a->setting_get = setting_get; a->chatenv = c; wchar_t *exts = setting_get(BKEY_EXTENSIONS_DIR); if (exts == NULL) { free(a); return; } char *asciidir = calloc(1, wcslen(exts) * 4); wcstombs(asciidir, exts, wcslen(exts) * 4); extdir = opendir(asciidir); if (extdir == NULL) { perror("Couldn't open extension directory"); exit(EXIT_FAILURE); return; } while ((entry = readdir(extdir))) { ext = get_extension(entry->d_name); if (strcmp(ext, "so") == 0) { wmemset(path, 0, 512); swprintf(path, 511, L"%s/%s", asciidir, entry->d_name); asciipath = calloc(1, 1022); wcstombs(asciipath, path, 1022); lib = dlopen(asciipath, RTLD_NOW); free(asciipath); if (lib == NULL) { wprintf(L"Unable to read %ls, invalid library\n", path); continue; } initializer = (initfun)dlsym(lib, BINIT_FUNCTION); if (initializer == NULL) { wprintf(L"Symbol %s not found in %ls, might want to fix that.\n", BINIT_FUNCTION, path); continue; } initializer(a); } } free(asciidir); closedir(extdir); }
void exec_commands(damn *d, packet *p) { if (wcscmp(p->command, L"recv") != 0) return; if (wcsncmp(p->body, L"admin", 5) == 0 && wcschr(p->body, L'\n') != NULL) return; context *ctx = malloc(sizeof(context)); ctx->damn = d; ctx->pkt = p; packet *sp = pkt_subpacket(p); if(wcscmp(sp->command, L"join") == 0) { ctx->msg = NULL; ctx->sender = sp->subcommand; ev_trigger(L"cmd.join", ctx); return; } if(wcscmp(sp->command, L"part") == 0) { ctx->msg = NULL; ctx->sender = sp->subcommand; ev_trigger(L"cmd.part", ctx); return; } bool triggered = 0; wchar_t *bod; size_t len = 0; wchar_t *cmdname; wchar_t *uname = setting_get(BKEY_USERNAME); size_t uname_len = wcslen(uname); wchar_t *trigger = setting_get(BKEY_TRIGGER); if (wmemcmp(trigger, sp->body, wcslen(trigger)) == 0) { triggered = true; bod = sp->body + wcslen(trigger); } else if (wmemcmp(uname, sp->body, uname_len) == 0 && sp->body[uname_len] == ':' && sp->body[uname_len + 1] == ' ') { triggered = true; bod = sp->body + uname_len + 2; } wchar_t *sender = pkt_getarg(sp, L"from"); unsigned char senderaccess = sender == NULL ? 0 : access_get(sender); if (triggered) { while (bod[len++] > 32); if (len > 1) { cmdname = calloc(1, sizeof(wchar_t) * (len + 10)); if (cmdname == NULL) HANDLE_ERR("Unable to allocate command name"); swprintf(cmdname, len + 9, L"cmd.trig.%ls", bod); ctx->msg = bod + len; ctx->sender = sender; ev_trigger_priv(cmdname, ctx, senderaccess); ctx = malloc(sizeof(context)); ctx->damn = d; ctx->pkt = p; } } ctx->msg = sp->body; ctx->sender = sender; wchar_t *ident = calloc(1, sizeof(wchar_t) * (wcslen(sp->body) + 13)); if (ident == NULL) perror("Unable to allocate memory for command ID"); swprintf(ident, wcslen(sp->body) + 12, L"cmd.notrig.%ls", sp->body); ev_trigger_priv(ident, ctx, senderaccess); ev_trigger_priv(L"cmd.notrig", ctx, senderaccess); free(ident); if(p->ref == 0) free(ctx); }
isc_result_t setting_get_bool(const char *const name, const settings_set_t *const set, isc_boolean_t *target) { return setting_get(name, ST_BOOLEAN, set, target); }
isc_result_t setting_get_str(const char *const name, const settings_set_t *const set, const char **target) { return setting_get(name, ST_STRING, set, target); }
isc_result_t setting_get_uint(const char *const name, const settings_set_t *const set, isc_uint32_t *target) { return setting_get(name, ST_UNSIGNED_INTEGER, set, target); }