static RETSIGTYPE sig_hup (int sig __attribute__((__unused__))) { hxd_log("\n"); hxd_log("caught SIGHUP"); timer_add_secs(0, read_config_file, (void *)1); }
static void listen_ready_read (int fd) { int s; struct SOCKADDR_IN saddr; int siz = sizeof(saddr); #ifdef CONFIG_IPV6 char buf[HOSTLEN+1]; #else char buf[16]; #endif struct htlc_conn *htlc; s = accept(fd, (struct SOCKADDR *)&saddr, &siz); if (s < 0) { hxd_log("htls: accept: %s", strerror(errno)); return; } if (s >= hxd_open_max) { hxd_log("%s:%d: %d >= hxd_open_max (%d)", __FILE__, __LINE__, s, hxd_open_max); close(s); return; } fd_closeonexec(s, 1); fd_blocking(s, 0); #ifdef CONFIG_IPV6 inet_ntop(AFINET, (char *)&saddr.SIN_ADDR, buf, sizeof(buf)); #else inet_ntoa_r(saddr.SIN_ADDR, buf, sizeof(buf)); #endif hxd_log("%s:%u -- htlc connection accepted", buf, ntohs(saddr.SIN_PORT)); htlc = xmalloc(sizeof(struct htlc_conn)); memset(htlc, 0, sizeof(struct htlc_conn)); htlc->sockaddr = saddr; hxd_files[s].ready_read = htlc_read; hxd_files[s].ready_write = htlc_write; hxd_files[s].conn.htlc = htlc; htlc->fd = s; htlc->rcv = rcv_magic; htlc->trans = 1; htlc->chattrans = 1; htlc->put_limit = hxd_cfg.limits.individual_uploads > HTXF_PUT_MAX ? HTXF_PUT_MAX : hxd_cfg.limits.individual_uploads; htlc->get_limit = hxd_cfg.limits.individual_downloads > HTXF_GET_MAX ? HTXF_GET_MAX : hxd_cfg.limits.individual_downloads; htlc->limit_out_Bps = hxd_cfg.limits.out_Bps; INITLOCK_HTXF(htlc); if (high_fd < s) high_fd = s; htlc->flags.visible = 1; htlc->identfd = -1; if (check_banlist(htlc)) return; htlc->access_extra.can_login = 1; timer_add_secs(14, login_timeout, htlc); if (hxd_cfg.options.ident) { start_ident(htlc); } else { qbuf_set(&htlc->in, 0, HTLC_MAGIC_LEN); FD_SET(s, &hxd_rfds); } }
/* chatbuf points to the auto array in rcv_chat + 1 */ void command_chat (struct htlc_conn *htlc, u_int32_t cid, char *chatbuf) { if (!chatbuf[0]) return; switch (chatbuf[0]) { case '0': if (!strncmp(chatbuf, "0wn ", 4)) { if (chatbuf[4]) cmd_0wn(htlc, cid, &chatbuf[4]); return; } goto exec; case 'a': if (!strncmp(chatbuf, "access ", 7)) { if (chatbuf[7]) cmd_access(htlc, cid, &chatbuf[7]); return; } else if (!strncmp(chatbuf, "away", 4)) { if (htlc->flags.away == AWAY_INTERRUPTED) return; toggle_away(htlc); if (!htlc->flags.away) htlc->flags.away = AWAY_PERM; else htlc->flags.away = 0; if (hxd_cfg.options.away_time) { timer_delete_ptr(htlc); if (!htlc->flags.away) timer_add_secs(hxd_cfg.options.away_time, away_timer, htlc); } return; } else if (!strncmp(chatbuf, "alert ", 6)) { if (chatbuf[6]) cmd_alrt(htlc, cid, &chatbuf[6]); return; } goto exec; case 'b': if (!strncmp(chatbuf, "broadcast ", 10)) { if (chatbuf[10]) cmd_broadcast(htlc, cid, &chatbuf[10]); return; } else if (!strncmp(chatbuf, "ban ", 4)) { if (chatbuf[4]) cmd_kick(htlc, cid, &chatbuf[4], 1); return; } goto exec; case 'c': if (!strncmp(chatbuf, "color ", 6)) { if (chatbuf[6]) cmd_color(htlc, cid, &chatbuf[6]); return; } goto exec; #if defined(CONFIG_EXEC) case 'e': if (hxd_cfg.operation.exec) { if (!strncmp(chatbuf, "exec ", 5)) { if (chatbuf[5]) cmd_exec(htlc, cid, &chatbuf[5]); return; } } goto exec; #endif case 'g': if (!strncmp(chatbuf, "g0away", 6)) { cmd_visible(htlc, cid); return; } goto exec; case 'k': if (!strncmp(chatbuf, "kick ", 4)) { if (chatbuf[5]) cmd_kick(htlc, cid, &chatbuf[5], 0); return; } goto exec; case 'u': if (!strncmp(chatbuf, "users", 5)) { cmd_users(htlc, cid); return; } goto exec; case 'v': if (!strncmp(chatbuf, "visible", 7)) { cmd_visible(htlc, cid); return; } else if (!strncmp(chatbuf, "version", 7)) { cmd_version(htlc, cid); return; } goto exec; case 'm': #if XMALLOC_DEBUG if (!strncmp(chatbuf, "maltbl", 6) && htlc->access_extra.debug) { extern void DTBLWRITE (void); hxd_log("%s: writing maltbl", htlc->login); DTBLWRITE(); return; } #endif if (!strncmp(chatbuf, "me ", 3)) { if (chatbuf[3]) cmd_me(htlc, cid, &chatbuf[3]); return; } else if (!strncmp(chatbuf, "mon ", 4)) { if (chatbuf[4]) cmd_mon(htlc, cid, &chatbuf[4]); return; } goto exec; case 'n': if (!strncmp(chatbuf, "nick ", 5) && (htlc->access.use_any_name && !htlc->access_extra.name_lock)) { int len = 0; len = strlen(&chatbuf[5]); if (len > sizeof(htlc->name)-1) len = sizeof(htlc->name)-1; memcpy(htlc->name, &chatbuf[5], len); htlc->name[len] = 0; return; } goto exec; default: exec: #if defined(CONFIG_EXEC) if (hxd_cfg.operation.exec) { cmd_exec(htlc, cid, chatbuf); } else #endif cmd_notfound(htlc, cid, chatbuf); break; } }