irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit c50d55c1d9e83a0794af0bc87040cdaca0edc292
parent 131754a4a667b211b8e0f229a8e0aa34ea7d0bd8
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 28 Jul 2012 01:09:15 +0200

general cleanup

Diffstat:
irctk.c | 70+++++++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -27,12 +27,13 @@ enum default_destinations {DEFAULT_FIRST, DEFAULT_LAST_IN, DEFAULT_LAST_OUT, DEF enum event_tos {NOTHING, COMMAND, MESSAGE}; enum track {NO, YES, UNIQUE}; -// TODO get rid of that -#define MAX_LEN 4096 +#define MAX_LINE_LEN 4096 +#define MAX_CHAN_LEN 4096 +#define MAX_CHANS_LEN 4096 #define MAX_NICK_LEN 4096 -#define LINE_BUFFER 4096 +#define STDIN_BUFFER_SIZE 4096 -#define INITIAL_CHAN_ALLOC 2 +#define INITIAL_CHAN_LIST_SIZE 2 // non-standard error for the hybrid ircd #define ERR_BADCHANNAME 479 @@ -45,7 +46,7 @@ const char *argp_program_bug_address = "<a3nm@a3nm.net>"; static char doc[] = "irctk -- an IRC toolkit"; static char args_doc[] = "[NICK[:PASS]@]SERVER[:PORT] [CHANNEL[:PASS]]..."; -enum arg_types {STANDARD, TIMING, MISC, COM_MODE, CHANNEL_SELECTION, BOT_OPTIONS, +enum arg_types {STANDARD, TIMING, MISC, CHANNEL_SELECTION, BOT_OPTIONS, TRACKING, PARSING, DISPLAY_SELECTION, NAME}; static struct argp_option options[] = { @@ -195,9 +196,9 @@ struct arguments int command; char * raw_dest; char ready; - char last_chan_in[MAX_LEN]; - char last_nick_in[MAX_LEN]; - char last_chans_out[MAX_LEN]; + char last_chan_in[MAX_CHAN_LEN]; + char last_nick_in[MAX_NICK_LEN]; + char last_chans_out[MAX_CHANS_LEN]; int show_nick_prefix; int filter; int prune; @@ -205,7 +206,6 @@ struct arguments typedef struct arguments irc_ctx_t; -/* The program settings */ struct arguments args; /* The initial argument values */ @@ -495,7 +495,7 @@ typedef struct action { typedef struct fifo { int hd; int tl; - line queue[LINE_BUFFER]; + line queue[STDIN_BUFFER_SIZE]; } fifo; typedef struct fifo_ctrl { @@ -522,7 +522,7 @@ void init_fifo_ctrl(fifo_ctrl *c) { void init_fifo_set (fifo_set *s) { s->n = 0; - s->allocated = INITIAL_CHAN_ALLOC; + s->allocated = INITIAL_CHAN_LIST_SIZE; s->chans = malloc(s->allocated * sizeof(char*)); assert(s->chans); s->fifos = malloc(s->allocated * sizeof(fifo)); @@ -559,10 +559,10 @@ void init_fifo(fifo *f) { } int size(fifo *f) { - return (f->tl - f->hd + LINE_BUFFER) % LINE_BUFFER; + return (f->tl - f->hd + STDIN_BUFFER_SIZE) % STDIN_BUFFER_SIZE; } int full(fifo *f) { - return size(f) == LINE_BUFFER - 1; + return size(f) == STDIN_BUFFER_SIZE - 1; } int full_fifo_set(fifo_set *s) { // fifo_set is full if one fifo is full @@ -600,14 +600,14 @@ void realloc_chans(fifo_set *s) { int push_chan_alias(fifo_set *s, const char *chan, const char *alias) { if (s->n == s->allocated) realloc_chans(s); - s->chans[s->n] = malloc(MAX_LEN * sizeof(chan)); + s->chans[s->n] = malloc(MAX_CHANS_LEN * sizeof(chan)); assert(s->chans[s->n]); - strncpy(s->chans[s->n], chan, MAX_LEN-1); + strncpy(s->chans[s->n], chan, MAX_CHAN_LEN-1); init_fifo(&s->fifos[s->n]); s->was_pushed[s->n] = 0; - s->surface_name[s->n] = malloc(MAX_LEN * sizeof(chan)); + s->surface_name[s->n] = malloc(MAX_NICK_LEN * sizeof(chan)); assert(s->surface_name[s->n]); - strncpy(s->surface_name[s->n], alias, MAX_LEN-1); + strncpy(s->surface_name[s->n], alias, MAX_NICK_LEN-1); return (s->n)++; } @@ -732,16 +732,16 @@ void push_one(fifo_set *s, char *fl, char *dest, char *l, *lineidx = f->tl; debug("pushed one, returning next dep %d %d", *fifoidx, *lineidx); f->tl++; - f->tl %= LINE_BUFFER; + f->tl %= STDIN_BUFFER_SIZE; } void set_last_idxes(fifo_set *s, char *chan, int fifoidx, int lineidx) { int c = index_of_chan(s, chan); fifo *f = &(s->fifos[c]); debug("set_last_idxes %d %d for \"%s\" ioc %d position %d", fifoidx, lineidx, - f->queue[(f->tl - 1 + LINE_BUFFER) % LINE_BUFFER].line, c, (f->tl - 1 + LINE_BUFFER) % LINE_BUFFER); - f->queue[(f->tl - 1 + LINE_BUFFER) % LINE_BUFFER].next_dep_fifoidx = fifoidx; - f->queue[(f->tl - 1 + LINE_BUFFER) % LINE_BUFFER].next_dep_lineidx = lineidx; + f->queue[(f->tl - 1 + STDIN_BUFFER_SIZE) % STDIN_BUFFER_SIZE].line, c, (f->tl - 1 + STDIN_BUFFER_SIZE) % STDIN_BUFFER_SIZE); + f->queue[(f->tl - 1 + STDIN_BUFFER_SIZE) % STDIN_BUFFER_SIZE].next_dep_fifoidx = fifoidx; + f->queue[(f->tl - 1 + STDIN_BUFFER_SIZE) % STDIN_BUFFER_SIZE].next_dep_lineidx = lineidx; } void reset_chan_marks(fifo_set *s) { @@ -883,7 +883,7 @@ void pop_if_sendable(fifo_set *s, int c, int *n_result, action *result) { result[*n_result].destination = s->surface_name[c]; (*n_result)++; f->hd++; - f->hd %= LINE_BUFFER; + f->hd %= STDIN_BUFFER_SIZE; } else { // don't pop sentinel //debug("don't pop: channel %d position %d was_sendable? %d, line %p", c, f->hd, @@ -1125,7 +1125,7 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line) join_channel(s, chan); if (args.track != NO) { - char lline[MAX_LEN + MAX_NICK_LEN + 2]; + char lline[MAX_LINE_LEN + MAX_NICK_LEN + 2]; int seppos = -1; int i; for (i=0; i<strlen(line); i++) { @@ -1151,7 +1151,7 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line) debug("CURRENT LINE %s", lline); pthread_mutex_unlock(&fifos.ctrl.mutex); line[seppos] = sep; - strncat(lline, line + seppos, MAX_LEN-1); + strncat(lline, line + seppos, MAX_LINE_LEN-1); rsl = do_say(s, chan, lline); } } else { @@ -1172,7 +1172,7 @@ void cmd_msg(char *full_line, char *target, char *line) debug("cmd_msg %s \"%s\" (%p), last_in %s", target, line, line, args.last_chan_in); if (args.track != NO) { - char lline[MAX_LEN + MAX_NICK_LEN + 2]; + char lline[MAX_LINE_LEN + MAX_NICK_LEN + 2]; int seppos = -1; int i; for (i=0; i<strlen(line); i++) { @@ -1194,7 +1194,7 @@ void cmd_msg(char *full_line, char *target, char *line) pthread_mutex_unlock(&fifos.ctrl.mutex); line[seppos] = sep; if (c >= 0) { - strncpy(lline, line + seppos, MAX_LEN-1); + strncpy(lline, line + seppos, MAX_LINE_LEN-1); debug("COPY TO LLINE"); free(full_line); line = lline; @@ -1215,17 +1215,17 @@ void cmd_msg(char *full_line, char *target, char *line) if (args.show_nick_prefix && args.last_nick_in[0] && args.last_chan_in[0] == '#') { if (line[0] != '\n') { - msg = malloc((2*MAX_LEN + 2)* sizeof(char)); + msg = malloc((2*MAX_LINE_LEN + 2)* sizeof(char)); assert(msg); msg[0] = 0; if (args.track == YES) { strncat((char*) msg, input_nick(args.last_nick_in), - MAX_LEN-1); + MAX_LINE_LEN-1); } else { - strncat((char*) msg, args.last_nick_in, MAX_LEN-1); + strncat((char*) msg, args.last_nick_in, MAX_LINE_LEN-1); } strcat((char*) msg, ": "); - strncat((char*) msg, line, MAX_LEN-1); + strncat((char*) msg, line, MAX_LINE_LEN-1); free(full_line); full_line = msg; line = msg; @@ -1521,14 +1521,14 @@ void event_channel (irc_session_t *session, const char *event, } // if addressed in our private chan, reply on the sender's priv chan if (strcmp(params[0], args.nick)) - strncpy(args.last_chan_in, params[0], MAX_LEN-1); - else strncpy(args.last_chan_in, origin?origin:"someone", MAX_LEN-1); + strncpy(args.last_chan_in, params[0], MAX_CHAN_LEN-1); + else strncpy(args.last_chan_in, origin?origin:"someone", MAX_CHAN_LEN-1); // if UNIQUE, store the uid, else store the surface if (args.track == UNIQUE) { strncpy(args.last_nick_in, origin?output_nick(origin):"someone", - MAX_LEN-1); + MAX_NICK_LEN-1); } else { - strncpy(args.last_nick_in, origin?origin:"someone", MAX_LEN-1); + strncpy(args.last_nick_in, origin?origin:"someone", MAX_NICK_LEN-1); } } } @@ -1636,7 +1636,7 @@ static void* fifo_in_thread (void *arg) { line[i] = 0; debug("[thread_in] calling with line target msg %p %p %p", line, target, msg); cmd_msg(line, target, msg); - strncpy(args.last_chans_out, target, MAX_LEN-1); + strncpy(args.last_chans_out, target, MAX_CHANS_LEN-1); } else { /* No target specified, we attempt the default */ debug("[thread_in] calling with line target msg %p %p %p", line, "", line);