int route_to_user(struct hub_info* hub, struct hub_user* user, struct adc_message* msg) { #ifdef DEBUG_SENDQ char* data = strndup(msg->cache, msg->length-1); LOG_PROTO("send %s: \"%s\"", sid_to_string(user->id.sid), data); free(data); #endif if (!user->connection) return 0; uhub_assert(msg->cache && *msg->cache); if (ioq_send_is_empty(user->send_queue) && !user_flag_get(user, flag_pipeline)) { /* Perform oportunistic write */ ioq_send_add(user->send_queue, msg); handle_net_write(user); } else { if (check_send_queue(hub, user, msg) >= 0) { ioq_send_add(user->send_queue, msg); if (!user_flag_get(user, flag_pipeline)) user_net_io_want_write(user); } } return 1; }
ssize_t net_con_ssl_accept(struct net_connection* con) { struct net_ssl_openssl* handle = get_handle(con); handle->state = tls_st_accepting; ssize_t ret; ret = SSL_accept(handle->ssl); LOG_PROTO("SSL_accept() ret=%d", ret); if (ret > 0) { net_con_update(con, NET_EVENT_READ); handle->state = tls_st_connected; return ret; } return handle_openssl_error(con, ret, tls_st_accepting); }
ssize_t net_ssl_send(struct net_connection* con, const void* buf, size_t len) { struct net_ssl_openssl* handle = get_handle(con); uhub_assert(handle->state == tls_st_connected); ERR_clear_error(); ssize_t ret = SSL_write(handle->ssl, buf, len); add_io_stats(handle); LOG_PROTO("SSL_write(con=%p, buf=%p, len=" PRINTF_SIZE_T ") => %d", con, buf, len, ret); if (ret > 0) handle->ssl_write_events = 0; else ret = handle_openssl_error(con, ret, 0); net_ssl_update(con, handle->events); // Update backend only return ret; }
int hub_handle_message(struct hub_info* hub, struct hub_user* u, const char* line, size_t length) { int ret = 0; struct adc_message* cmd = 0; LOG_PROTO("recv %s: %s", sid_to_string(u->id.sid), line); if (user_is_disconnecting(u)) return -1; cmd = adc_msg_parse_verify(u, line, length); if (cmd) { switch (cmd->cmd) { case ADC_CMD_HSUP: CHECK_FLOOD(extras, 0); ret = hub_handle_support(hub, u, cmd); break; case ADC_CMD_HPAS: CHECK_FLOOD(extras, 0); ret = hub_handle_password(hub, u, cmd); break; case ADC_CMD_BINF: CHECK_FLOOD(update, 1); ret = hub_handle_info(hub, u, cmd); break; case ADC_CMD_DINF: case ADC_CMD_EINF: case ADC_CMD_FINF: case ADC_CMD_BQUI: case ADC_CMD_DQUI: case ADC_CMD_EQUI: case ADC_CMD_FQUI: /* these must never be allowed for security reasons, so we ignore them. */ CHECK_FLOOD(extras, 1); break; case ADC_CMD_EMSG: case ADC_CMD_DMSG: case ADC_CMD_BMSG: case ADC_CMD_FMSG: CHECK_FLOOD(chat, 1); ret = hub_handle_chat_message(hub, u, cmd); break; case ADC_CMD_BSCH: case ADC_CMD_DSCH: case ADC_CMD_ESCH: case ADC_CMD_FSCH: cmd->priority = -1; if (plugin_handle_search(hub, u, cmd->cache) == st_deny) break; CHECK_FLOOD(search, 1); ROUTE_MSG; case ADC_CMD_FRES: // spam case ADC_CMD_BRES: // spam case ADC_CMD_ERES: // pointless. CHECK_FLOOD(extras, 1); break; case ADC_CMD_DRES: cmd->priority = -1; if (plugin_handle_search_result(hub, u, uman_get_user_by_sid(hub->users, cmd->target), cmd->cache) == st_deny) break; /* CHECK_FLOOD(search, 0); */ ROUTE_MSG; case ADC_CMD_DRCM: cmd->priority = -1; if (plugin_handle_revconnect(hub, u, uman_get_user_by_sid(hub->users, cmd->target)) == st_deny) break; CHECK_FLOOD(connect, 1); ROUTE_MSG; case ADC_CMD_DCTM: cmd->priority = -1; if (plugin_handle_connect(hub, u, uman_get_user_by_sid(hub->users, cmd->target)) == st_deny) break; CHECK_FLOOD(connect, 1); ROUTE_MSG; case ADC_CMD_BCMD: case ADC_CMD_DCMD: case ADC_CMD_ECMD: case ADC_CMD_FCMD: case ADC_CMD_HCMD: CHECK_FLOOD(extras, 1); break; default: CHECK_FLOOD(extras, 1); ROUTE_MSG; } adc_msg_free(cmd); } else { if (!user_is_logged_in(u)) { ret = -1; } } return ret; }
int hub_handle_message(struct hub_info* hub, struct hub_user* u, const char* line, size_t length) { int ret = 0; struct adc_message* cmd = 0; LOG_PROTO("recv %s: %s", sid_to_string(u->id.sid), line); if (user_is_disconnecting(u)) return -1; cmd = adc_msg_parse_verify(u, line, length); if (cmd) { switch (cmd->cmd) { case ADC_CMD_HSUP: CHECK_FLOOD(extras, 0); ret = hub_handle_support(hub, u, cmd); break; case ADC_CMD_HPAS: CHECK_FLOOD(extras, 0); ret = hub_handle_password(hub, u, cmd); break; case ADC_CMD_BINF: CHECK_FLOOD(update, 1); ret = hub_handle_info(hub, u, cmd); break; case ADC_CMD_DINF: case ADC_CMD_EINF: case ADC_CMD_FINF: /* these must never be allowed for security reasons, so we ignore them. */ break; case ADC_CMD_EMSG: case ADC_CMD_DMSG: case ADC_CMD_BMSG: case ADC_CMD_FMSG: CHECK_FLOOD(chat, 1); ret = hub_handle_chat_message(hub, u, cmd); break; case ADC_CMD_BSCH: case ADC_CMD_DSCH: case ADC_CMD_ESCH: case ADC_CMD_FSCH: cmd->priority = -1; CHECK_CHAT_ONLY; CHECK_FLOOD(search, 1); ROUTE_MSG; case ADC_CMD_DRES: cmd->priority = -1; CHECK_CHAT_ONLY; /* CHECK_FLOOD(search, 0); */ ROUTE_MSG; case ADC_CMD_DRCM: case ADC_CMD_DCTM: cmd->priority = -1; CHECK_CHAT_ONLY; CHECK_FLOOD(connect, 1); ROUTE_MSG; default: CHECK_FLOOD(extras, 1); ROUTE_MSG; } adc_msg_free(cmd); } else { if (!user_is_logged_in(u)) { ret = -1; } } return ret; }