/* rename file after upload */ static void fetch_rename(fetch_curl_t *ft, const char *effective_url) { char *name; char *destname; int rc; int fd; if (strncasecmp(ft->name, "AUTO", 4) != 0) /* NOTRANSLATE */ return; name = fetch_get_filename(ft, effective_url); if (name == NULL) return; destname = mystrjoin(ft->uploaddir, name, '/'); fd = open(destname, O_RDONLY | ADDED_OPEN_FLAGS); if (fd >= 0) { close(fd); outerror(OUTERROR_TYPE_WARN_LOUD, "File %s could not be moved to %s: %s", ft->name, name, strerror(EEXIST)); } else { rc = rename(ft->fullname, destname); if (rc < 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "File %s could not be moved to %s: %s", ft->name, name, strerror(errno)); } else { a_respond(&(ft->u), "fetched: '%s'", destname); } } mydelete(destname); mydelete(name); }
static int l_setup_listen(upload * const l) { char *tempstr; char *msg; unsigned int rc; updatecontext(); rc = irc_open_listen(&(l->con)); if (rc != 0) { l_closeconn(l, "Connection Lost", 0); return 1; } msg = setup_dcc_local(&(l->con.local)); tempstr = getsendname(l->file); privmsg_fast(l->nick, IRC_CTCP "DCC SEND %s %s %" LLPRINTFMT "d %u" IRC_CTCP, /* NOTRANSLATE */ tempstr, msg, l->totalsize, l->token); mydelete(msg); msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &(l->con.local.sa)); ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "DCC SEND sent to %s on %s, waiting for connection on %s", l->nick, gnetwork->name, msg); mydelete(tempstr); mydelete(msg); l->ul_status = UPLOAD_STATUS_LISTENING; return 0; }
/* send DCC command to start download */ void t_start_dcc_send(transfer *tr) { char *dccdata; char *sendnamestr; updatecontext(); sendnamestr = getsendname(tr->xpack->file); dccdata = setup_dcc_local(&tr->con.local); if (tr->passive_dcc) { bzero((char *) &(tr->con.local), sizeof(tr->con.local)); privmsg_fast(tr->nick, IRC_CTCP "DCC SEND %s %s %" LLPRINTFMT "d %u" IRC_CTCP, /* NOTRANSLATE */ sendnamestr, dccdata, tr->xpack->st_size, tr->id); } else { privmsg_fast(tr->nick, IRC_CTCP "DCC SEND %s %s %" LLPRINTFMT "d" IRC_CTCP, /* NOTRANSLATE */ sendnamestr, dccdata, tr->xpack->st_size); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "listen on port %d for %s (%s on %s)", tr->con.localport, tr->nick, tr->hostname, gnetwork->name); } mydelete(dccdata); mydelete(sendnamestr); }
void shutdowndccchat(dccchat_t *chat, int flush) { if (chat->status != DCCCHAT_UNUSED) { if (flush) { flushdccchat(chat); } usleep(100*1000); shutdown_close(chat->con.clientsocket); mydelete(chat->groups); mydelete(chat->hostmask); mydelete(chat->nick); mydelete(chat->con.localaddr); mydelete(chat->con.remoteaddr); ir_boutput_delete(&chat->boutput); if (chat->status == DCCCHAT_LISTENING) ir_listen_port_connected(chat->con.localport); #ifdef USE_UPNP if (gdata.upnp_router && (chat->con.family == AF_INET)) upnp_rem_redir(chat->con.localport); #endif /* USE_UPNP */ memset(chat, 0, sizeof(dccchat_t)); chat->con.clientsocket = FD_UNUSED; chat->status = DCCCHAT_UNUSED; gdata.num_dccchats--; } return; }
static void irc_005(ir_parseline_t *ipl) { unsigned int ii = 3; char *item; while((item = getpart(ipl->line, ++ii))) { if (item[0] == ':') { mydelete(item); break; } if (!strncmp("PREFIX=(", item, 8)) { char *ptr = item+8; unsigned int pi; memset(&(gnetwork->prefixes), 0, sizeof(gnetwork->prefixes)); for (pi = 0; (ptr[pi] && (ptr[pi] != ')') && (pi < MAX_PREFIX)); ++pi) { gnetwork->prefixes[pi].p_mode = ptr[pi]; } if (ptr[pi] == ')') { ptr += pi + 1; for (pi = 0; (ptr[pi] && (pi < MAX_PREFIX)); ++pi) { gnetwork->prefixes[pi].p_symbol = ptr[pi]; } } for (pi = 0; pi < MAX_PREFIX; ++pi) { if ((gnetwork->prefixes[pi].p_mode && !gnetwork->prefixes[pi].p_symbol) || (!gnetwork->prefixes[pi].p_mode && gnetwork->prefixes[pi].p_symbol)) { outerror(OUTERROR_TYPE_WARN, "Server prefix list on %s doesn't make sense, using defaults: %s", gnetwork->name, item); initprefixes(); } } } if (!strncmp("CHANMODES=", item, 10)) { char *ptr = item+10; unsigned int ci; unsigned int cm; memset(&(gnetwork->chanmodes), 0, sizeof(gnetwork->chanmodes)); for (ci = cm = 0; (ptr[ci] && (cm < MAX_CHANMODES)); ++ci) { if (ptr[ci+1] == ',') { /* we only care about ones with arguments */ gnetwork->chanmodes[cm++] = ptr[ci++]; } } } mydelete(item); } }
/* open file on disk for upload */ int l_setup_file(upload * const l, struct stat *stp) { char *fullfile; int retval; updatecontext(); if (l->uploaddir == NULL) { l_closeconn(l, "No uploaddir defined.", 0); return 1; } /* local file already exists? */ fullfile = mystrjoin(l->uploaddir, l->file, '/'); l->filedescriptor = open(fullfile, O_WRONLY | O_CREAT | O_EXCL | ADDED_OPEN_FLAGS, CREAT_PERMISSIONS ); if ((l->filedescriptor < 0) && (errno == EEXIST)) { retval = stat(fullfile, stp); if (retval < 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Stat Upload File '%s': %s", fullfile, strerror(errno)); l_closeconn(l, "File Error, File couldn't be opened for writing", errno); mydelete(fullfile); return 1; } if (!S_ISREG(stp->st_mode) || (stp->st_size >= l->totalsize)) { l_closeconn(l, "File Error, That filename already exists", 0); mydelete(fullfile); return 1; } l->filedescriptor = open(fullfile, O_WRONLY | O_APPEND | ADDED_OPEN_FLAGS); if (l->filedescriptor >= 0) { l->resumesize = l->bytesgot = stp->st_size; if (l->resumed <= 0) { close(l->filedescriptor); mydelete(fullfile); return 2; /* RESUME */ } } } if (l->filedescriptor < 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Access Upload File '%s': %s", fullfile, strerror(errno)); l_closeconn(l, "File Error, File couldn't be opened for writing", errno); mydelete(fullfile); return 1; } mydelete(fullfile); return 0; }
/* check permissions and setup the upload transfer */ void upload_start(const char *nick, const char *hostname, const char *hostmask, const char *filename, const char *remoteip, const char *remoteport, const char *bytes, char *token) { upload *ul; char *uploaddir; char *tempstr; off_t len; updatecontext(); len = atoull(bytes); if (invalid_upload(nick, hostmask, len)) return; uploaddir = get_uploaddir(hostmask); if (uploaddir == NULL) { error_upload_start(nick, hostmask, "no uploaddir", "No uploaddir defined."); return; } if (disk_full(uploaddir) != 0) { error_upload_start(nick, hostmask, "disk full", "not enough free space on disk"); return; } if (file_uploading(filename) != 0) { error_upload_start(nick, hostmask, "upload running", "I'm already getting this file"); return; } if (max_uploads_reached() != 0) { error_upload_start(nick, hostmask, "too many uploads", "I'm already getting too many files"); return; } ul = irlist_add(&gdata.uploads, sizeof(upload)); l_initvalues(ul); ul->file = mystrdup(getfilename(filename)); ul->con.family = (strchr(remoteip, ':')) ? AF_INET6 : AF_INET; ul->con.remoteaddr = mystrdup(remoteip); ul->con.remoteport = atoi(remoteport); ul->totalsize = len; ul->nick = mystrdup(nick); ul->hostname = mystrdup(hostname); ul->uploaddir = mystrdup(uploaddir); ul->net = gnetwork->net; qupload_started(gnetwork->net, nick); tempstr = getsendname(ul->file); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "DCC Send Accepted from %s on %s: %s (%" LLPRINTFMT "dkB)", nick, gnetwork->name, tempstr, (ul->totalsize / 1024)); mydelete(tempstr); if (gdata.mirc_dcc64) if (ul->totalsize > 0xFFFFFFFFL) ul->mirc_dcc64 = 1; if (ul->con.remoteport > 0U) { l_establishcon(ul); } else { /* Passive DCC */ l_setup_passive(ul, token); } }
/* call a ruby script as CGI via HTTP */ unsigned int http_ruby_script(const char *name, const char *output) { struct stat st; char *tempstr; int rc; updatecontext(); if (!name) return 1; if (stat(name, &st) < 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "cannot access '%s', ignoring: %s", name, strerror(errno)); return 1; } ruby_script(name); tempstr = mymalloc(maxtextlength); snprintf(tempstr, maxtextlength, "$stdout = File.new(\"%s\", \"w+\")", output); /* NOTRANSLATE */ rb_eval_string_protect(tempstr, &rc); mydelete(tempstr); rb_load_protect(rb_str_new(name, strlen(name)), 0, &rc); if (rc != 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "ruby_exec failed with %d: %s", rc, strerror(errno)); iroffer_ruby_errro(rc); } rb_eval_string_protect("$stdout.close", &rc); /* NOTRANSLATE */ if (rc != 0) return 1; return 0; }
static unsigned int telnet_open_listen(unsigned int i) { char *vhost = NULL; char *msg; unsigned int rc; ir_sockaddr_union_t listenaddr; updatecontext(); vhost = irlist_get_nth(&gdata.telnet_vhost, i); if (vhost == NULL) return 1; rc = open_listen(0, &listenaddr, &(telnet_listen[i]), gdata.telnet_port, 1, 0, vhost); if (rc != 0) return 1; telnet_family[i] = listenaddr.sa.sa_family; msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &listenaddr.sa); ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "Telnet SERVER waiting for connection on %s", msg); mydelete(msg); return 0; }
/* search the DDC transfer a user wants to resume */ unsigned int t_find_resume(const char *nick, const char *filename, const char *localport, const char *bytes, char *token) { char *sendnamestr; transfer *guess; transfer *tr; off_t len; guess = NULL; for (tr = irlist_get_head(&gdata.trans); tr; tr = irlist_get_next(tr)) { if ((tr->tr_status != TRANSFER_STATUS_LISTENING) && (tr->tr_status != TRANSFER_STATUS_RESUME)) continue; if (strcasecmp(tr->caps_nick, nick)) continue; /* the filename can be converted */ if (guess == NULL) guess = tr; if (strcasestr(tr->xpack->file, filename)) break; if (tr->con.localport == (unsigned)atoi(localport)) break; } if (tr == NULL) { if (guess != NULL) { outerror(OUTERROR_TYPE_WARN, "Guessed transfer that %s on %s tried to resume!", nick, gnetwork->name); outerror(OUTERROR_TYPE_WARN, "resume trying %s, %s, %d", nick, filename, atoi(localport)); tr = guess; } else { t_find_debug(nick, filename, localport); return 1; } } len = atoull(bytes); if (len >= tr->xpack->st_size) { notice(nick, "You can't resume the transfer at a point greater than the size of the file"); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "XDCC [%02i:%s on %s]: Resume attempted beyond end of file ( %" LLPRINTFMT "d >= %" LLPRINTFMT "d )", tr->id, tr->nick, gnetwork->name, len, tr->xpack->st_size); return 1; } t_setresume(tr, bytes); sendnamestr = getsendname(filename); if ((tr->tr_status == TRANSFER_STATUS_RESUME) && (token != NULL)) { privmsg_fast(nick, IRC_CTCP "DCC ACCEPT %s %s %s %s" IRC_CTCP, sendnamestr, localport, bytes, token); /* NOTRANSLATE */ } else { privmsg_fast(nick, IRC_CTCP "DCC ACCEPT %s %s %s" IRC_CTCP, sendnamestr, localport, bytes); /* NOTRANSLATE */ } mydelete(sendnamestr); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "XDCC [%02i:%s on %s]: Resumed at %" LLPRINTFMT "dK", tr->id, tr->nick, gnetwork->name, tr->startresume/1024); return 0; }
/* handle message from irc server */ static void ir_parseline(char *line) { ir_parseline_t ipl; unsigned int m; updatecontext(); removenonprintable(line); #ifdef USE_RUBY if (do_myruby_server(line)) return; #endif /* USE_RUBY */ /* we only support lines upto maxtextlength, truncate line */ line[maxtextlength-1] = '\0'; if (gdata.debug > 14) ioutput(OUT_S|OUT_L, COLOR_CYAN, ">IRC>: %u, %s", gnetwork->net + 1, line); bzero((char *)&ipl, sizeof(ipl)); ipl.line = line; m = get_argv(ipl.part, line, MAX_IRCMSG_PARTS); if (ipl.part[1] != NULL) ir_parseline2(&ipl); for (m = 0; m < MAX_IRCMSG_PARTS; ++m) mydelete(ipl.part[m]); }
static void update_getip_net(unsigned int net, ir_uint32 ourip) { char *oldtxt; gnetwork_t *backup; struct in_addr old; struct in_addr in; unsigned int ss; in.s_addr = htonl(ourip); backup = gnetwork; for (ss=0; ss<gdata.networks_online; ++ss) { gnetwork = &(gdata.networks[ss]); if (gnetwork->net == net) continue; if (gnetwork->getip_net != net) continue; if (gnetwork->ourip == ourip) continue; gnetwork->usenatip = 1; old.s_addr = htonl(gnetwork->ourip); oldtxt = mystrdup(inet_ntoa(old)); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "DCC IP changed from %s to %s on %s", oldtxt, inet_ntoa(in), gnetwork->name); mydelete(oldtxt); gnetwork->ourip = ourip; } gnetwork = backup; }
/* returns the size in a human readable form */ char *sizestr(unsigned int spaces, off_t num) { #define SIZESTR_SIZE 5L char *str = (char *)mymalloc(SIZESTR_SIZE); float val; unsigned int i; if (num <= 0) { snprintf(str, SIZESTR_SIZE, spaces ? "%4s" : "%s", "0"); /* NOTRANSLATE */ return str; } if (num < 1024) { snprintf(str, SIZESTR_SIZE, spaces ? "%4s" : "%s", "<1k"); /* NOTRANSLATE */ return str; } /* KB */ val = (float)num; for (i = 0; size_units[i]; ++i) { val /= 1024.0; if ((i > 0) && (val < 9.5)) { snprintf(str, SIZESTR_SIZE, spaces ? "%2.1f%c" : "%.1f%c", val, size_units[i]); /* NOTRANSLATE */ return str; } if (val < 999.5) { snprintf(str, SIZESTR_SIZE, spaces ? "%3.0f%c" : "%.0f%c", val, size_units[i]); /* NOTRANSLATE */ return str; } } mydelete(str); str = (char *)mymalloc(SIZESTR_SIZE + SIZESTR_SIZE); snprintf(str, SIZESTR_SIZE + SIZESTR_SIZE , "%.0fE", val); /* NOTRANSLATE */ return str; }
static void notice_transfer(const char *nick, xdcc *xd, const char *msg) { char *sizestrstr; sizestrstr = sizestr(0, xd->st_size); notice_fast(nick, "%s, which is %sB. (resume supported)", msg, sizestrstr); mydelete(sizestrstr); }
/* check that the given text is an IP address or hostname and store it as external DCC IP */ void update_natip(const char *var) { struct hostent *hp; struct in_addr old; struct in_addr in; ir_uint32 oldip; char *oldtxt; updatecontext(); if (var == NULL) return; gnetwork->usenatip = 1; if (gnetwork->myip.sa.sa_family != AF_INET) return; if (gnetwork->r_ourip != 0) return; bzero((char *)&in, sizeof(in)); if (inet_aton(var, &in) == 0) { hp = gethostbyname(var); if (hp == NULL) { outerror(OUTERROR_TYPE_WARN_LOUD, "Invalid NAT Host, Ignoring: %s", hstrerror(h_errno)); return; } if ((unsigned)hp->h_length > sizeof(in) || hp->h_length < 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "Invalid DNS response, Ignoring: %s", hstrerror(h_errno)); return; } memcpy(&in, hp->h_addr_list[0], sizeof(in)); } old.s_addr = htonl(gnetwork->ourip); if (old.s_addr == in.s_addr) return; oldip = gnetwork->ourip; gnetwork->ourip = ntohl(in.s_addr); if (oldip != gnetwork->ourip) { oldtxt = mystrdup(inet_ntoa(old)); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "DCC IP changed from %s to %s on %s", oldtxt, inet_ntoa(in), gnetwork->name); mydelete(oldtxt); update_getip_net(gnetwork->net, gnetwork->ourip); } if (gdata.debug > 0) ioutput(OUT_S|OUT_L, COLOR_YELLOW, "ip=%s\n", inet_ntoa(in)); /* check for 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 */ if (((gnetwork->ourip & 0xFF000000U) == 0x0A000000U) || ((gnetwork->ourip & 0xFFF00000U) == 0xAC100000U) || ((gnetwork->ourip & 0xFFFF0000U) == 0xC0A80000U)) { outerror(OUTERROR_TYPE_WARN_LOUD, "usenatip of %s looks wrong, this is probably not what you want to do", inet_ntoa(in)); } }
/* from curl tool_cb_hdr.c, Copyright (C) 1998 - 2011, Daniel Stenberg */ static size_t fetch_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) { const size_t cb = size * nmemb; const size_t failure = (cb) ? 0 : 1; fetch_curl_t *ft = userdata; char *temp; char *work; char *end; size_t len; updatecontext(); if (ft == NULL) return cb; /* ignore */ #ifdef DEBUG if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) { outerror(OUTERROR_TYPE_WARN_LOUD, "Header data = %ld exceeds single call write limit!", size); return failure; } #endif temp = mystrdup(ptr); len = cb; if (temp[len - 1] == '\n') { --(len); if (temp[len - 1] == '\r') { --(len); } } temp[len] = 0; if ((gdata.debug > 0) && (cb > 2)) { a_respond(&(ft->u), "FETCH header '%s'", temp); } if (cb >= 20) { if (strncasecmp("Content-disposition:", temp, 20) == 0) { /* NOTRANSLATE */ /* look for the 'filename=' parameter (encoded filenames (*=) are not supported) */ work = strstr(temp + 20, "filename="); /* NOTRANSLATE */ if (work != NULL) { work += 9; /* stop at first ; */ end = strchr(work, ';'); if (end != NULL) *end = 0; ft->contentname = mystrdup(work); clean_quotes(ft->contentname); a_respond(&(ft->u), "FETCH filename '%s'", ft->contentname); } } } mydelete(temp); return cb; }
/* complete the connection to the IRC server */ static unsigned int connectirc2(res_addrinfo_t *remote) { int retval; int family; if (remote->ai_reset) gnetwork->serv_resolv.next = 0; family = remote->ai_addr.sa_family; gnetwork->ircserver = socket(family, remote->ai_socktype, remote->ai_protocol); if (gnetwork->ircserver < 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "Socket Error: %s", strerror(errno)); return 1; } if (gdata.debug > 0) { char *msg; msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &(remote->ai_addr)); ioutput(OUT_S, COLOR_YELLOW, "Connecting to %s", msg); mydelete(msg); } if (bind_irc_vhost(family, gnetwork->ircserver) != 0) { outerror(OUTERROR_TYPE_WARN_LOUD, "Couldn't Bind To Virtual Host"); event_close(gnetwork->ircserver); return 1; } if (set_socket_nonblocking(gnetwork->ircserver, 1) < 0 ) outerror(OUTERROR_TYPE_WARN, "Couldn't Set Non-Blocking"); alarm(CTIMEOUT); retval = connect(gnetwork->ircserver, &(remote->ai_addr), remote->ai_addrlen); if ( (retval < 0) && !((errno == EINPROGRESS) || (errno == EAGAIN)) ) { outerror(OUTERROR_TYPE_WARN_LOUD, "Connection to Server Failed: %s", strerror(errno)); alarm(0); event_close(gnetwork->ircserver); return 1; } alarm(0); if (gdata.debug > 0) { ioutput(OUT_S, COLOR_YELLOW, "ircserver socket = %d", gnetwork->ircserver); } gnetwork->lastservercontact=gdata.curtime; /* good */ gnetwork->serverstatus = SERVERSTATUS_TRYING; return 0; }
void writestatus(dccchat_t *chat) { char *tempstr; updatecontext(); tempstr = mymalloc(maxtextlength); getstatusline(tempstr,maxtextlength); writedccchat(chat,0,"%s\n",tempstr); mydelete(tempstr); }
int setupdccchatout(const char *nick, const char *hostmask, const char *token) { char *msg; char *token2 = NULL; unsigned int rc; dccchat_t *chat; updatecontext(); chat = irlist_add(&gdata.dccchats, sizeof(dccchat_t)); chat->name = gnetwork->name; chat->status = DCCCHAT_UNUSED; chat->con.family = gnetwork->myip.sa.sa_family; rc = irc_open_listen(&(chat->con)); if (rc != 0) return 1; gdata.num_dccchats++; chat->status = DCCCHAT_LISTENING; chat->con.clientsocket = FD_UNUSED; chat->nick = mystrdup(nick); chat->net = gnetwork->net; chat->hostmask = mystrdup(hostmask); msg = setup_dcc_local(&(chat->con.local)); if (token != NULL) { privmsg_fast(nick, IRC_CTCP "DCC CHAT CHAT %s %s" IRC_CTCP, msg, token); } else { privmsg_fast(nick, IRC_CTCP "DCC CHAT CHAT %s" IRC_CTCP, msg); } my_getnameinfo(msg, maxtextlength -1, &(chat->con.local.sa)); chat->con.localaddr = mystrdup(msg); mydelete(token2); mydelete(msg); ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "DCC CHAT sent to %s on %s, waiting for connection on %s", nick, chat->name, chat->con.localaddr); return 0; }
static VALUE cie_message(void) { VALUE copy; char *val; val = getpart_eol(cLine, 4); if (val == NULL) return Qnil; copy = rb_str_new(val + 1, strlen(val + 1)); mydelete(val); return copy; }
static VALUE cie_channel(void) { VALUE copy; char *val; val = getpart(cLine, 3); if (val == NULL) return Qnil; copy = rb_str_new(val, strlen(val)); mydelete(val); return copy; }
/* convert a search string into fnmatch */ char *grep_to_fnmatch(const char *grep) { char *raw; char *match; size_t len; len = strlen(grep) + 3; raw = mymalloc(len); snprintf(raw, len, "*%s*", grep); /* NOTRANSLATE */ match = hostmask_to_fnmatch(raw); mydelete(raw); return match; }
/* check for a match with unlimitedhost */ void t_unlmited(transfer * const tr, const char *hostmask) { char *qhostmask; if (hostmask != NULL) { t_unlmited2(tr, hostmask); return; } qhostmask = to_hostmask(tr->nick, tr->hostname); t_unlmited2(tr, qhostmask); mydelete(qhostmask); }
static VALUE cie_hostmask(void) { VALUE copy; char *val; val = getpart(cLine, 1); if (val == NULL) return Qnil; copy = rb_str_new(val + 1, strlen(val + 1)); mydelete(val); return copy; }
/* accept incoming connection */ static void l_setup_accept(upload * const l) { SIGNEDSOCK int addrlen; char *msg; updatecontext(); addrlen = sizeof(l->con.remote); if ((l->con.clientsocket = accept(l->con.listensocket, &(l->con.remote.sa), &addrlen)) < 0) { outerror(OUTERROR_TYPE_WARN, "Accept Error, Aborting: %s", strerror(errno)); l->con.clientsocket = FD_UNUSED; l_closeconn(l, "Connection Lost", 0); return; } ir_listen_port_connected(l->con.localport); event_close(l->con.listensocket); l->con.listensocket = FD_UNUSED; ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "DCC SEND connection received"); ir_setsockopt(l->con.clientsocket); notice(l->nick, "DCC Send Accepted, Connecting..."); msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &(l->con.remote.sa)); mydelete(l->con.remoteaddr); l->con.remoteaddr = mystrdup(msg); mydelete(msg); l->con.remoteport = get_port(&(l->con.remote)); l->con.connecttime = gdata.curtime; l->con.lastcontact = gdata.curtime; l->ul_status = UPLOAD_STATUS_GETTING; }
static void irc_001(ir_parseline_t *ipl) { char *tptr; ioutput(OUT_S|OUT_L, COLOR_NO_COLOR, "Server welcome: %s", ipl->line); update_server_welcome(ipl->line); /* update server name */ mydelete(gnetwork->curserveractualname); gnetwork->curserveractualname = getpart(ipl->line + 1, 1); /* update nick */ mydelete(gnetwork->user_nick); mydelete(gnetwork->caps_nick); gnetwork->user_nick = mystrdup(ipl->part[2]); gnetwork->caps_nick = mystrdup(ipl->part[2]); caps(gnetwork->caps_nick); gnetwork->nick_number = 0; gnetwork->next_restrict = gdata.curtime + gdata.restrictsend_delay; ++(gdata.needsclear); tptr = get_user_modes(); if (tptr && tptr[0]) { writeserver(WRITESERVER_NOW, "MODE %s %s", gnetwork->user_nick, tptr); } /* server connected raw command */ for (tptr = irlist_get_head(&(gnetwork->server_connected_raw)); tptr; tptr = irlist_get_next(tptr)) { writeserver(WRITESERVER_NORMAL, "%s", tptr); } /* nickserv */ identify_needed(0); }
/* build a pattern to match this user and hostname */ char *to_hostmask(const char *nick, const char *hostname) { char *nick2; char *hostmask; size_t len; len = strlen(hostname) + strlen(nick) + 4; hostmask = (char *)mymalloc(len); nick2 = mystrdup(nick); replace_char(nick2, '[', '?'); replace_char(nick2, ']', '?'); snprintf(hostmask, len, "%s!*@%s", nick2, hostname); mydelete(nick2); return hostmask; }
/* start next transfer */ void fetch_next(void) { gnetwork_t *backup; fetch_queue_t *fq; updatecontext(); if (irlist_size(&gdata.fetch_queue) == 0) return; fq = irlist_get_head(&gdata.fetch_queue); if (fq == NULL) return; backup = gnetwork; gnetwork = &(gdata.networks[fq->net]); fetch_now(&(fq->u), fq->uploaddir, fq->name, fq->url); mydelete(fq->u.snick); mydelete(fq->name); mydelete(fq->url); mydelete(fq->uploaddir); irlist_delete(&gdata.fetch_queue, fq); gnetwork = backup; }
/* remove temp uploadhosts */ void clean_uploadhost(void) { tupload_t *tu; updatecontext(); for (tu = irlist_get_head(&gdata.tuploadhost); tu; ) { if (tu->u_time >= gdata.curtime) { tu = irlist_get_next(tu); continue; } mydelete(tu->u_host); tu = irlist_delete(&gdata.tuploadhost, tu); } }
void setupdccchataccept(dccchat_t *chat) { SIGNEDSOCK int addrlen; char *msg; updatecontext(); addrlen = sizeof(struct sockaddr_in); if ((chat->con.clientsocket = accept(chat->con.listensocket, &(chat->con.remote.sa), &addrlen)) < 0) { outerror(OUTERROR_TYPE_WARN,"Accept Error, Aborting: %s",strerror(errno)); event_close(chat->con.listensocket); chat->con.clientsocket = FD_UNUSED; chat->con.listensocket = FD_UNUSED; return; } ir_listen_port_connected(chat->con.localport); event_close(chat->con.listensocket); chat->con.listensocket = FD_UNUSED; ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "DCC CHAT connection received, authenticating"); if (set_socket_nonblocking(chat->con.clientsocket, 1) < 0 ) { outerror(OUTERROR_TYPE_WARN,"Couldn't Set Non-Blocking"); } if (is_in_badip(&(chat->con.remote))) { shutdowndccchat(chat, 0); return; } chat->status = DCCCHAT_AUTHENTICATING; chat->con.connecttime = gdata.curtime; chat->con.lastcontact = gdata.curtime; ir_boutput_init(&chat->boutput, chat->con.clientsocket, 0); msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &(chat->con.remote.sa)); chat->con.remoteaddr = mystrdup(msg); mydelete(msg); setup_chat_banner(chat); }