/* * looks in all the approp directories */ void *bnirc_dlopen(const char *name, int mode) { assert(name); char buf[412]; size_t i; void *f; if (bool_option("verbose")) cio_out("trying to open %s\n", name); if ((f = dlopen(name, mode)) != NULL) return f; strncpy(buf, getenv("HOME"), 200); strcat(buf, "/.bnIRC/"); strncat(buf, name, 200); if (bool_option("verbose")) cio_out("trying to open %s\n", buf); if ((f = dlopen(buf, mode)) != NULL) return f; for (i = 0; f == NULL && dirs[i] != NULL; i++) { strncpy(buf, dirs[i], 200); strncat(buf, name, 200); if (bool_option("verbose")) cio_out("trying to open %s\n", buf); f = dlopen(buf, mode); } return f; }
std::vector<bool_option> factory_generator_cuda::get_bool_options() { std::vector<bool_option> res; res.push_back(bool_option("cuda_dont_share_buffers", &cuda_dont_share_buffers, false, "Don't share buffers between layer. Switch it on if you suspect a bug in there")); res.push_back(bool_option("cuda_single_command_stream", &cuda_single_command_stream, false, "Use single stream for kernels. Switch it on if you suspect a bug when kernels are submitted into multiple streams")); return res; }
static int ping_hook ( int argc, char *argv[] ) { if(bool_option("show_pongs")) cio_out("responding to PING with '%s'\n", argv[1]); irc_out("PONG %s\n", argv[1]); return 0; }
void register_poll(irc_poll_t * sel) { int i; for (i = 0; i < slots_in_use; i++) { if (fds[i].fd == sel->fd) { assert(!"attempt to add irc_poll_t multiple times!"); } } i = alloc_free_slot(); fds[i].fd = sel->fd; fds[i].events = POLLIN; poll_pointers[i] = sel; sel->in = fdopen(sel->fd, "r"); sel->out = fdopen(sel->fd, "w"); /* is there a nicer way to deal with this? */ setvbuf(sel->in, NULL, _IONBF, 0); if (bool_option("verbose")) cio_out("registered poll [%p] with slot %d\n", sel, i); return; }
static int join_hook(int argc, char *argv[]) { char *nick = grab_nick(argv[0]); /* @DISABLED@ window_t w = channel_get_window(argv[2]); if(current_username && strcasecmp(current_username, nick)) { channel_add_flags(argv[2], CHANNEL_JOIN); strncpy(channels[w], argv[2], 255); channels[w][255] = 0; } channel_set_server(argv[2], irc_pick_server()); user_channel(nick, argv[2]); cwio_out(channel_get_window(argv[2]), "%s %s is now in %s\n", timestamp(), nick, argv[2]); @DISABLED@ */ channel_t *ch = find_channel(argv[2], irc_pick_server()); if (!ch) return -1; user_t *u = find_user(nick, irc_pick_server()); assert(u); free(nick); u->add_channel(u, ch->name); if(bool_option("show_joins")) { cwio_out(ch->win, "%s %s is now in %s [%s]\n", timestamp(), u->name, ch->name, u->server); } if (bool_option("about_channels")) { /************************************** * check if we are using the right * channel name, if not, fix it * this really is kind of a hack **************************************/ if (strcmp(ch->name, argv[2])) { free(ch->name); ch->name = copy_string(argv[2]); } } return 0; }
/* * looks in all the approp directories */ char *bnirc_find_file(const char *name) { assert(name); char *buf = malloc(412); size_t i; FILE *f; if (bool_option("verbose")) cio_out("checking for %s\n", name); if ((f = fopen(name, "r")) != NULL) { fclose(f); return copy_string(name); } strncpy(buf, getenv("HOME"), 200); strcat(buf, "/.bnIRC/"); strncat(buf, name, 200); if (bool_option("verbose")) cio_out("checking for %s\n", buf); if ((f = fopen(buf, "r")) != NULL) { fclose(f); return buf; } for (i = 0; f == NULL && dirs[i] != NULL; i++) { strncpy(buf, dirs[i], 200); strncat(buf, name, 200); if (bool_option("verbose")) cio_out("checking for %s\n", buf); f = fopen(buf, "r"); if (f) { fclose(f); return buf; } } return NULL; }
static int part_hook(int argc, char *argv[]) { char *nick = grab_nick(argv[0]); user_t *u = find_user(nick, irc_pick_server()); channel_t *ch = find_channel(argv[2], irc_pick_server()); if (!ch) return -1; if(bool_option("show_parts")) { cwio_out(ch->win, "%s %s has left %s [%s]\n", timestamp(), u->name, ch->name, argv[3]); } u->rm_channel(u, ch->name); free(nick); return 0; }
char *grab_nick(const char *server_text) { size_t len = 0; while (server_text[len + 1] != '!' && server_text[len + 1] != 0 && server_text[len + 1] != ' ') { len++; } char *nick = malloc(len + 1); strncpy(nick, &server_text[1], len); nick[len] = 0; if (bool_option("verbose")) cio_out("parsed nick [%s] from [%s]\n", nick, server_text); return nick; }
/** * create the test suite for sanei config related tests */ static void sanei_config_suite (void) { /* tests */ inexistent_config (); empty_config (); null_config (); null_attach (); string_option (); int_option (); string_list_option (); word_array_option (); bool_option (); fixed_option (); wrong_range_int_option (); wrong_string_list_option (); wrong_bool_option (); wrong_fixed_option (); /* backend real conf inspired cases */ umax_pp (); snapscan (); }
int parse_server_string ( const char *str ) { assert(str); if(bool_option("show_all_server_strings")) cio_out(str); current_server_string = str; size_t i; char **argv; int argc; char *buf = NULL; server_string_t *si; server_string_list_t *sl; /* make a buffer */ buf = copy_string(str); assert(buf != NULL); buf[strlen(buf) - 1] = 0; if(strlen(buf) == 0) { return -1; } make_argv(&argc, &argv, buf); assert(argc != 0); // we want a consistent format regardless of whether or not a prefix // was sent, so if one wasn't we fake it if(argv[0][0] != ':') { // no prefix was found char **tmp = malloc(sizeof(char *) * (argc + 1)); tmp[0] = malloc(strlen(irc_pick_server()) + 2); tmp[0][0] = ':'; strcpy(&tmp[0][1], irc_pick_server()); for(i = 0; i < argc; i++) { tmp[i + 1] = copy_string(argv[i]); } free_argv(argc, argv); argc++; argv = tmp; } // run hooks rcv_hook_t *rcvp = &hook_head; for(list_next(rcvp); rcvp != &hook_head; list_next(rcvp)) { rcvp->func(argc, argv); } // find a function to run sl = (server_string_list_t *)(head.head.next); find_next_string_handler: for( ; (list_t *)sl != (list_t *)&head; list_next(sl)) { si = sl->strings; while(si->keystring != NULL) { if(strcmp_nc(argv[1], si->keystring) == 0) { goto found_string_handler; } si++; } } // nothing was found if(bool_option("verbose") || bool_option("show_unhandled_msgs")) { cio_out("unhandled string sent from server: %s\n", str); } free_argv(argc, argv); free(buf); return -1; found_string_handler: free_argv(argc, argv); if(buf[0] == ':') { make_max_argv(&argc, &argv, buf, si->argc); } else { make_max_argv(&argc, &argv, buf, si->argc - 1); char **tmp = malloc(sizeof(char *) * (argc + 1)); //tmp[0] = copy_string(irc_pick_server()); tmp[0] = malloc(strlen(irc_pick_server()) + 2); tmp[0][0] = ':'; strcpy(&tmp[0][1], irc_pick_server()); //add_char_to_str(tmp[0], 0, ':'); for(i = 0; i < argc; i++) { tmp[i + 1] = copy_string(argv[i]); } free_argv(argc, argv); argc++; argv = tmp; } if(si->strip_colon && strlen(argv[argc - 1]) != 0 && argv[argc - 1][0] == ':') { remove_char_from_str(argv[argc - 1], 0); } /********************************************** * make sure argc is correct, so that the * callbacks don't get any suprises **********************************************/ assert(!(argc > si->argc)); if(argc < si->argc) { char **tmp = argv; argv = malloc(sizeof(char *) * si->argc); for(i = 0; i < argc; i++) { argv[i] = tmp[i]; } for(i = argc; i < si->argc; i++) { argv[i] = malloc(1); argv[i][0] = 0; } argc = si->argc; } int retval = si->hook(argc, argv); if(retval) { list_next(sl); goto find_next_string_handler; } free_argv(argc, argv); current_server_string = NULL; return retval; }
void make_max_argv(int *argc, char ***argv, const char *str, size_t n) { const char *i; size_t size; int tmp; int add_extra; /* figure out argc */ *argc = word_count(str); if (*argc >= n) { *argc = n; } if (bool_option("verbose")) cio_out("argc = %d\n", *argc); /* initialize argv */ *argv = malloc(sizeof(char *) * (*argc + 1)); (*argv)[*argc] = NULL; /* populate argv */ i = str; tmp = 0; while (*i && tmp < n - 1) { add_extra = 0; if (isspace(*i)) { i++; continue; } if(*i == '"') { i++; size = strcspn(i, "\""); add_extra = 1; } else if (*i == '\'') { i++; size = strcspn(i, "'"); add_extra = 1; } else { size = strcspn(i, WSPACE); } (*argv)[tmp] = malloc(size + 1); strncpy((*argv)[tmp], i, size); (*argv)[tmp][size] = 0; if (bool_option("verbose")) cio_out("argv[%d] = \"%s\"\n", tmp, (*argv)[tmp]); i += size + add_extra; tmp++; } if (*argc != n) return; /* we are done here */ /* get the final entry to argv */ while (*i) { assert(tmp == *argc - 1); if (!isspace(*i)) break; i++; } (*argv)[*argc - 1] = malloc(strlen(i) + 1); strcpy((*argv)[*argc - 1], i); if (bool_option("verbose")) cio_out("argv[%d] = \"%s\"\n", *argc - 1, (*argv)[*argc - 1]); }