static void handle_insert(int argc, char **argv) { struct irc_line *l; enum data_direction direction; if (argc < 2) { fprintf(stderr, "Usage: insert <client|server> <line>\n"); return; } if (!g_strcasecmp(argv[1], "client")) direction = TO_SERVER; else if (!g_strcasecmp(argv[1], "server")) direction = FROM_SERVER; else { fprintf(stderr, "Unable to parse direction `%s'\n", argv[1]); return; } l = irc_parse_line(argv[2]); if (l == NULL) { fprintf(stderr, "Error parsing line\n"); return; } linestack_insert_line(ctx, l, direction, state); }
void ipc_to_master_str( char *format, ... ) { char *msg_buf; va_list params; va_start( params, format ); msg_buf = g_strdup_vprintf( format, params ); va_end( params ); if( strlen( msg_buf ) > 512 ) { /* Don't send it, it's too long... */ } else if( global.conf->runmode == RUNMODE_FORKDAEMON ) { if( global.listen_socket >= 0 ) if( write( global.listen_socket, msg_buf, strlen( msg_buf ) ) <= 0 ) ipc_child_disable(); } else if( global.conf->runmode == RUNMODE_DAEMON ) { char **cmd, *s; if( ( s = strchr( msg_buf, '\r' ) ) ) *s = 0; cmd = irc_parse_line( msg_buf ); ipc_command_exec( NULL, cmd, ipc_master_commands ); g_free( cmd ); } g_free( msg_buf ); }
END_TEST void state_process(struct irc_network_state *ns, const char *line) { struct irc_line *l; l = irc_parse_line(line); g_assert(l); g_assert(state_handle_data(ns, l)); free_line(l); }
struct irc_line *irc_parse_linef(const char *fmt, ...) { va_list ap; char *ret; struct irc_line *l; va_start(ap, fmt); ret = g_strdup_vprintf(fmt, ap); l = irc_parse_line(ret); g_free(ret); va_end(ap); return l; }
static void handle_irc_line (struct network *net, char *line) { struct reply_handler *hand; struct irc_reply *rpl; int index; network_write_raw(net, line); rpl = irc_parse_line(line); if(rpl == NULL) DEBUG_PRINT("!!!!ERROR!!!!"); DEBUG_PRINT("Reply:"); DEBUG_PRINT("Prefix: %s", rpl->prefix.raw); DEBUG_PRINT("Prefix User: %s", rpl->prefix.user); DEBUG_PRINT("Prefix Host: %s", rpl->prefix.host); DEBUG_PRINT("Code: %d", rpl->code); DEBUG_PRINT("Cmd: %s", rpl->cmd); ARRAY_FOREACH(rpl->lines, index) DEBUG_PRINT("Line %d: %s", index, rpl->lines.arr[index]); DEBUG_PRINT("Colon: %s", rpl->colon); for (hand = reply_handler_list; hand->handler != NULL; hand++) { if (hand->cmd && rpl->cmd) { if (strcmp(hand->cmd, rpl->cmd) == 0) { DEBUG_PRINT("Handler: %p", hand->handler); (hand->handler) (net, rpl); goto cleanup; } } else if (hand->code > 0) { if (hand->code == rpl->code) { DEBUG_PRINT("Handler: %p", hand->handler); (hand->handler) (net, rpl); goto cleanup; } } } if (hand->handler == NULL) (reply_handler_list[0].handler) (net, rpl); cleanup: irc_reply_free(rpl); }
void ipc_to_children_str( char *format, ... ) { char *msg_buf; va_list params; va_start( params, format ); msg_buf = g_strdup_vprintf( format, params ); va_end( params ); if( strlen( msg_buf ) > 512 ) { /* Don't send it, it's too long... */ } else if( global.conf->runmode == RUNMODE_FORKDAEMON ) { int msg_len = strlen( msg_buf ); GSList *l, *next; for( l = child_list; l; l = next ) { struct bitlbee_child *c = l->data; next = l->next; if( write( c->ipc_fd, msg_buf, msg_len ) <= 0 ) ipc_master_free_one( c ); } } else if( global.conf->runmode == RUNMODE_DAEMON ) { char **cmd, *s; if( ( s = strchr( msg_buf, '\r' ) ) ) *s = 0; cmd = irc_parse_line( msg_buf ); ipc_to_children( cmd ); g_free( cmd ); } g_free( msg_buf ); }
GIOStatus irc_sendf(GIOChannel *c, GIConv iconv, GError **error, char *fmt, ...) { va_list ap; char *r = NULL; struct irc_line *l; GIOStatus ret; g_assert(c); g_assert(fmt); va_start(ap, fmt); r = g_strdup_vprintf(fmt, ap); l = irc_parse_line(r); g_free(r); ret = irc_send_line(c, iconv, l, error); free_line(l); return ret; }
gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond ) { char *buf, **cmd; if( ( buf = ipc_readline( source, &ipc_child_recv_fd ) ) ) { cmd = irc_parse_line( buf ); if( cmd ) { ipc_command_exec( data, cmd, ipc_child_commands ); g_free( cmd ); } g_free( buf ); } else { ipc_child_disable(); } return TRUE; }
gboolean ipc_master_read( gpointer data, gint source, b_input_condition cond ) { struct bitlbee_child *child = data; char *buf, **cmd; if( ( buf = ipc_readline( source, &child->to_fd ) ) ) { cmd = irc_parse_line( buf ); if( cmd ) { ipc_command_exec( child, cmd, ipc_master_commands ); g_free( cmd ); } g_free( buf ); } else { ipc_master_free_fd( source ); } return TRUE; }
GIOStatus irc_recv_line(GIOChannel *c, GIConv iconv, GError **error, struct irc_line **l) { gchar *raw = NULL, *cvrt = NULL; GIOStatus status; gsize in_len; g_assert(l != NULL); *l = NULL; g_assert(c); status = g_io_channel_read_line(c, &raw, &in_len, NULL, error); if (status != G_IO_STATUS_NORMAL) { g_free(raw); return status; } if (iconv == (GIConv)-1) { cvrt = raw; } else { cvrt = g_convert_with_iconv(raw, -1, iconv, NULL, NULL, error); if (cvrt == NULL) { cvrt = raw; status = G_IO_STATUS_ERROR; } else { g_free(raw); } } *l = irc_parse_line(cvrt); g_free(cvrt); return status; }
void irc_process(irc_t *irc) { char **lines, *temp, **cmd; int i; if (irc->readbuffer != NULL) { lines = irc_splitlines(irc->readbuffer); for (i = 0; *lines[i] != '\0'; i++) { char *conv = NULL; /* [WvG] If the last line isn't empty, it's an incomplete line and we should wait for the rest to come in before processing it. */ if (lines[i + 1] == NULL) { temp = g_strdup(lines[i]); g_free(irc->readbuffer); irc->readbuffer = temp; i++; break; } if (irc->iconv != (GIConv) - 1) { gsize bytes_read, bytes_written; conv = g_convert_with_iconv(lines[i], -1, irc->iconv, &bytes_read, &bytes_written, NULL); if (conv == NULL || bytes_read != strlen(lines[i])) { /* GLib can do strange things if things are not in the expected charset, so let's be a little bit paranoid here: */ if (irc->status & USTATUS_LOGGED_IN) { irc_rootmsg(irc, "Error: Charset mismatch detected. The charset " "setting is currently set to %s, so please make " "sure your IRC client will send and accept text in " "that charset, or tell BitlBee which charset to " "expect by changing the charset setting. See " "`help set charset' for more information. Your " "message was ignored.", set_getstr(&irc->b->set, "charset")); g_free(conv); conv = NULL; } else { irc_write(irc, ":%s NOTICE * :%s", irc->root->host, "Warning: invalid characters received at login time."); conv = g_strdup(lines[i]); for (temp = conv; *temp; temp++) { if (*temp & 0x80) { *temp = '?'; } } } } lines[i] = conv; } if (lines[i] && (cmd = irc_parse_line(lines[i]))) { irc_exec(irc, cmd); g_free(cmd); } g_free(conv); /* Shouldn't really happen, but just in case... */ if (!g_slist_find(irc_connection_list, irc)) { g_free(lines); return; } } if (lines[i] != NULL) { g_free(irc->readbuffer); irc->readbuffer = NULL; } g_free(lines); } }
static gboolean handle_client_detect(GIOChannel *ioc, struct pending_client *pc) { GIOStatus status; gsize read; gchar header[2]; GError *error = NULL; status = g_io_channel_read_chars(ioc, header, 1, &read, &error); if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN) { if (error != NULL) g_error_free(error); return FALSE; } if (header[0] == SOCKS_VERSION) { listener_log(LOG_TRACE, pc->listener, "Detected SOCKS."); pc->type = CLIENT_TYPE_SOCKS; pc->socks.state = SOCKS_STATE_NEW; return TRUE; } else { struct irc_line *l = NULL; gchar *raw = NULL, *cvrt = NULL; gchar *complete; GIOStatus status; gboolean ret; gsize in_len; pc->type = CLIENT_TYPE_REGULAR; g_assert(ioc != NULL); status = g_io_channel_read_line(ioc, &raw, &in_len, NULL, &error); if (status != G_IO_STATUS_NORMAL) { g_free(raw); g_error_free(error); return status; } complete = g_malloc(in_len+2); complete[0] = header[0]; memcpy(complete+1, raw, in_len); complete[in_len+1] = '\0'; g_free(raw); if (pc->listener->iconv == (GIConv)-1) { cvrt = complete; } else { cvrt = g_convert_with_iconv(complete, -1, pc->listener->iconv, NULL, NULL, &error); if (cvrt == NULL) { cvrt = complete; status = G_IO_STATUS_ERROR; if (error != NULL) g_error_free(error); } else { g_free(complete); } } l = irc_parse_line(cvrt); ret = pc->listener->ops->handle_client_line(pc, l); free_line(l); g_free(cvrt); return ret; } }
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <stdio.h> #include <string.h> #include <check.h> #include "ctrlproxy.h" #include "torture.h" #include "internals.h" START_TEST(test_no_subst) char *s; struct irc_line *l; l = irc_parse_line("PRIVMSG :"); s = custom_subst(NULL, "bla", l, "", FALSE, FALSE); fail_if(strcmp(s, "bla")); free_line(l); END_TEST START_TEST(test_percent) char *s; struct irc_line *l; l = irc_parse_line("PRIVMSG :"); s = custom_subst(NULL, "bla%%", l, "", FALSE, FALSE); fail_if(strcmp(s, "bla%")); free_line(l); END_TEST START_TEST(test_nick)