/* * Reset the network card(s). * * This function is called each time the system is reset, * either a hard reset (including power-up) or a soft reset * including C-A-D reset.) It is responsible for connecting * everything together. */ void network_reset(void) { int i = -1; #ifdef ENABLE_NIC_LOG network_log("NETWORK: reset (type=%d, card=%d) debug=%d\n", network_type, network_card, nic_do_log); #else network_log("NETWORK: reset (type=%d, card=%d)\n", network_type, network_card); #endif ui_sb_update_icon(SB_NETWORK, 0); /* Just in case.. */ network_close(); /* If no active card, we're done. */ if ((network_type==NET_TYPE_NONE) || (network_card==0)) return; network_mutex = thread_create_mutex(L"VARCem.NetMutex"); /* Initialize the platform module. */ switch(network_type) { case NET_TYPE_PCAP: i = net_pcap_init(); break; case NET_TYPE_SLIRP: i = net_slirp_init(); break; } if (i < 0) { /* Tell user we can't do this (at the moment.) */ ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2102); // FIXME: we should ask in the dialog if they want to // reconfigure or quit, and throw them into the // Settings dialog if yes. /* Disable network. */ network_type = NET_TYPE_NONE; return; } network_log("NETWORK: set up for %s, card='%s'\n", (network_type==NET_TYPE_SLIRP)?"SLiRP":"Pcap", net_cards[network_card].name); /* Add the (new?) card to the I/O system. */ if (net_cards[network_card].device) { network_log("NETWORK: adding device '%s'\n", net_cards[network_card].name); device_add(net_cards[network_card].device); } }
static void on_transport_log(struct irc_transport *transport, const struct irc_line *l, const GError *error) { struct irc_network *network = transport->userdata; const char *errmsg = (error == NULL)?"UNKNOWN":error->message; if (l->argc == 0) network_log(LOG_WARNING, network, "Error while sending empty line: %s", errmsg); else network_log(LOG_WARNING, network, "Error while sending line '%s': %s", l->args[0], errmsg); }
/* Stop any network activity. */ void network_close(void) { /* If already closed, do nothing. */ if (network_mutex == NULL) return; /* Force-close the PCAP module. */ net_pcap_close(); /* Force-close the SLIRP module. */ net_slirp_close(); /* Close the network events. */ if (poll_data.wake_poll_thread != NULL) { thread_destroy_event(poll_data.wake_poll_thread); poll_data.wake_poll_thread = NULL; } if (poll_data.poll_complete != NULL) { thread_destroy_event(poll_data.poll_complete); poll_data.poll_complete = NULL; } /* Close the network thread mutex. */ thread_close_mutex(network_mutex); network_mutex = NULL; network_mac = NULL; network_log("NETWORK: closed.\n"); }
static void server_send_login (struct irc_network *s) { struct irc_login_details *login_details = s->callbacks->get_login_details(s); g_assert(s); s->connection.state = NETWORK_CONNECTION_STATE_LOGIN_SENT; network_log(LOG_TRACE, s, "Sending login details"); s->external_state = network_state_init(login_details->nick, login_details->username, get_my_hostname()); network_state_set_log_fn(s->external_state, state_log_helper, s); if (s->callbacks->state_set) s->callbacks->state_set(s); g_assert(s->linestack != NULL); if (login_details->password != NULL) { network_send_args(s, "PASS", login_details->password, NULL); } g_assert(login_details->nick != NULL && strlen(login_details->nick) > 0); network_send_args(s, "NICK", login_details->nick, NULL); g_assert(login_details->username != NULL && strlen(login_details->username) > 0); g_assert(login_details->mode != NULL && strlen(login_details->mode) > 0); g_assert(login_details->unused != NULL && strlen(login_details->unused) > 0); g_assert(login_details->realname != NULL && strlen(login_details->realname) > 0); network_send_args(s, "USER", login_details->username, login_details->mode, login_details->unused, login_details->realname, NULL); free_login_details(login_details); }
static void on_transport_charset_error(struct irc_transport *transport, const char *error_msg) { struct irc_network *network = transport->userdata; network_log(LOG_WARNING, network, "Error while sending line with charset: %s", error_msg); }
/** * Change the character set used to communicate with the server. * * @param n network to change the character set for * @param name name of the character set to use * @return true if setting the charset worked */ gboolean network_set_charset(struct irc_network *n, const char *name) { if (!transport_set_charset(n->connection.transport, name)) { network_log(LOG_WARNING, n, "Unable to find charset `%s'", name); return FALSE; } return TRUE; }
void log_network_line(const struct irc_network *n, const struct irc_line *l, gboolean incoming) { char *raw; if (current_log_level < LOG_DATA) return; raw = irc_line_string(l); network_log(LOG_DATA, n, "%c %s", incoming?'<':'>', raw); g_free(raw); }
void message(const char *format, ...) { va_list args, args2; va_start(args, format); __va_copy(args2, args); print_log(TERM_FG_WHITE "[Message]", format, args); network_log(format, args2); va_end(args); va_end(args2); }
static void network_report_disconnect(struct irc_network *n, const char *fmt, ...) { va_list ap; char *tmp; va_start(ap, fmt); tmp = g_strdup_vprintf(fmt, ap); va_end(ap); g_free(n->connection.data.tcp.last_disconnect_reason); n->connection.data.tcp.last_disconnect_reason = tmp; network_log(LOG_WARNING, n, "%s", tmp); }
static void state_log_helper(enum log_level l, void *userdata, const char *msg) { network_log(l, (const struct irc_network *)userdata, "%s", msg); }