char *make_string_var(const char *var_name) { int cnt, msv_index; char *ret = NULL; char *copy; copy = LOCAL_COPY(var_name); upper(copy); if ((find_fixed_array_item (irc_variable, sizeof(IrcVariable), NUMBER_OF_VARIABLES, copy, &cnt, &msv_index) == NULL)) return NULL; if (cnt >= 0) return NULL; switch (irc_variable[msv_index].type) { case STR_TYPE_VAR: ret = m_strdup(irc_variable[msv_index].string); break; case INT_TYPE_VAR: ret = m_strdup(ltoa(irc_variable[msv_index].integer)); break; case BOOL_TYPE_VAR: ret = m_strdup(var_settings[irc_variable[msv_index].integer]); break; case CHAR_TYPE_VAR: ret = m_dupchar(irc_variable[msv_index].integer); break; } return ret; }
char* getInfo(int request) { #define NAME_LENGTH 40 char buffer[NAME_LENGTH]; char* ptr; if(request == NL_ASK_NAME) message = "Enter your name: "; else if(request == NL_ASK_IP) message = "dest:port: "; else if(request == NL_ASK_FILE) message = "File to send: "; else// if(request == NL_ASK_MESSAGE) message = "Enter your message: "; /* else message = "Unknown request: ";*/ redraw(0); getnstr(buffer, NAME_LENGTH); message = NULL; if((ptr = strchr(buffer, '\n')) != NULL) *ptr = '\0'; if(request == NL_ASK_NAME) { free(my_name); my_name = m_strdup(buffer); } return m_strdup(buffer); }
/* Connect via TCP to a host. */ struct dropbear_progress_connection *connect_remote(const char* remotehost, const char* remoteport, connect_callback cb, void* cb_data) { struct dropbear_progress_connection *c = NULL; int err; struct addrinfo hints; c = m_malloc(sizeof(*c)); c->remotehost = m_strdup(remotehost); c->remoteport = m_strdup(remoteport); c->sock = -1; c->cb = cb; c->cb_data = cb_data; list_append(&ses.conn_pending, c); memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_UNSPEC; err = getaddrinfo(remotehost, remoteport, &hints, &c->res); if (err) { int len; len = 100 + strlen(gai_strerror(err)); c->errstring = (char*)m_malloc(len); snprintf(c->errstring, len, "Error resolving '%s' port '%s'. %s", remotehost, remoteport, gai_strerror(err)); TRACE(("Error resolving: %s", gai_strerror(err))) } else {
static unsigned char* get_response(unsigned char* prompt) { FILE* tty = NULL; unsigned char* response = NULL; /* not a password, but a reasonable limit */ char buf[DROPBEAR_MAX_CLI_PASS]; char* ret = NULL; fprintf(stderr, "%s", prompt); tty = fopen(_PATH_TTY, "r"); if (tty) { ret = fgets(buf, sizeof(buf), tty); fclose(tty); } else { ret = fgets(buf, sizeof(buf), stdin); } if (ret == NULL) { response = (unsigned char*)m_strdup(""); } else { unsigned int buflen = strlen(buf); /* fgets includes newlines */ if (buflen > 0 && buf[buflen-1] == '\n') buf[buflen-1] = '\0'; response = (unsigned char*)m_strdup(buf); } m_burn(buf, sizeof(buf)); return response; }
static void addportandaddress(char* spec) { char *myspec = NULL; if (svr_opts.portcount < DROPBEAR_MAX_PORTS) { /* We don't free it, it becomes part of the runopt state */ myspec = m_strdup(spec); /* search for ':', that separates address and port */ svr_opts.ports[svr_opts.portcount] = strchr(myspec, ':'); if (svr_opts.ports[svr_opts.portcount] == NULL) { /* no ':' -> the whole string specifies just a port */ svr_opts.ports[svr_opts.portcount] = myspec; } else { /* Split the address/port */ svr_opts.ports[svr_opts.portcount][0] = '\0'; svr_opts.ports[svr_opts.portcount]++; svr_opts.addresses[svr_opts.portcount] = myspec; } if (svr_opts.addresses[svr_opts.portcount] == NULL) { /* no address given -> fill in the default address */ svr_opts.addresses[svr_opts.portcount] = m_strdup(DROPBEAR_DEFADDRESS); } if (svr_opts.ports[svr_opts.portcount][0] == '\0') { /* empty port -> exit */ dropbear_exit("Bad port"); } svr_opts.portcount++; } }
char *my_itoa_base(int nbr, char *base, int pad) { int i; char buf[256]; buf[0] = 0; if (!base || my_strlen(base) <= 1) return (m_strdup(buf)); if (nbr == 0) { i = 0; while (i < pad) { buf[i] = base[0]; i += 1; } buf[i] = 0; return (m_strdup(buf)); } if (nbr < 0) { buf[0] = '-'; nbr = -nbr; write_positive_nbr(buf + 1, nbr, base, pad); } else { write_positive_nbr(buf, nbr, base, pad); } return m_strdup(buf); }
/* get_clean_ref_token: * Given a text, extracts the clean ref token, which either has to be * surrounded by "ss#..", inside a <a name=".." tag, or without any * html characters around. Otherwise returns an empty string. The * returned string has to be freed always. */ char *get_clean_ref_token(const char *text) { char *buf, *t; const char *pname, *pcross; pname = strstr(text, "<a name=\""); pcross = strstr(text, "ss#"); if (pname && pcross) { /* Take the first one */ if (pname < pcross) pcross = 0; else pname = 0; } if (pname) { buf = m_strdup(pname + 9); t = strchr(buf, '"'); *t = 0; } else if (pcross) { buf = m_strdup(pcross + 3); t = strchr(buf, '"'); *t = 0; } else if (!strchr(text, '<') && !strchr(text, '>')) buf = m_strdup(text); else { /* this is mainly for debugging */ printf("'%s' was rejected as clean ref token\n", text); buf = m_strdup(""); } assert(buf); return buf; }
struct match_node * match_node_new(const char *name, const char *type, struct match_node *next) { struct match_node *node; node = m_malloc(sizeof(*node)); node->next = next; node->filename = m_strdup(name); node->filetype = m_strdup(type); return node; }
static void addportandaddress(const char* spec) { char *spec_copy = NULL, *myspec = NULL, *port = NULL, *address = NULL; if (svr_opts.portcount < DROPBEAR_MAX_PORTS) { /* We don't free it, it becomes part of the runopt state */ spec_copy = m_strdup(spec); myspec = spec_copy; if (myspec[0] == '[') { myspec++; port = strchr(myspec, ']'); if (!port) { /* Unmatched [ -> exit */ dropbear_exit("Bad listen address"); } port[0] = '\0'; port++; if (port[0] != ':') { /* Missing port -> exit */ dropbear_exit("Missing port"); } } else { /* search for ':', that separates address and port */ port = strrchr(myspec, ':'); } if (!port) { /* no ':' -> the whole string specifies just a port */ port = myspec; } else { /* Split the address/port */ port[0] = '\0'; port++; address = myspec; } if (!address) { /* no address given -> fill in the default address */ address = DROPBEAR_DEFADDRESS; } if (port[0] == '\0') { /* empty port -> exit */ dropbear_exit("Bad port"); } svr_opts.ports[svr_opts.portcount] = m_strdup(port); svr_opts.addresses[svr_opts.portcount] = m_strdup(address); svr_opts.portcount++; m_free(spec_copy); } }
void add_to_a_list(char *thestring, int thetype, char *nick, char *channels, char *reason, int shitlevel) { ShitList *sremove = NULL; int scount = 0; switch(thetype) { case SHITLIST_ADD: { if (!(sremove = nickinshit(nick, thestring))) { shit_count++; sremove = (ShitList *) new_malloc(sizeof(ShitList)); sremove->level = shitlevel; sremove->reason = m_strdup(reason); sremove->channels = m_strdup(channels); sremove->filter = m_sprintf("%s!%s", nick, thestring); add_to_list((List **)&shitlist_list, (List *)sremove); sync_whowas_addshit(sremove); sync_shitlist(sremove, 1); if (shitlevel == PERM_IGNORE) ignore_nickname(sremove->filter, IGNORE_ALL, 0); bitchsay("Adding %s!%s to Shitlist", nick, thestring); } else bitchsay ("%s!%s already on my Shitlist", nick, thestring); break; } case SHITLIST_REMOVE: { char *s_str; s_str = m_sprintf("%s!%s", nick, thestring); while ((sremove = (ShitList *)removewild_from_list((List **)&shitlist_list, s_str))) { shit_count--; scount++; if (sremove->level == PERM_IGNORE) ignore_nickname(sremove->filter, IGNORE_ALL, IGNORE_REMOVE); sync_whowas_unshit(sremove); sync_shitlist(sremove, 0); new_free(&sremove->filter); new_free(&sremove->reason); new_free(&sremove->channels); new_free((char **)&sremove); bitchsay("Deleting %s!%s from Shitlist", nick, thestring); } if (!scount) bitchsay("Didnt find %s!%s on the Shitlist", nick, thestring); new_free(&s_str); break; } } }
char *get_cset(char *var, ChannelList *chan, char *value) { int var_index, cnt = 0; var_index = find_cset_variable(cset_array, var, &cnt); if (cnt == 1) { char s[81]; CSetArray *var; var = &(cset_array[var_index]); *s = 0; switch (var->type) { case BOOL_TYPE_VAR: { strcpy(s, get_cset_int_var(chan->csets, var_index)?var_settings[ON] : var_settings[OFF]); if (value) { int val = -1; if (!my_stricmp(value, on)) val = 1; else if (!my_stricmp(value, off)) val = 0; else { if (isdigit((unsigned char)*value)) val = (int)(*value - '0'); } if (val != -1) set_cset_int_var(chan->csets, var_index, val); } break; } case INT_TYPE_VAR: { strncpy(s, ltoa(get_cset_int_var(chan->csets, var_index)), 30); if (value && isdigit((unsigned char)*value)) set_cset_int_var(chan->csets, var_index, my_atol(value)); break; } case STR_TYPE_VAR: { char *t; t = m_strdup(get_cset_str_var(chan->csets, var_index)); if (value) set_cset_str_var(chan->csets, var_index, value); return t; } } return m_strdup(s && *s ? s : empty_string); } return m_strdup(empty_string); }
static void tar_entry_copy(struct tar_entry *dst, struct tar_entry *src) { memcpy(dst, src, sizeof(struct tar_entry)); dst->name = m_strdup(src->name); dst->linkname = m_strdup(src->linkname); if (src->stat.uname) dst->stat.uname = m_strdup(src->stat.uname); if (src->stat.gname) dst->stat.gname = m_strdup(src->stat.gname); }
void createTask(char* title, char* description, struct tm startDate, struct tm endDate, struct error* err) { err->error = NO_ERROR; /* * 1. Establish connection with db * 2. Execute insert statement * Always check for errors **/ if(!db) { if(!initializeConnection(NULL)) { exit(1); } } if(!title || !description) { err->error = DATABASE_INSERT; err->description= sqlite3_errmsg(db); return ; } const char* unused; sqlite3_stmt* statement; char* sql = "INSERT INTO TASKS(TITLE, DESCRIPTION, START_DATE, END_DATE) VALUES(?,?,?,?)"; int rc = sqlite3_prepare(db, sql, -1, &statement, &unused); if(!rc == SQLITE_OK) { err->error = DATABASE_INSERT; err->description= sqlite3_errmsg(db); return ; } sqlite3_bind_text(statement, 1, title, strlen(title), SQLITE_STATIC); sqlite3_bind_text(statement, 2, description, strlen(description), SQLITE_STATIC); char* st_date_str = m_strdup(asctime(&startDate)); sqlite3_bind_text(statement, 3, st_date_str, strlen(st_date_str)-1, SQLITE_STATIC); char* en_date_str = m_strdup(asctime(&endDate)); sqlite3_bind_text(statement, 4, en_date_str, strlen(en_date_str)-1, SQLITE_STATIC); sqlite3_step(statement); rc = sqlite3_finalize(statement); if(rc != SQLITE_OK) { err->error = DATABASE_INSERT; err->description = sqlite3_errmsg(db); } free(st_date_str); free(en_date_str); }
/* Set chansession command to the one forced * by any 'command' public key option. */ void svr_pubkey_set_forced_command(struct ChanSess *chansess) { if (ses.authstate.pubkey_options) { if (chansess->cmd) { /* original_command takes ownership */ chansess->original_command = chansess->cmd; } else { chansess->original_command = m_strdup(""); } chansess->cmd = m_strdup(ses.authstate.pubkey_options->forced_command); #ifdef LOG_COMMANDS dropbear_log(LOG_INFO, "Command forced to '%s'", chansess->original_command); #endif } }
void add_userhost_to_userlist(char *nick, char *uhost, char *channels, char *passwd, unsigned int flags) { UserList *uptr; uptr = new_malloc(sizeof(UserList)); uptr->nick = m_strdup(nick); uptr->host = m_strdup(uhost); uptr->channels = m_strdup(channels); if (passwd) malloc_strcpy(&uptr->password, passwd); uptr->flags = flags; uptr->time = now; add_userlist(uptr); sync_nicklist(uptr, 1); user_count++; }
Flooding *BX_add_name_to_floodlist(char *name, char *host, char *channel, HashEntry *list, unsigned int size) { Flooding *nptr; unsigned long hvalue = hash_nickname(name, size); nptr = (Flooding *)new_malloc(sizeof(Flooding)); nptr->next = (Flooding *) list[hvalue].list; nptr->name = m_strdup(name); nptr->host = m_strdup(host); list[hvalue].list = (void *) nptr; /* quick tally of nicks in chain in this array spot */ list[hvalue].links++; /* keep stats on hits to this array spot */ list[hvalue].hits++; return nptr; }
/* Checks a user provided comma-separated algorithm list for available * options. Any that are not acceptable are removed in-place. Returns the * number of valid algorithms. */ int check_user_algos(const char* user_algo_list, algo_type * algos, const char *algo_desc) { algo_type new_algos[MAX_PROPOSED_ALGO]; /* this has two passes. first we sweep through the given list of * algorithms and mark them as usable=2 in the algo_type[] array... */ int num_ret = 0; char *work_list = m_strdup(user_algo_list); char *last_name = work_list; char *c; for (c = work_list; *c; c++) { if (*c == ',') { *c = '\0'; try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret); c++; last_name = c; } } try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret); m_free(work_list); new_algos[num_ret].name = NULL; /* Copy one more as a blank delimiter */ memcpy(algos, new_algos, sizeof(*new_algos) * (num_ret+1)); return num_ret; }
void set_random_seed_file( const char *name ) { if( seed_file_name ) BUG(); seed_file_name = m_strdup( name ); }
/** * Generate the pathname for the destination binary package. * * If the pathname cannot be computed, because the destination is a directory, * then NULL will be returned. * * @param dir The directory from where to build the binary package. * @param dest The destination name, either a file or directory name. * @return The pathname for the package being built. */ static char * gen_dest_pathname(const char *dir, const char *dest) { if (dest) { struct stat dest_stab; if (stat(dest, &dest_stab)) { if (errno != ENOENT) ohshite(_("unable to check for existence of archive '%.250s'"), dest); } else if (S_ISDIR(dest_stab.st_mode)) { /* Need to compute the destination name from the package control file. */ return NULL; } return m_strdup(dest); } else { char *pathname; pathname = m_malloc(strlen(dir) + sizeof(DEBEXT)); strcpy(pathname, dir); path_trim_slash_slashdot(pathname); strcat(pathname, DEBEXT); return pathname; } }
static int statoverride_list(const char *const *argv) { struct fileiterator *iter; struct filenamenode *file; const char *thisarg; struct glob_node *glob_list = NULL; int ret = 1; while ((thisarg = *argv++)) { char *pattern = path_cleanup(thisarg); glob_list_prepend(&glob_list, pattern); } if (glob_list == NULL) glob_list_prepend(&glob_list, m_strdup("*")); iter = files_db_iter_new(); while ((file = files_db_iter_next(iter))) { struct glob_node *g; for (g = glob_list; g; g = g->next) { if (fnmatch(g->pattern, file->name, 0) == 0) { statdb_node_print(stdout, file); ret = 0; break; } } } files_db_iter_free(iter); glob_list_free(glob_list); return ret; }
CPlugin::CPlugin(NPP pNPInstance, int16_t argc, char* argn[], char* argv[]): m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(false), m_pScriptableObject(NULL) { #ifdef XP_WIN m_hWnd = NULL; #endif // code from npruntime, get browser version const char *ua = NPN_UserAgent(m_pNPInstance); strcpy(m_String, ua); // Here is an example of passing parameters from plugin to ScriptablePlugin // initialize id NPIdentifier code_id = NPN_GetStringIdentifier("code"); NPVariant v1; VOID_TO_NPVARIANT(v1); for (int16_t i = 0;i < argc;i++) { printf("%s = %s\n", argn[i], argv[i]); if (!strcmp(argn[i],"code")) { STRINGZ_TO_NPVARIANT(m_strdup(argv[i]),v1); } } NPObject *myobj = this->GetScriptableObject(); NPN_SetProperty(m_pNPInstance, myobj, code_id, &v1); NPN_ReleaseObject(myobj); }
char *get_help_topic(char *args, int helpfunc) { char *new_comm = NULL; int found = 0, i; char *others = NULL; new_comm = LOCAL_COPY(args); for (i = 0; helpfunc ? script_help[i] : help_index[i]; i++) { if (!my_strnicmp(helpfunc?script_help[i]->title:help_index[i]->title, new_comm, strlen(new_comm))) { int j; char *text = NULL; if (found++) { m_s3cat(&others, " , ", helpfunc?script_help[i]->title:help_index[i]->title); continue; } if (args && *args && do_hook(HELPTOPIC_LIST, "%s", args)) put_it("%s",convert_output_format("$G \002$0\002: Help on Topic: \002$1\002", version, args)); for (j = 0; ; j++) { if (helpfunc && (script_help[i] && script_help[i]->contents[j])) text = script_help[i]->contents[j]; else if (!helpfunc && (help_index[i] && help_index[i]->contents[j])) text = help_index[i]->contents[j]; else break; if (text && do_hook(HELPSUBJECT_LIST, "%s %s", new_comm, text)) { in_chelp++; put_it("%s", convert_output_format(text, NULL)); in_chelp--; } } text = helpfunc ?script_help[i]->relates:help_index[i]->relates; if (text && do_hook(HELPTOPIC_LIST, "%s", text)) put_it("%s", convert_output_format(text, NULL)); } else if (found) break; } if (!found) { if (do_hook(HELPTOPIC_LIST, "%s", args)) bitchsay("No help on %s", args); } if (others && found) { if (do_hook(HELPTOPIC_LIST, "%d %s", found, others)) put_it("Other %d subjects: %s", found - 1, others); } new_free(&others); if (helpfunc) return m_strdup(empty_string); return NULL; }
void add_new_fset(char *name, char *args) { if (args && *args) { IrcVariable *tmp = NULL; int cnt, loc; tmp = (IrcVariable *)find_array_item((Array *)&ext_fset_list, name, &cnt, &loc); if (!tmp || cnt >= 0) { tmp = new_malloc(sizeof(IrcVariable)); tmp->name = m_strdup(name); tmp->type = STR_TYPE_VAR; add_to_array((Array *)&ext_fset_list, (Array_item *)tmp); } malloc_strcpy(&tmp->string, args); } else { IrcVariable *tmp; if ((tmp = (IrcVariable *)remove_from_array((Array *)&ext_fset_list, name))) { new_free(&tmp->name); new_free(&tmp->string); new_free(&tmp); } } }
void trigproc_run_deferred(void) { jmp_buf ejbuf; char *pkgname; debug(dbg_triggers, "trigproc_run_deferred"); while (!pkg_queue_is_empty(&deferred)) { struct pkginfo *pkg; pkg = pkg_queue_pop(&deferred); if (!pkg) continue; pkgname = m_strdup(pkg_describe(pkg, pdo_foreign)); if (setjmp(ejbuf)) { pop_error_context(ehflag_bombout); free(pkgname); continue; } push_error_context_jump(&ejbuf, print_error_perpackage, pkgname); pkg->clientdata->trigprocdeferred = NULL; trigproc(pkg); pop_error_context(ehflag_normaltidy); free(pkgname); } }
static void new_key (int meta, unsigned chr, int type, int change, char *stuff) { /* * Create a map first time we bind into it. We have to do this * Because its possible to do /bind METAX-f when there is not * otherwise any key bound to METAX. */ if (!keys) return; if (!keys[meta]) new_metamap(meta); if (KEY(meta, chr)) { if (KEY(meta, chr)->stuff) new_free(&(KEY(meta, chr)->stuff)); if (KEY(meta, chr)->filename) new_free(&(KEY(meta, chr)->filename)); new_free(&(KEY(meta, chr))); KEY(meta, chr) = NULL; } if (type != 0) { KEY(meta, chr) = (KeyMap *)new_malloc(sizeof(KeyMap)); KEY(meta, chr)->key_index = type; KEY(meta, chr)->changed = change; /* KEY(meta, chr)->filename = m_strdup(current_package());*/ if (stuff) KEY(meta, chr)->stuff = m_strdup(stuff); else KEY(meta, chr)->stuff = NULL; } }
/*************** * Extract from a given path the filename component. * */ char * make_basename(const char *filepath) { char *p; if ( !(p=strrchr(filepath, DIRSEP_C)) ) #ifdef HAVE_DRIVE_LETTERS if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) #endif { return m_strdup(filepath); } return m_strdup(p+1); }
static char *_get_lang_name_from_file(const char *file_name, char *lang_code) { char *line; char buf1[256], buf2[256]; ASSERT(file_name); ASSERT(*file_name); ASSERT(lang_code); lang_code[0] = file_name[0]; lang_code[1] = file_name[1]; lang_code[2] = 0; get_executable_name(buf1, sizeof(buf1)); replace_filename(buf2, buf1, file_name, sizeof(buf2)); push_config_state(); set_config_file(buf2); line = m_strdup(get_config_string(0, "language_name", "")); pop_config_state(); if (*line) return line; free(line); return 0; }
static void _retrieve_available_languages(void) { int ret; struct al_ffblk info; _free_available_languages(); _available_languages = m_xmalloc(sizeof(char*)); TRACE("Entering retrieve section\n"); if (!(ret = al_findfirst("??text.cfg", &info, 0))) { while (!ret) { char lang_code[3]; char *lang_name = _get_lang_name_from_file(info.name, lang_code); TRACE("Found file %s\n", info.name); if (lang_name) { TRACE(" code %s, name %s\n", lang_code, lang_name); _available_languages = m_xrealloc(_available_languages, ((_num_available_languages + 1) * 2) * sizeof(char*)); _available_languages[_num_available_languages*2] = m_strdup(lang_code); _available_languages[_num_available_languages*2+1] = lang_name; _num_available_languages++; } ret = al_findnext(&info); } al_findclose(&info); } }
static void addhostkey(const char *keyfile) { if (svr_opts.num_hostkey_files >= MAX_HOSTKEYS) { dropbear_exit("Too many hostkeys"); } svr_opts.hostkey_files[svr_opts.num_hostkey_files] = m_strdup(keyfile); svr_opts.num_hostkey_files++; }
void nick_completion(char dumb, char *dumber) { char *q, *line; int i = -1; char *nick = NULL, *tmp; q = line = m_strdup(¤t_screen->input_buffer[MIN_POS]); if (in_completion == STATE_NORMAL) { i = word_count(line); nick = extract_words(line, i - 1, i); } if (nick) line[strlen(line) - strlen(nick)] = 0; else *line = 0; if ((tmp = getchannick(input_lastmsg, nick && *nick ? nick : NULL))) { malloc_strcat(&q, tmp); set_input(q); update_input(UPDATE_ALL); malloc_strcpy(&input_lastmsg, tmp); in_completion = STATE_COMPLETE; } new_free(&q); new_free(&nick); }