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; } }
void remove_csets_for_channel(CSetList *tmp) { new_free(&tmp->channel); new_free(&tmp->channel_log_file); new_free(&tmp->chanmode); new_free(&tmp); }
int delay_flush_all (void *arg, char *sub) { char buffer[BIG_BUFFER_SIZE+1]; char *args = (char *)arg; char *serv_num = NULL; char *channel = NULL; int ofs = from_server; channel = next_arg(args, &args); if ((serv_num = next_arg(args, &args))) from_server = atoi(serv_num); if (channel && *channel && mode_str && user) { sprintf(buffer, "MODE %s %s%s %s\r\n", channel, plus_mode, mode_str, user); push_len = strlen(buffer); add_mode_buffer(buffer, push_len); mode_str_len = 0; new_free(&mode_str); new_free(&user); memset(plus_mode, 0, sizeof(plus_mode)); push_len = 0; } flush_mode(NULL); new_free(&arg); from_server = ofs; return 0; }
int open_file_for_read (const char *filename) { char *dummy_filename = (char *) 0; struct epic_loadfile *elf; struct stat sb; File * fr; malloc_strcpy(&dummy_filename, filename); elf = uzfopen(&dummy_filename, ".", 1, &sb); new_free(&dummy_filename); if (!elf) { new_free(&elf); return -1; } if (sb.st_mode & 0111) { say("Cannot open %s -- executable file", filename); return -1; } fr=new_file(elf); return fr->id; }
/* * Unregister a filedesc for readable events * and close it down and free its input buffer */ int new_close (int des) { if (des < 0) return -1; if (FD_ISSET(des, &readables)) FD_CLR(des, &readables); if (FD_ISSET(des, &writables)) FD_CLR(des, &writables); if (FD_ISSET(des, &held_readables)) FD_CLR(des, &held_readables); if (FD_ISSET(des, &held_writables)) FD_CLR(des, &held_writables); if (io_rec) { if (io_rec[des]) new_free(&io_rec[des]->buffer); new_free((char **)&(io_rec[des])); } close(des); /* * If we're closing the highest fd in use, then we * want to adjust global_max_fd downward to the next highest fd. */ while ( global_max_fd >= 0 && !FD_ISSET(global_max_fd, &readables) && !FD_ISSET(global_max_fd, &held_readables)) global_max_fd--; return -1; }
static char * encrypt_by_prog (const unsigned char *str, size_t *len, Crypt *key) { char *ret = NULL, *input; char * args[3]; int iplen; args[0] = malloc_strdup(key->prog); args[1] = malloc_strdup("encrypt"); args[2] = NULL; input = malloc_strdup2(key->key, "\n"); iplen = strlen(input); new_realloc((void**)&input, *len + iplen); memmove(input + iplen, str, *len); *len += iplen; ret = exec_pipe(key->prog, input, len, args); new_free(&args[0]); new_free(&args[1]); new_free((char**)&input); new_realloc((void**)&ret, 1+*len); ret[*len] = 0; return ret; }
void add_mode(ChannelList *chan, char *mode, int plus, char *nick, char *reason, int max_modes) { char buffer[BIG_BUFFER_SIZE+1]; if (mode_len >= (IRCD_BUFFER_SIZE-100)) { flush_mode(chan); push_len = 0; } if (reason) { sprintf(buffer, "KICK %s %s :%s\r\n", chan->channel, nick, reason); push_len = strlen(buffer); add_mode_buffer(buffer, push_len); } else { mode_str_len++; strcat(plus_mode, plus ? "+" : "-"); malloc_strcat(&mode_str, mode); m_s3cat(&user, space, nick); if (mode_str_len >= max_modes) { sprintf(buffer, "MODE %s %s%s %s\r\n", chan->channel, plus_mode, mode_str, user); push_len = strlen(buffer); add_mode_buffer(buffer, push_len); new_free(&mode_str); new_free(&user); memset(plus_mode, 0, sizeof(plus_mode)); mode_str_len = push_len = 0; } } }
/* * delete_timer: clean up after a Timer that is no longer needed. * You must _not_ submit a Timer that is still on the schedule. * * Arguments: * ntimer - An unneeded Timer that is not on the Timer list. * Deleting a still-scheduled Timer is an error. */ static void delete_timer (Timer *otimer) { Timer *tmp; /* * First we make sure 'otimer' is not still scheduled * before we go free()ing it. * (This is a violation of the API, but we're forgiving) * (The other option is to make this return failure, but * since this is a void function, we'll just DTRT) */ for (tmp = PendingTimers; tmp; tmp = tmp->next) { if (tmp == otimer) { yell("delete_timer: Warning: Deleting a timer that " "is still scheduled. Unscheduling it."); unlink_timer(otimer); break; } } if (!otimer->callback) { new_free((char **)&otimer->command); new_free((char **)&otimer->subargs); } new_free(&otimer->ref); new_free((char **)&otimer); }
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); } } }
/* * history_match: using wild_match(), this finds the latest match in the * history file and returns it as the function result. Returns null if there * is no match. Note that this sticks a '*' at the end if one is not already * there. */ static char *history_match(char *match) { char *ptr; char *match_str = NULL; if (*(match + strlen(match) - 1) == '*') malloc_strcpy(&match_str, match); else { match_str = new_malloc(strlen(match) + 2); strcpy(match_str, match); strcat(match_str, "*"); } if (get_int_var(HISTORY_VAR)) { if ((last_dir == -1) || (tmp == (History *) NULL)) tmp = command_history_head; else tmp = tmp->next; for (; tmp; tmp = tmp->next) { ptr = tmp->stuff; while (ptr && strchr(get_string_var(CMDCHARS_VAR), *ptr)) ptr++; if (wild_match(match_str, ptr)) { new_free(&match_str); last_dir = PREV; return (tmp->stuff); } } } last_dir = -1; new_free(&match_str); return NULL; }
int ext2_read_directory(struct filesystem *fs, int dino, char *f) { /* read the directory inode in */ struct ext2_inode *inode = kmalloc(sizeof(*inode)); ext2_read_inode(fs, inode, dino); if (inode->type & 0x4000 == 0) return -ENOTDIR; /* the block pointers contain some 'struct ext2_dir's, so parse */ void *bbuf = kmalloc(EXT2_PRIV(fs)->blocksize); for (int i = 0; i < 12; i++) { ext2_read_block(fs, bbuf, inode->dbp[i]); struct ext2_dir *d = (void *)bbuf; if (d->size == 0 || d->namelength == 0) break; int r = 0; while (r < EXT2_PRIV(fs)->blocksize) { if (strncmp(&d->reserved + 1, f, d->namelength) == 0) { int k = d->inode; new_free(bbuf); return k; } r += d->size; if (d->size == 0 || d->namelength == 0) { goto c1; } d = (struct ext2_dir *)((uintptr_t)d + d->size); } c1:; } new_free(bbuf); return -ENOENT; }
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); }
static char * all_keys_for_dbm (int refnum) { Dbm * db; Datum k; char * retval = NULL; size_t clue = 0; char * x; if (!(db = lookup_dbm(refnum))) return NULL; k = sdbm_firstkey(db->db); x = Datum_to_string(k); malloc_strcat_wordlist_c(&retval, space, x, &clue); new_free(&x); for (;;) { k = sdbm_nextkey(db->db); if (k.dptr == NULL) break; x = Datum_to_string(k); malloc_strcat_wordlist_c(&retval, space, x, &clue); new_free(&x); } return retval; }
static void update_mail_level2_mbox (void) { Stat stat_buf; int status; int count; status = poll_mbox_status(&stat_buf); /* There is no mail */ if (status == 0) { mail_last_count = 0; if (mail_last_count_str) new_free(&mail_last_count_str); } /* If our count is invalid or there is new mail, recount mail */ else if (mail_last_count == -1 || status == 2) { /* So go ahead and recount the mails in mbox */ count = mbox_count(); if (count == 0) new_free(&mail_last_count_str); else { malloc_sprintf(&mail_last_count_str, "%d", count); /* * If there is new mail, or if we're switching to * /set mail 2, tell the user how many emails there are. */ if (count > mail_last_count) { /* This is to avoid $0 in /on mail being wrong. */ if (mail_last_count < 0) mail_last_count = 0; if (!mail_latch) { mail_latch++; if (do_hook(MAIL_LIST, "%d %d", count - mail_last_count, count)) { int lastlog_level = set_lastlog_msg_level(LOG_CRAP); say("You have new email."); set_lastlog_msg_level(lastlog_level); } mail_latch--; } } mbox_last_changed = stat_buf.st_ctime; mbox_last_size = stat_buf.st_size; mail_last_count = count; } } }
void remove_all(int type) { UserList *tmp; ShitList *tmp_s, *next_s; ChannelList *chan; NickList *nick; void *location = NULL; int i = 0; if (type == -1 || type == USERLIST_REMOVE) { int size = -1; while ((tmp = next_userlist(NULL, &size, &location))) { if ((tmp = find_userlist(tmp->host, tmp->channels, 1))) { new_free(&tmp->nick); new_free(&tmp->host); new_free(&tmp->channels); new_free(&tmp->password); new_free(&tmp->comment); new_free((char **)&tmp); } } user_count = 0; user_list = NULL; for (i = 0; i < server_list_size(); i ++) { for (chan = get_server_channels(i); chan; chan = chan->next) { for(nick = next_nicklist(chan,NULL); nick; nick = next_nicklist(chan, nick)) nick->userlist = NULL; } } } if (type == -1 || type == SHITLIST_REMOVE) { for (tmp_s = shitlist_list; tmp_s; tmp_s = next_s) { next_s = tmp_s->next; sync_shitlist(tmp_s, 0); new_free(&tmp_s->filter); new_free(&tmp_s->channels); new_free(&tmp_s->reason); new_free((char **)&tmp_s); } for (i = 0; i < server_list_size(); i ++) { for (chan = get_server_channels(i); chan; chan = chan->next) { for(nick = next_nicklist(chan,NULL); nick; nick = next_nicklist(chan, nick)) nick->shitlist = NULL; } } shit_count = 0; shitlist_list = NULL; } }
/* * add_to_log: add the given line to the log file. If no log file is open * this function does nothing. * (Note: "logref" should be -1 unless we are logging from a /log log, ie, * any place that is not inside logfiles.c) */ void add_to_log (int logref, FILE *fp, long winref, const unsigned char *line, int mangler, const char *rewriter) { char *local_line = NULL; int old_logref; static int recursive = 0; /* * I added "recursive" because this function should not * generate any output. But it might generate output if * the string expand was bogus below. I chose to "fix" this * by refusing to log anything recursively. The downside * is any errors won't get logged, which may or may not be * a problem, I haven't decided yet. */ if (recursive > 0) return; if (!fp || inhibit_logging) return; recursive++; old_logref = current_log_refnum; current_log_refnum = logref; /* Do this first */ /* Either do mangling or /set no_control_log, but never both! */ if (mangler == 0) mangler = logfile_line_mangler; else if (get_int_var(NO_CONTROL_LOG_VAR)) mangler |= STRIP_UNPRINTABLE; if (mangler) local_line = new_normalize_string(line, 1, mangler); else local_line = malloc_strdup(line); if (rewriter == NULL) rewriter = get_string_var(LOG_REWRITE_VAR); if (rewriter) { char *prepend_exp; char argstuff[10240]; /* First, create the $* list for the expando */ snprintf(argstuff, 10240, "%ld %s", winref, local_line); new_free(&local_line); /* Now expand the expando with the above $* */ prepend_exp = expand_alias(rewriter, argstuff); local_line = prepend_exp; } fprintf(fp, "%s\n", local_line); fflush(fp); new_free(&local_line); current_log_refnum = old_logref; recursive--; }
/* * delete_timer: */ static void delete_timer (Timer *otimer) { if (!otimer->callback) { new_free((char **)&otimer->command); new_free((char **)&otimer->subargs); } new_free((char **)&otimer); }
static Logfile * logfile_remove (Logfile *log, char **args) { char *arg = next_arg(*args, args); char *ptr; WNickList *new_nl; int i; if (!log) { say("REMOVE: You need to specify a logfile first"); return NULL; } if (!arg) say("Remove: Remove nicknames/channels logged to this file"); else while (arg) { if ((ptr = strchr(arg, ',')) != NULL) *ptr++ = 0; if (log->type == LOG_TARGETS) { if ((new_nl = (WNickList *)remove_from_list((List **)&(log->targets), arg))) { say("Removed %s from log target list", new_nl->nick); new_free(&new_nl->nick); new_free((char **)&new_nl); } else say("%s is not on the list for this log!", arg); } else if (log->type == LOG_SERVERS || log->type == LOG_WINDOWS) { int refnum = my_atol(ptr); for (i = 0; i < MAX_TARGETS; i++) { if (log->refnums[i] == refnum) { say("Removed %d to log refnum list", refnum); log->refnums[i] = -1; break; } } if (i >= MAX_TARGETS) say("%s is not on the refnum list for this log!", arg); } arg = ptr; } return log; }
/* free list of interfaces */ static void iflist_free(struct iflist *ifihead) { struct iflist *ifi, *ifinext; for (ifi = ifihead; ifi != NULL; ifi = ifinext) { if (ifi->ifi_addr != NULL) new_free(&ifi->ifi_addr); ifinext = ifi->ifi_next; /* can't fetch ifi_next after free() */ new_free(&ifi); /* the ifi_info{} itself */ } }
static void update_mail_level1_maildir (void) { int status; Stat stat_buf; status = poll_maildir_status(&stat_buf); /* There is no mail */ if (status == 0) { if (mail_last_count_str) new_free(&mail_last_count_str); } /* Mailbox changed. */ else if (status == 2) { int count_new = maildir_count(); /* There is no mail */ if (count_new == 0) { if (mail_last_count_str) new_free(&mail_last_count_str); } /* Maildir changed. */ if (count_new > mail_last_count) { /* Tell the user that they have new mail. */ if (!mail_latch) { mail_latch++; if (do_hook(MAIL_LIST, "You have new email")) { int lastlog_level = set_lastlog_msg_level(LOG_CRAP); say("You have new email."); set_lastlog_msg_level(lastlog_level); } mail_latch--; } malloc_strcpy(&mail_last_count_str, empty_string); } /* * Mark the last time we checked mail, and revoke the * "count", so it must be regened by /set mail 2. */ maildir_last_changed = stat_buf.st_ctime; mail_last_count = count_new; } }
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; } } }
static void WordsListFormCleanup(AppContext* appContext) { Assert(appContext->wordsList); Assert(appContext->wordsInListCount); while (appContext->wordsInListCount) { char* word=appContext->wordsList[--appContext->wordsInListCount]; if (word) new_free(word); } new_free(appContext->wordsList); appContext->wordsList=NULL; }
void free_lastlog(Window *win) { Lastlog *ptr; for (ptr = win->lastlog_head; ptr;) { Lastlog *next = ptr->next; new_free(&ptr->msg); new_free(&ptr); ptr = next; } win->lastlog_head = NULL; win->lastlog_tail = NULL; win->lastlog_size = 0; }
void my_freeaddrinfo (AI *ai) { #ifdef GETADDRINFO_DOES_NOT_DO_AF_UNIX if (ai->ai_family == AF_UNIX) { new_free(&ai->ai_canonname); new_free(&ai->ai_addr); new_free(&ai); return; } #endif freeaddrinfo(ai); }
static XS (XS_call) { int foo = 0; char* retval=NULL; char* arg=NULL; dXSARGS; for (foo=0; foo<items; foo++) { arg = malloc_strdup((char*)SvPV_nolen(ST(foo))); retval = (char*)call_function(arg, ""); XST_mPV(foo, retval); new_free(&arg); new_free(&retval); } XSRETURN(items); }
void standard_level_warning (const char *who, char **rejects) { if (rejects && *rejects) { char *s; say("%s ignored the these unsupported levels: %s", who, *rejects); s = get_all_levels(); say("The valid levels are: %s", s); new_free(&s); new_free(rejects); } }
static void shitlist_erase(ShitList **clientlist) { ShitList *Client, *tmp; for (Client = *clientlist; Client;) { new_free(&Client->filter); new_free(&Client->reason); tmp = Client->next; new_free((char **)&Client); Client = tmp; } *clientlist = NULL; }
void foreach(u_char *command, u_char *args, u_char *subargs) { u_char *struc = NULL, *ptr, *body = NULL, *var = NULL; u_char **sublist; int total; int i; int slen; if ((ptr = new_next_arg(args, &args)) == NULL) { yell("FOREACH: missing structure expression"); return; } malloc_strcpy(&struc, ptr); malloc_strcat(&struc, UP(".")); upper(struc); if ((var = next_arg(args, &args)) == NULL) { new_free(&struc); yell("FOREACH: missing variable"); return; } while (isspace(*args)) args++; if ((body = next_expr(&args, '{')) == NULL) /* } */ { new_free(&struc); yell("FOREACH: missing statement"); return; } sublist = match_alias(struc, &total, VAR_ALIAS); slen = my_strlen(struc); for (i = 0; i < total; i++) { unsigned display; display = set_display_off(); add_alias(VAR_ALIAS, var, sublist[i]+slen); set_display(display); parse_line(NULL, body, subargs ? subargs : empty_string(), 0, 0, 0); new_free(&sublist[i]); } new_free(&sublist); new_free(&struc); }
void input_msgreply(char dumb, char *dumber) { char *cmdchar; char *line, *cmd, *t; char *snick; NickTab *nick = NULL; int got_space = 0; if (!(cmdchar = get_string_var(CMDCHARS_VAR))) cmdchar = DEFAULT_CMDCHARS; t = line = m_strdup(get_input()); if (t) got_space = strchr(t, ' ') ? 1 : 0; cmd = next_arg(line, &line); snick = next_arg(line, &line); if ((cmd && *cmd == *cmdchar && got_space) || !cmd) { if (cmd && *cmd == *cmdchar) cmd++; if (in_completion == STATE_NORMAL && snick) strncpy(new_nick, snick, sizeof(new_nick) - 1); if ((nick = getnextnick(new_nick, input_lastmsg, snick))) { if (nick->nick && *(nick->nick)) { snick = nick->nick; malloc_strcpy(&input_lastmsg, nick->nick); } } if (nick) { char *tmp = NULL; input_clear_line('\0', NULL); if (get_fset_var(FORMAT_NICK_MSG_FSET)) malloc_strcpy(&tmp, stripansicodes(convert_output_format (get_fset_var(FORMAT_NICK_MSG_FSET), "%s%s %s %s", cmdchar, nick->type ? nick->type : cmd ? cmd : "msg", nick->nick, line ? line : empty_str))); else malloc_sprintf(&tmp, "%s%s %s %s", cmdchar, nick->type ? nick->type : cmd ? cmd : "msg", nick->nick, line ? line : empty_str); set_input(tmp); new_free(&tmp); } else command_completion(0, NULL); } else command_completion(0, NULL); update_input(UPDATE_ALL); new_free(&t); }
static XS (XS_expr) { unsigned foo, food = 0; char* retval=NULL; char* arg=NULL; dXSARGS; for (foo=0; foo<items; foo++) { arg = malloc_strdup((char*)SvPV_nolen(ST(foo))); retval = (char*)parse_inline(arg, "", &food); XST_mPV(foo, retval); new_free(&arg); new_free(&retval); } XSRETURN(items); }