int handle_client_connection(t_client_info *client, t_client_info *list, char *cmd, t_channel **channels) { char *buff; buff = strdup(cmd); bzero(cmd, 4096); if (strncmp(buff, "PASS ", 5) == 0) return (0); else if (strncmp(buff, "NICK ", 5) == 0) return (handle_nick(client, buff + 5, list)); else if (strncmp(buff, "USER ", 5) == 0) return (0); else if (strncmp(buff, "JOIN ", 5) == 0) return (join_channel(client, buff + 5, channels)); else if (strncmp(buff, "PART ", 5) == 0) return (part_channel(client, channels)); else if (strncmp(buff, "LIST", 4) == 0) return (list_channels(*channels, cmd, client)); else if (strncmp(buff, "USERS", 5) == 0) return (list_users(client, *channels)); else if (strncmp(buff, "MSG", 3) == 0) return (private_message(client, list, buff)); else return (send_messages(client, *channels, buff)); return (0); }
void list(t_client *cli, t_packet *pack) { if (!pack->arg[0]) list_channels(cli->fd); else search_channels(cli->fd, pack->arg[0]); }
/* * The 'list <options>' first level command */ int cmd_list(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; const char *session_name; static poptContext pc; struct lttng_domain domain; struct lttng_domain *domains = NULL; memset(&domain, 0, sizeof(domain)); if (argc < 1) { usage(stderr); ret = CMD_ERROR; goto end; } pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: usage(stderr); ret = CMD_UNDEFINED; goto end; } } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = CMD_ERROR; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_list); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } /* Get session name (trailing argument) */ session_name = poptGetArg(pc); DBG2("Session name: %s", session_name); if (opt_kernel) { domain.type = LTTNG_DOMAIN_KERNEL; } else if (opt_userspace) { DBG2("Listing userspace global domain"); domain.type = LTTNG_DOMAIN_UST; } else if (opt_jul) { DBG2("Listing JUL domain"); domain.type = LTTNG_DOMAIN_JUL; } else if (opt_log4j) { domain.type = LTTNG_DOMAIN_LOG4J; } else if (opt_python) { domain.type = LTTNG_DOMAIN_PYTHON; } if (!opt_kernel && opt_syscall) { WARN("--syscall will only work with the Kernel domain (-k)"); ret = CMD_ERROR; goto end; } if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) { handle = lttng_create_handle(session_name, &domain); if (handle == NULL) { ret = CMD_FATAL; goto end; } } if (session_name == NULL) { if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j && !opt_python) { ret = list_sessions(NULL); if (ret) { goto end; } } if (opt_kernel) { if (opt_syscall) { ret = list_syscalls(); if (ret) { goto end; } } else { ret = list_kernel_events(); if (ret) { goto end; } } } if (opt_userspace) { if (opt_fields) { ret = list_ust_event_fields(); } else { ret = list_ust_events(); } if (ret) { goto end; } } if (opt_jul || opt_log4j || opt_python) { ret = list_agent_events(); if (ret) { goto end; } } } else { /* List session attributes */ if (lttng_opt_mi) { /* Open element sessions * Present for xml consistency */ ret = mi_lttng_sessions_open(writer); if (ret) { goto end; } } /* MI: the ouptut of list_sessions is an unclosed session element */ ret = list_sessions(session_name); if (ret) { goto end; } /* Domain listing */ if (opt_domain) { ret = list_domains(session_name); goto end; } /* Channel listing */ if (opt_kernel || opt_userspace) { if (lttng_opt_mi) { /* Add of domains and domain element for xml * consistency and validation */ ret = mi_lttng_domains_open(writer); if (ret) { goto end; } /* Open domain and leave it open for * nested channels printing */ ret = mi_lttng_domain(writer, &domain, 1); if (ret) { goto end; } } ret = list_tracker_pids(); if (ret) { goto end; } ret = list_channels(opt_channel); if (ret) { goto end; } if (lttng_opt_mi) { /* Close domain and domain element */ ret = mi_lttng_close_multi_element(writer, 2); } if (ret) { goto end; } } else { int i, nb_domain; /* We want all domain(s) */ nb_domain = lttng_list_domains(session_name, &domains); if (nb_domain < 0) { ret = CMD_ERROR; ERR("%s", lttng_strerror(nb_domain)); goto end; } if (lttng_opt_mi) { ret = mi_lttng_domains_open(writer); if (ret) { ret = CMD_ERROR; goto end; } } for (i = 0; i < nb_domain; i++) { switch (domains[i].type) { case LTTNG_DOMAIN_KERNEL: MSG("=== Domain: Kernel ===\n"); break; case LTTNG_DOMAIN_UST: MSG("=== Domain: UST global ===\n"); MSG("Buffer type: %s\n", domains[i].buf_type == LTTNG_BUFFER_PER_PID ? "per PID" : "per UID"); break; case LTTNG_DOMAIN_JUL: MSG("=== Domain: JUL (Java Util Logging) ===\n"); break; case LTTNG_DOMAIN_LOG4J: MSG("=== Domain: LOG4j (Logging for Java) ===\n"); break; case LTTNG_DOMAIN_PYTHON: MSG("=== Domain: Python (logging) ===\n"); break; default: MSG("=== Domain: Unimplemented ===\n"); break; } if (lttng_opt_mi) { ret = mi_lttng_domain(writer, &domains[i], 1); if (ret) { ret = CMD_ERROR; goto end; } } /* Clean handle before creating a new one */ if (handle) { lttng_destroy_handle(handle); } handle = lttng_create_handle(session_name, &domains[i]); if (handle == NULL) { ret = CMD_FATAL; goto end; } if (domains[i].type == LTTNG_DOMAIN_JUL || domains[i].type == LTTNG_DOMAIN_LOG4J || domains[i].type == LTTNG_DOMAIN_PYTHON) { ret = list_session_agent_events(); if (ret) { goto end; } continue; } switch (domains[i].type) { case LTTNG_DOMAIN_KERNEL: case LTTNG_DOMAIN_UST: ret = list_tracker_pids(); if (ret) { goto end; } break; default: break; } ret = list_channels(opt_channel); if (ret) { goto end; } if (lttng_opt_mi) { /* Close domain element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } } } if (lttng_opt_mi) { /* Close the domains, session and sessions element */ ret = mi_lttng_close_multi_element(writer, 3); if (ret) { ret = CMD_ERROR; goto end; } } } } /* Mi closing */ if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; } free(domains); if (handle) { lttng_destroy_handle(handle); } poptFreeContext(pc); return ret; }
/* * The 'list <options>' first level command */ int cmd_list(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; const char *session_name; static poptContext pc; struct lttng_domain domain; struct lttng_domain *domains = NULL; memset(&domain, 0, sizeof(domain)); if (argc < 1) { usage(stderr); ret = CMD_ERROR; goto end; } pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: usage(stderr); ret = CMD_UNDEFINED; goto end; } } /* Get session name (trailing argument) */ session_name = poptGetArg(pc); DBG2("Session name: %s", session_name); if (opt_kernel) { domain.type = LTTNG_DOMAIN_KERNEL; } else if (opt_userspace) { DBG2("Listing userspace global domain"); domain.type = LTTNG_DOMAIN_UST; } else if (opt_jul) { DBG2("Listing JUL domain"); domain.type = LTTNG_DOMAIN_JUL; } if (opt_kernel || opt_userspace || opt_jul) { handle = lttng_create_handle(session_name, &domain); if (handle == NULL) { ret = CMD_FATAL; goto end; } } if (session_name == NULL) { if (!opt_kernel && !opt_userspace && !opt_jul) { ret = list_sessions(NULL); if (ret != 0) { goto end; } } if (opt_kernel) { ret = list_kernel_events(); if (ret < 0) { ret = CMD_ERROR; goto end; } } if (opt_userspace) { if (opt_fields) { ret = list_ust_event_fields(); } else { ret = list_ust_events(); } if (ret < 0) { ret = CMD_ERROR; goto end; } } if (opt_jul) { ret = list_jul_events(); if (ret < 0) { ret = CMD_ERROR; goto end; } } } else { /* List session attributes */ ret = list_sessions(session_name); if (ret != 0) { goto end; } /* Domain listing */ if (opt_domain) { ret = list_domains(session_name); goto end; } if (opt_kernel || opt_userspace) { /* Channel listing */ ret = list_channels(opt_channel); if (ret < 0) { goto end; } } else { int i, nb_domain; /* We want all domain(s) */ nb_domain = lttng_list_domains(session_name, &domains); if (nb_domain < 0) { ret = nb_domain; ERR("%s", lttng_strerror(ret)); goto end; } for (i = 0; i < nb_domain; i++) { switch (domains[i].type) { case LTTNG_DOMAIN_KERNEL: MSG("=== Domain: Kernel ===\n"); break; case LTTNG_DOMAIN_UST: MSG("=== Domain: UST global ===\n"); MSG("Buffer type: %s\n", domains[i].buf_type == LTTNG_BUFFER_PER_PID ? "per PID" : "per UID"); break; case LTTNG_DOMAIN_JUL: MSG("=== Domain: JUL (Java Util Logging) ===\n"); break; default: MSG("=== Domain: Unimplemented ===\n"); break; } /* Clean handle before creating a new one */ if (handle) { lttng_destroy_handle(handle); } handle = lttng_create_handle(session_name, &domains[i]); if (handle == NULL) { ret = CMD_FATAL; goto end; } if (domains[i].type == LTTNG_DOMAIN_JUL) { ret = list_session_jul_events(); if (ret < 0) { goto end; } continue; } ret = list_channels(opt_channel); if (ret < 0) { goto end; } } } } end: free(domains); if (handle) { lttng_destroy_handle(handle); } poptFreeContext(pc); return ret; }
int main(int argc, const char *argv[]) { try { CmdArgParser parser(argc, argv); parser.setHeader("Archive Export version " ARCH_VERSION_TXT ", " EPICS_VERSION_STRING ", built " __DATE__ ", " __TIME__ "\n\n"); parser.setArgumentsInfo("<index file> {channel}"); CmdArgFlag be_verbose (parser, "verbose", "Verbose mode"); CmdArgString pattern (parser, "match", "<reg. exp.>", "Channel name pattern"); CmdArgFlag do_list (parser, "list", "List all channels"); CmdArgFlag do_info (parser, "info", "Time-range info on channels"); CmdArgString start_time (parser, "start", "<time>", "Format: \"mm/dd/yyyy[ hh:mm:ss[.nano-secs]]\""); CmdArgString end_time (parser, "end", "<time>", "(exclusive)"); CmdArgFlag status_text(parser, "text", "Include text column for status/severity (default)"); CmdArgFlag no_status_text(parser, "no_text", "Exclude text column for status/severity"); CmdArgString output (parser, "output", "<file>", "Output to file"); CmdArgDouble plotbin (parser, "plotbin", "<seconds>", "Bin the raw data for plotting"); CmdArgDouble average (parser, "average", "<seconds>", "average values"); CmdArgDouble linear (parser, "linear", "<seconds>", "Interpolate values linearly"); CmdArgString format_txt (parser, "format", "<decimal|engineering|exponential>", "Use specific format for numbers"); CmdArgInt prec (parser, "precision", "<int>", "Precision of numbers"); CmdArgFlag GNUPlot (parser, "gnuplot", "Generate GNUPlot command file"); CmdArgFlag image (parser, "Gnuplot", "Generate GNUPlot output for Image"); CmdArgFlag raw_time (parser, "raw_time", "Include columns for EPICS time stamp"); CmdArgFlag millisecs (parser, "millisecs", "Truncate time to millisecs in spreadsheet dump."); // defaults prec.set(-1); if (! parser.parse()) return -1; if (parser.getArguments().size() < 1) { parser.usage(); return -1; } precision = prec; if (!strncmp(format_txt.get().c_str(), "d", 1)) format = RawValue::DECIMAL; else if (!strncmp(format_txt.get().c_str(), "en", 2)) format = RawValue::ENGINEERING; else if (!strncmp(format_txt.get().c_str(), "ex", 2)) format = RawValue::EXPONENTIAL; else if (format_txt.get().length() > 0) { fprintf(stderr, "Unknown format string '%s'\n", format_txt.get().c_str()); return -1; } verbose = be_verbose; only_millisecs = millisecs; // Start/end time AutoPtr<epicsTime> start, end; stdString txt; if (start_time.get().length() > 0) { start = new epicsTime; if (!string2epicsTime(start_time.get(), *start)) { fprintf(stderr, "Parse error for start time '%s'\n", start_time.get().c_str()); start = 0; parser.usage(); return -1; } if (verbose) printf("Using start time %s\n", epicsTimeTxt(*start, txt)); } if (end_time.get().length() > 0) { end = new epicsTime(); if (!string2epicsTime(end_time.get(), *end)) { fprintf(stderr, "Parse error for end time '%s'\n", end_time.get().c_str()); end = 0; parser.usage(); return -1; } if (verbose) printf("Using end time %s\n", epicsTimeTxt(*end, txt)); } if (start && end && *start > *end) { // Could simply swap start and end, but assume the user is // confused and should rethink the request. fprintf(stderr, "start time is greater than end time.\n"); return -1; } // Index name stdString index_name = parser.getArgument(0); // Channel names stdVector<stdString> names; if (parser.getArguments().size() > 1) { if (! pattern.get().empty()) { fputs("Pattern from '-m' switch is ignored\n" "since a list of channels was also provided.\n", stderr); } // first argument was directory file name, skip that: for (size_t i=1; i<parser.getArguments().size(); ++i) names.push_back(parser.getArgument(i)); } if ((GNUPlot || image) && output.get().length() == 0) { fprintf(stderr, "The -gnuplot/Gnuplot options require " "an -output file\n"); return -1; } // How? ReaderFactory::How how = ReaderFactory::Raw; double delta = 0.0; if (double(plotbin) > 0.0) { how = ReaderFactory::Plotbin; delta = double(plotbin); } else if (double(average) > 0.0) { how = ReaderFactory::Average; delta = double(average); } else if (double(linear) > 0.0) { how = ReaderFactory::Linear; delta = double(linear); } // Open index AutoIndex index; index.open(index_name.c_str()); if (verbose) printf("Opened index '%s'\n", index_name.c_str()); if (do_info && names.size()<=0 && pattern.get().length()<=0) do_list.set(); // otherwise it'd be a NOP if (names.size() <= 0 && (do_list || pattern.get().length() > 0)) get_names_for_pattern(index, names, pattern); if (do_info) list_channels(index, names, true); else if (do_list) list_channels(index, names, false); else if (names.size() > 0) { if (GNUPlot || image) dump_gnuplot(index, names, start, end, how, delta, output, image); else dump_spreadsheet(index, names, start, end, raw_time, !no_status_text, how, delta, output); } index.close(); } catch (GenericException &e) { fprintf(stderr, "Error:\n%s\n", e.what()); return -1; } return 0; }
int main(int argc, char *argv[]) { const char *ifname, *cmd; unsigned char bnounit = 0; char *if_base = NULL; unsigned int unit_res = -1; int res = 0; if (argc < 2 || strncmp(argv[1],"-h",2) == 0 || strncmp(argv[1],"--h",3) == 0) usage(); ifname = argv[1]; if (argc == 2) { ieee80211_status(ifname); return 0; } cmd = argv[2]; if (streq(cmd, "create")) { struct ieee80211_clone_params cp; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); memset(&cp, 0, sizeof(cp)); strncpy(cp.icp_name, ifname, IFNAMSIZ); /* NB: station mode is the default */ cp.icp_opmode = IEEE80211_M_STA; /* NB: default is to request a unique bssid/mac */ cp.icp_flags = IEEE80211_CLONE_BSSID; while (argc > 3) { if (strcmp(argv[3], "wlanmode") == 0) { if (argc < 5) usage(); cp.icp_opmode = (u_int16_t) getopmode(argv[4]); argc--; argv++; } else if (strcmp(argv[3], "wlandev") == 0) { if (argc < 5) usage(); strncpy(ifr.ifr_name, argv[4], IFNAMSIZ); argc--; argv++; } else if (strcmp(argv[3], "nounit" ) == 0) { bnounit = 1; } else { int flag = getflag(argv[3]); if (flag < 0) cp.icp_flags &= ~(-flag); else cp.icp_flags |= flag; } argc--; argv++; } if (ifr.ifr_name[0] == '\0') errx(1, "no device specified with wlandev"); res = if_split_name(cp.icp_name, &if_base, &unit_res); if (res < 0) { err(1, "if_split_name() - malloc"); } else if ((res == 0) && (bnounit == 0)) { /* user gave a string only and using a unit */ unit_res = if_find_unit(if_base); if (unit_res < 0) { err(1, "if_find_unit - failed"); } else { snprintf(cp.icp_name + strlen(if_base), IFNAMSIZ - strlen(if_base), "%d", unit_res); } } free(if_base); if_base = NULL; ifr.ifr_data = (void *) &cp; vap_create(&ifr); printf("%s\n", ifr.ifr_name); } else if (streq(cmd, "destroy")) { vap_destroy(ifname); } else if (streq(cmd, "list")) { if (argc > 3) { const char *arg = argv[3]; if (streq(arg, "sta")) list_stations(ifname); else if (streq(arg, "scan") || streq(arg, "ap")) list_scan(ifname); else if (streq(arg, "chan") || streq(arg, "freq")) list_channels(ifname, 1); else if (streq(arg, "active")) list_channels(ifname, 0); else if (streq(arg, "keys")) list_keys(ifname); else if (streq(arg, "caps")) list_capabilities(ifname); else if (streq(arg, "wme")) list_wme(ifname); else err(1, "unknown 'list' option: %s", arg); } else /* NB: for compatibility */ list_stations(ifname); } else usage(); return 0; }