imc_info *imc_new_info() { imc_info *i, *p; i=imc_malloc(sizeof(*i)); i->name = NULL; i->host = NULL; i->port = 0; i->connection = NULL; i->clientpw = NULL; i->serverpw = NULL; i->timer_duration = IMC_MIN_RECONNECT_TIME; i->rcvstamp = 0; i->noforward = 0; i->flags = 0; i->last_connected = 0; /* ugly hack, but Too Bad, I don't want another global floating around */ i->next=NULL; for (p=imc_info_list; p && p->next; p=p->next) ; if (!p) imc_info_list=i; else p->next=i; return i; }
void icec_load_channels(void) { FILE *fp; char name[MAX_STRING_LENGTH]; char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char buf3[MAX_STRING_LENGTH]; char buf4[MAX_STRING_LENGTH]; int l; strcpy(name, imc_prefix); strcat(name, "icec"); fp=fopen(name, "r"); if (!fp) { imc_logerror("Can't open %s", name); return; } while (fscanf(fp, "%s %s %d\n" "%[^\n]\n" "%[^\n]\n", buf1, buf2, &l, buf3, buf4) == 5) { ice_channel *c=imc_malloc(sizeof(*c)); c->local=imc_malloc(sizeof(*c->local)); c->name=imc_strdup(buf1); c->local->name=imc_strdup(buf2); c->local->format1=imc_strdup(buf3); c->local->format2=imc_strdup(buf4); c->local->level=l; c->next=saved_channel_list; saved_channel_list=c; imc_logstring("ICEc: configured %s as %s", c->name, c->local->name); } fclose(fp); }
static imc_mailid *new_mailid(void) { imc_mailid *p; p=imc_malloc(sizeof(*p)); p->id = NULL; p->received = 0; p->next = NULL; return p; }
/* new_qnode: get a new qnode */ static imc_qnode *new_qnode(void) { imc_qnode *p; p=imc_malloc(sizeof(*p)); p->data = NULL; p->next = NULL; p->tomud = NULL; return p; }
void icec_recv_update(const char *from, const char *chan, const char *owner, const char *operators, const char *policy, const char *invited, const char *excluded) { ice_channel *c; const char *mud; mud = imc_mudof(from); /* forged? */ if(!strchr(chan, ':') || strcasecmp(mud, ice_mudof(chan))) { return; } c = icec_findchannel(chan); if(!c) { c = imc_malloc(sizeof(*c)); c->name = imc_strdup(chan); c->owner = imc_strdup(owner); c->operators = imc_strdup(operators); c->invited = imc_strdup(invited); c->excluded = imc_strdup(excluded); c->local = NULL; c->active = NULL; c->next = icec_channel_list; icec_channel_list = c; } else { imc_strfree(c->owner); imc_strfree(c->operators); imc_strfree(c->invited); imc_strfree(c->excluded); c->name = imc_strdup(chan); c->owner = imc_strdup(owner); c->operators = imc_strdup(operators); c->invited = imc_strdup(invited); c->excluded = imc_strdup(excluded); } if(!strcasecmp(policy, "open")) { c->policy = ICE_OPEN; } else if(!strcasecmp(policy, "closed")) { c->policy = ICE_CLOSED; } else { c->policy = ICE_PRIVATE; } if(c->local && !ice_audible(c, imc_name)) { icec_localfree(c); } icec_notify_update(c); imc_cancel_event(ev_icec_timeout, c); imc_add_event(ICEC_TIMEOUT, ev_icec_timeout, c, 0); }
/* set up a new imc_connect struct, and link it into imc_connect_list */ imc_connect *imc_new_connect(void) { imc_connect *c; c=imc_malloc(sizeof(*c)); c->state = IMC_CLOSED; c->desc = -1; c->insize = IMC_MINBUF; c->inbuf = imc_malloc(c->insize); c->outsize = IMC_MINBUF; c->outbuf = imc_malloc(c->outsize); c->inbuf[0] = c->outbuf[0] = 0; c->info = NULL; c->spamcounter1=0; c->spamcounter2=0; c->spamtime1=0; c->spamtime2=0; c->newoutput=0; c->next=imc_connect_list; imc_connect_list=c; return c; }
/* new_mail: create a new mail structure */ static imc_mail *new_mail(void) { imc_mail *p; p=imc_malloc(sizeof(*p)); p->from = NULL; p->to = NULL; p->subject = NULL; p->date = NULL; p->text = NULL; p->id = NULL; p->received = 0; p->usage = 0; p->next = NULL; return p; }
void icec_notify_update(ice_channel *c) { if (!c->local) { /* saved channel? */ ice_channel *saved; for (saved=saved_channel_list; saved; saved=saved->next) if (!strcasecmp(saved->name, c->name)) { c->local=imc_malloc(sizeof(icec_lchannel)); c->local->name=imc_strdup(saved->local->name); c->local->format1=imc_strdup(saved->local->format1); c->local->format2=imc_strdup(saved->local->format2); c->local->level=saved->local->level; return; } } }
/* put a line onto descriptors output buffer */ static void do_send(imc_connect *c, const char *line) { int len; char *newbuf; int newsize=c->outsize; if (c->state==IMC_CLOSED) return; // imc_debug(c, 1, line); /* log outgoing traffic */ if (!c->outbuf[0]) c->newoutput=1; len=strlen(c->outbuf)+strlen(line)+3; if (len > c->outsize) { #ifdef SHOW_OVERFLOW /* not an error anymore, expected and handled - shogar */ if (len > IMC_MAXBUF) { if (!c->info || !(c->info->flags & IMC_QUIET)) imc_logerror("%s: output buffer overflow", imc_getconnectname(c)); imc_logerror("%d: was allocated", c->outsize); // imc_logerror("current buf: %s", c->outbuf); // do_close(c); // imc_free(c->outbuf,c->outsize); // c->outsize=IMC_MINBUF; // c->outbuf= imc_malloc(c->outsize); // len=strlen(line)+3; // return; } #endif while(newsize < len) newsize*=2; newbuf=imc_malloc(newsize); strcpy(newbuf, c->outbuf); imc_free(c->outbuf, c->outsize); c->outbuf=newbuf; c->outsize=newsize; } if (len<c->outsize/2 && len >= IMC_MINBUF) { newsize=c->outsize/2; newbuf=imc_malloc(newsize); strcpy(newbuf, c->outbuf); imc_free(c->outbuf, c->outsize); c->outbuf=newbuf; c->outsize=newsize; } strcat(c->outbuf, line); strcat(c->outbuf, "\n\r"); if (strlen(c->outbuf)>=c->outsize/2) { imc_cancel_event(ev_shrink_output, c); imc_add_event(IMC_SHRINKTIME, ev_shrink_output, c, 0); } }
/* read waiting data from descriptor. * read to a temp buffer to avoid repeated allocations */ static void do_read(imc_connect *c) { int size; int r; char temp[IMC_MAXBUF]; char *newbuf; int newsize; r=read(c->desc, temp, IMC_MAXBUF-1); if (!r || (r<0 && errno != EAGAIN && errno != EWOULDBLOCK)) { if (!c->info || !(c->info->flags & IMC_QUIET)) { if (r<0) /* read error */ { imc_lerror("%s: read", imc_getconnectname(c)); } else /* socket was closed */ { imc_logerror("%s: read: EOF", imc_getconnectname(c)); } } do_close(c); return; } if (r<0) /* EAGAIN error */ return; temp[r]=0; size=strlen(c->inbuf)+r+1; if (size>=c->insize) { #ifdef SHOW_OVERFLOW /* not an error anymore, expected and handled - shogar */ if (size>IMC_MAXBUF) { imc_logerror("%s: input buffer overflow", imc_getconnectname(c)); imc_logerror("%d: was allocated", c->insize); // do_close(c); // imc_free(c->inbuf,c->insize); // c->insize=IMC_MINBUF; // c->inbuf= imc_malloc(c->insize); // size = r + 1; // return; } #endif newsize=c->insize; while(newsize<size) newsize*=2; newbuf=imc_malloc(newsize); strcpy(newbuf, c->inbuf); imc_free(c->inbuf, c->insize); c->inbuf=newbuf; c->insize=newsize; } if (size>c->insize/2) { imc_cancel_event(ev_shrink_input, c); imc_add_event(IMC_SHRINKTIME, ev_shrink_input, c, 0); } if (size<c->insize/2 && size >= IMC_MINBUF) { newsize=c->insize; newsize/=2; newbuf=imc_malloc(newsize); strcpy(newbuf, c->inbuf); imc_free(c->inbuf, c->insize); c->inbuf=newbuf; c->insize=newsize; } strcat(c->inbuf, temp); imc_stats.rx_bytes += r; }