/* Reads file DB v1 entries from fdb_s and saves them to fdb_t in * v3 format. */ static void convert_version1(FILE *fdb_s, FILE *fdb_t) { filedb1 fdb1; fseek(fdb_s, 0L, SEEK_SET); while (!feof(fdb_s)) { fread(&fdb1, sizeof(filedb1), 1, fdb_s); if (!feof(fdb_s)) { if (!(fdb1.stat & FILE_UNUSED)) { filedb_entry *fdbe = malloc_fdbe(); fdbe->stat = fdb1.stat; if (fdb1.filename[0]) malloc_strcpy(fdbe->filename, fdb1.filename); if (fdb1.desc[0]) malloc_strcpy(fdbe->desc, fdb1.desc); if (fdb1.uploader[0]) malloc_strcpy(fdbe->uploader, fdb1.uploader); if (fdb1.flags_req[0]) malloc_strcpy(fdbe->flags_req, (char *) fdb1.flags_req); fdbe->uploaded = fdb1.uploaded; fdbe->size = fdb1.size; fdbe->gots = fdb1.gots; if (fdb1.sharelink[0]) malloc_strcpy(fdbe->sharelink, fdb1.sharelink); filedb_addfile(fdb_s, fdbe); free_fdbe(&fdbe); } } } }
static void filedb_setlink(char *dir, char *fn, char *link) { filedb_entry *fdbe = NULL; FILE *fdb = NULL; fdb = filedb_open(dir, 0); if (!fdb) return; filedb_readtop(fdb, NULL); fdbe = filedb_matchfile(fdb, ftell(fdb), fn); if (fdbe) { /* Change existing one? */ if ((fdbe->stat & FILE_DIR) || !fdbe->sharelink) return; if (!link || !link[0]) filedb_delfile(fdb, fdbe->pos); else { my_free(fdbe->sharelink); malloc_strcpy(fdbe->sharelink, link); filedb_updatefile(fdb, fdbe->pos, fdbe, UPDATE_ALL); } free_fdbe(&fdbe); return; } fdbe = malloc_fdbe(); malloc_strcpy(fdbe->uploader, botnetnick); malloc_strcpy(fdbe->filename, fn); malloc_strcpy(fdbe->sharelink, link); fdbe->uploaded = now; filedb_addfile(fdb, fdbe); free_fdbe(&fdbe); filedb_close(fdb); }
/* * This removes every character from the 'anchor' position to the current * position from the input line, and puts it into the cut buffer. It does * the requisite redraw as well. */ static void cut_input (int anchor) { char * buffer; size_t size; if (anchor < THIS_POS) { size = THIS_POS - anchor; buffer = alloca(size + 1); strlcpy(buffer, &INPUT_BUFFER[anchor], size + 1); malloc_strcpy(&cut_buffer, buffer); buffer = LOCAL_COPY(&THIS_CHAR); INPUT_BUFFER[anchor] = 0; ADD_TO_INPUT(buffer); THIS_POS = anchor; } else { size = anchor - THIS_POS; buffer = alloca(size + 1); strlcpy(buffer, &THIS_CHAR, size + 1); malloc_strcpy(&cut_buffer, buffer); buffer = LOCAL_COPY(&INPUT_BUFFER[anchor]); THIS_CHAR = 0; ADD_TO_INPUT(buffer); } update_input(UPDATE_ALL); }
static int tcl_setflags(ClientData cd, Tcl_Interp *irp, int argc, char *argv[]) { FILE *fdb; filedb_entry *fdbe; char *s = NULL, *p, *d; BADARGS(3, 4, " dir ?flags ?channel??"); malloc_strcpy(s, argv[1]); if (s[strlen(s) - 1] == '/') s[strlen(s) - 1] = 0; p = strrchr(s, '/'); if (p == NULL) { p = s; d = ""; } else { *p = 0; p++; d = s; } fdb = filedb_open(d, 0); if (!fdb) { Tcl_AppendResult(irp, "-3", NULL); /* filedb access failed */ my_free(s); return TCL_OK; } filedb_readtop(fdb, NULL); fdbe = filedb_matchfile(fdb, ftell(fdb), p); my_free(s); if (!fdbe) { Tcl_AppendResult(irp, "-1", NULL); /* No such dir */ return TCL_OK; } if (!(fdbe->stat & FILE_DIR)) { Tcl_AppendResult(irp, "-2", NULL); /* Not a dir */ return TCL_OK; } if (argc >= 3) { struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 }; char f[100]; break_down_flags(argv[2], &fr, NULL); build_flags(f, &fr, NULL); malloc_strcpy(fdbe->flags_req, f); } else my_free(fdbe->flags_req); if (argc == 4) malloc_strcpy(fdbe->chan, argv[3]); filedb_updatefile(fdb, fdbe->pos, fdbe, UPDATE_ALL); free_fdbe(&fdbe); filedb_close(fdb); Tcl_AppendResult(irp, "0", NULL); return TCL_OK; }
/* * set_input_prompt: sets a prompt that will be displayed in the input * buffer. This prompt cannot be backspaced over, etc. It's a prompt. * Setting the prompt to null uses no prompt */ void set_input_prompt (const void *stuff) { const char *prompt = (const char *)stuff; if (prompt) malloc_strcpy(&input_prompt, prompt); else if (input_prompt) malloc_strcpy(&input_prompt, empty_string); else return; update_input(UPDATE_ALL); }
/* * set_input_prompt: sets a prompt that will be displayed in the input * buffer. This prompt cannot be backspaced over, etc. It's a prompt. * Setting the prompt to null uses no prompt */ void set_input_prompt(Window * win, char *prompt, int unused) { if (prompt) { if (input_prompt && !strcmp(prompt, input_prompt)) return; malloc_strcpy(&input_prompt, convert_output_format(prompt, NULL, NULL)); } else { if (!input_prompt) return; malloc_strcpy(&input_prompt, empty_str); } update_input(UPDATE_ALL); }
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); }
/* * set_string_var: sets the string variable given as an index into the * variable table to the given string. If string is null, the current value * of the string variable is freed and set to null */ void set_string_var(enum VAR_TYPES var, char *string) { if (string) malloc_strcpy(&(irc_variable[var].string), string); else new_free(&(irc_variable[var].string)); }
/* * input_clear_to_bol: clears from the cursor to the beginning of the input * buffer */ void input_clear_to_bol(char unused, char *not_used) { char *ptr = NULL; cursor_to_input(); malloc_strcpy(&cut_buffer, &(MIN_CHAR)); cut_buffer[THIS_POS - MIN_POS] = (char) 0; malloc_strcpy(&ptr, &(THIS_CHAR)); MIN_CHAR = (char) 0; ADD_TO_INPUT(ptr); new_free(&ptr); THIS_POS = MIN_POS; term_move_cursor(MIN_POS, input_line); term_clear_to_eol(); update_input(UPDATE_FROM_CURSOR); }
void BX_fset_string_var(enum FSET_TYPES var, char *value) { if (value && *value) malloc_strcpy(&(fset_array[var].string), value); else new_free(&(fset_array[var].string)); }
/* input_backspace: does a backspace in the input buffer */ void input_backspace(char key, char *blah) { cursor_to_input(); if (THIS_POS > MIN_POS) { char *ptr = NULL; int pos; malloc_strcpy(&ptr, &(THIS_CHAR)); strcpy(&(PREV_CHAR), ptr); new_free(&ptr); THIS_POS--; term_cursor_left(); if (THIS_CHAR) { if (term_delete()) update_input(UPDATE_FROM_CURSOR); { pos = str_start + term_cols - 1; pos += count_ansi(&(current_screen->input_buffer[str_start]), zone); if (pos < strlen(INPUT_BUFFER)) { term_move_cursor(term_cols - 1, input_line); term_putchar(INPUT_BUFFER[pos]); } update_input(UPDATE_JUST_CURSOR); } } else { term_putchar(' '); term_cursor_left(); update_input(NO_UPDATE); } } in_completion = STATE_NORMAL; *new_nick = 0; }
/* input_delete_character: deletes a character from the input line */ void input_delete_character(char unused, char *not_used) { cursor_to_input(); if (THIS_CHAR) { char *ptr = NULL; int pos; malloc_strcpy(&ptr, &(NEXT_CHAR)); strcpy(&(THIS_CHAR), ptr); new_free(&ptr); if (term_delete()) update_input(UPDATE_FROM_CURSOR); else { pos = str_start + term_cols - 1; pos += count_ansi(&(current_screen->input_buffer[str_start]), zone); if (pos < strlen(INPUT_BUFFER)) { term_move_cursor(term_cols - 1, input_line); term_putchar(INPUT_BUFFER[pos]); term_move_cursor(cursor, input_line); } update_input(NO_UPDATE); } } in_completion = STATE_NORMAL; }
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); }
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; }
/* * create_timer_ref: returns the lowest unused reference number for a timer * All refnums that are not already in use are valid. * * The user is allowed to use any string as a refnum, we dont really care. * Automatically assigned refnums (when the user doesnt specify one) will * always be one more than the highest pending refnum. * * "refnum_gets" must be REFNUM_MAX + 1 bytes by definition of API. */ static int create_timer_ref (const char *refnum_wanted, char **refnum_gets) { Timer *tmp; int refnum = 0; char *refnum_want; refnum_want = LOCAL_COPY(refnum_wanted); /* If the user doesnt care */ if (*refnum_want == 0) { /* Find the lowest refnum available */ for (tmp = PendingTimers; tmp; tmp = tmp->next) { if (refnum < my_atol(tmp->ref)) refnum = my_atol(tmp->ref); } malloc_sprintf(refnum_gets, "%d", refnum + 1); } else { /* See if the refnum is available */ if (get_timer(refnum_want)) return -1; /* Already in use */ malloc_strcpy(refnum_gets, refnum_want); } return 0; }
static void set_fset_var_value(int var_index, char *name, char *value) { IrcVariable *var = NULL; if (name) var = find_ext_fset_var(name); if (!var) var = &(fset_array[var_index]); switch (var->type) { case STR_TYPE_VAR: { if (value) { if (*value) malloc_strcpy(&(var->string), value); else { put_it("%s", convert_output_format(fget_string_var(FORMAT_SET_FSET), "%s %s", var->name, var->string?var->string:empty_string)); return; } } else new_free(&(var->string)); if (var->func) (var->func) (current_window, var->string, 0); say("Value of %s set to %s", var->name, var->string ? var->string : "<EMPTY>"); } break; default: say("FSET_type not supported"); } }
static void set_hostname(char *host) { const struct iflist *ifl = iface_find(host); if (ifl == NULL) { yell("no such hostname [%s]!", host); } else if (local_host_name && !strcmp(local_host_name, ifl->ifi_host)) { bitchsay("%s is already my hostname, yo.", local_host_name); } else { sa_addr_t *addr; sa_rc_t ret; malloc_strcpy(&local_host_name, ifl->ifi_host); sa_addr_create(&addr); ret = sa_addr_s2a(addr, ifl->ifi_addr, ifl->ifi_len); if (ret != SA_OK) { sa_addr_destroy(addr); bitchsay("couldn't set local hostname: %s", sa_error(ret)); } else { bitchsay("local host name is now %s", local_host_name); if (local_host_addr) sa_addr_destroy(local_host_addr); local_host_addr = addr; t_parse_command("RECONNECT", NULL); } } }
static void set_clock_format (Window *win, char *value, int unused) { extern char *time_format; /* XXXX bogus XXXX */ malloc_strcpy(&time_format, value); update_clock(RESET_TIME); update_all_status(current_window, NULL, 0); }
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); } } }
static Logfile * logfile_name (Logfile *log, char **args) { char *arg; if (!log) { say("NAME: You need to specify a logfile first"); return NULL; } if (!(arg = next_arg(*args, args))) say("You must specify a name for the logfile!"); else { /* /log name - unsets the window name */ if (!strcmp(arg, "-")) new_free(&log->name); /* /log name to existing name -- ignore this. */ else if (log->name && (my_stricmp(log->name, arg) == 0)) return log; else if (is_logfile_name_unique(arg)) malloc_strcpy(&log->name, arg); else say("%s is not unique!", arg); } return log; }
/* * 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; }
static Logfile * logfile_filename (Logfile *log, char **args) { char * arg = next_arg(*args, args); if (!log) { say("FILENAME: You need to specify a logfile first"); return NULL; } if (!arg) { if (log->filename) say("Log %s is attached to %s", log->name, log->filename); else say("Log %s does not have a filename", log->name); return log; } if (log->active) logfile_off(log, NULL); malloc_strcpy(&log->filename, arg); if (log->active) logfile_on(log, NULL); return log; }
/* in response to a TOPIC message from the server */ static void p_topic(char *from, char **ArgList) { struct channel *tmp; if (!ArgList[1]) { fake(); return; } tmp = lookup_channel(ArgList[0], from_server, CHAN_NOUNLINK); malloc_strcpy(&tmp->topic, ArgList[1]); if (check_ignore(from, FromUserHost, tmp->channel, IGNORE_TOPICS | IGNORE_CRAP, NULL) != IGNORED) { message_from(ArgList[0], LOG_CRAP); if (do_hook(TOPIC_LIST, "%s %s %s", from, ArgList[0], ArgList[1])) { if (ArgList[1] && *ArgList[1]) { if (get_format(FORMAT_TOPIC_CHANGE_HEADER_FSET)) put_it("%s", convert_output_format(get_format(FORMAT_TOPIC_CHANGE_HEADER_FSET), "%s %s %s %s", update_clock(GET_TIME), from, ArgList[0], ArgList[1])); put_it("%s", convert_output_format(get_format(FORMAT_TOPIC_CHANGE_FSET), "%s %s %s %s", update_clock(GET_TIME), from, ArgList[0], ArgList[1])); } else put_it("%s", convert_output_format(get_format(FORMAT_TOPIC_UNSET_FSET), "%s %s %s", update_clock(GET_TIME), from, ArgList[0])); } message_from(NULL, LOG_CRAP); } update_all_status(curr_scr_win, NULL, 0); }
static void set_wset_var_value(Window *win, int var_index, char *value) { WSetArray *var; var = &(wset_array[var_index]); switch (var->type) { case STR_TYPE_VAR: { char **val = NULL; if ((val = get_wset_str_var_address(win->wset, var_index))) { if (value) { if (*value) malloc_strcpy(val, value); else { put_it("%s", convert_output_format(fget_string_var(FORMAT_SET_FSET), "%s %s", var->name, *val?*val:empty_string)); return; } } else new_free(val); if (var->func) (var->func) (win, *val, 0); say("Value of %s set to %s", var->name, *val ? *val : "<EMPTY>"); } } break; default: say("WSET_type not supported"); } }
void BX_set_wset_string_var(WSet *tmp, int var, char *value) { char **ptr = (char **)((unsigned long)tmp + wset_array[var].offset); if (value && *value) malloc_strcpy(ptr, value); else new_free(ptr); }
void BX_set_cset_str_var(CSetList *tmp, int var, char *value) { char **ptr = (char **) ((void *)tmp + cset_array[var].offset); if (value) malloc_strcpy(ptr, value); else new_free(ptr); }
/* input_clear_to_eol: erases from the cursor to the end of the input buffer */ void input_clear_to_eol(char unused, char *not_used) { cursor_to_input(); malloc_strcpy(&cut_buffer, &(THIS_CHAR)); THIS_CHAR = 0; term_clear_to_eol(); update_input(NO_UPDATE); }
/* * input_clear_line: clears entire input line */ void input_clear_line(char unused, char *not_used) { cursor_to_input(); malloc_strcpy(&cut_buffer, INPUT_BUFFER + MIN_POS); MIN_CHAR = (char) 0; THIS_POS = MIN_POS; term_move_cursor(current_screen->buffer_min_pos - count_ansi(current_screen->input_buffer, zone), input_line); term_clear_to_eol(); update_input(NO_UPDATE); }
void set_clock_format (void *stuff) { const VARIABLE *v; const char *value; v = (const VARIABLE *)stuff; value = v->string; malloc_strcpy(&time_format, value); reset_clock(NULL); }
void whilecmd(u_char *command, u_char *args, u_char *subargs) { u_char *expr = NULL, *ptr, *body = NULL, *newexp = NULL; int args_used; /* this isn't used here, but is passed * to expand_alias() */ if ((ptr = next_expr(&args, '(')) == NULL) { yell("WHILE: missing boolean expression"); return; } malloc_strcpy(&expr, ptr); if ((ptr = next_expr(&args, '{')) == NULL) { say("WHILE: missing expression"); new_free(&expr); return; } malloc_strcpy(&body, ptr); while (1) { malloc_strcpy(&newexp, expr); ptr = parse_inline(newexp, subargs ? subargs : empty_string(), &args_used); if (*ptr && *ptr !='0') { new_free(&ptr); parse_line(NULL, body, subargs ? subargs : empty_string(), 0, 0, 0); } else break; } new_free(&newexp); new_free(&ptr); new_free(&expr); new_free(&body); }