int do_init(int argc, char **argv) { int i; char *CONF_FILE = "conf/login.conf"; char *LANG_FILE = "conf/lang.conf"; char *INTER_FILE = "conf/inter.conf"; srand(gettick()); set_logfile("log/login.log"); set_dmpfile("log/login_dump.log"); for (i = 1; i < argc ; i++) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--h") == 0 || strcmp(argv[i], "--?") == 0 || strcmp(argv[i], "/?") == 0) help_screen(); else if (strcmp(argv[i], "--conf") == 0) CONF_FILE=argv[i+1]; else if (strcmp(argv[i],"--inter") == 0) INTER_FILE = argv[i+1]; else if (strcmp(argv[i],"--lang") == 0) LANG_FILE = argv[i+1]; } config_read(CONF_FILE); config_read(INTER_FILE); config_read("conf/char.conf"); sql_handle = Sql_Malloc(); if(sql_handle==NULL) { Sql_ShowDebug(sql_handle); exit(EXIT_FAILURE); } if( SQL_ERROR == Sql_Connect(sql_handle, sql_id, sql_pw, sql_ip, (uint16)sql_port, sql_db) ) { printf("id: %s pass: %s Port: %d\n",sql_id, sql_pw,sql_port); Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } //sql_init(); lang_read(LANG_FILE); set_termfunc(do_term); //zlib_init(); add_log(""); add_log("mYnexia Login Server Started.\n"); set_defaultaccept(clif_accept); set_defaultparse(clif_parse); login_fd = make_listen_port(login_port); timer_insert(10 * 60 * 1000, 10 * 60 * 1000, Remove_Throttle, 0, 0); //Lockout DB bf_lockout=uidb_alloc(DB_OPT_BASE); printf("mYnexia Login Server is \033[1;32mready\033[0m! Listening at %d.\n", login_port); add_log("Server Ready! Listening at %d.\n", login_port); return 0; }
int config_read(const char *cfg_file) { char line[1024], r1[1024], r2[1024]; int line_num = 0; FILE *fp; fp = fopen(cfg_file, "r"); if (fp == NULL) { printf("CFG_ERR: Configuration file (%s) not found.\n", cfg_file); return 1; } while(fgets(line, sizeof(line), fp)) { line_num++; if (line[0] == '/' && line[1] == '/') continue; if (sscanf(line, "%[^:]: %[^\r\n]", r1, r2) == 2) { if(strcmpi(r1, "login_port") == 0) { login_port = atoi(r2); } else if(strcmpi(r1, "login_id") == 0) { strncpy(login_id, r2, 32); login_id[31] = '\0'; } else if(strcmpi(r1, "login_pw") == 0) { strncpy(login_pw, r2, 32); login_pw[31] = '\0'; } else if(strcmpi(r1, "login_log") == 0) { set_logfile(r2); } else if(strcmpi(r1, "dump_log") == 0) { set_dmpfile(r2); } else if(strcmpi(r1, "dump_save") == 0) { dump_save = atoi(r2); } else if(strcmpi(r1, "meta") == 0) { add_meta(r2); } else if(strcmpi(r1,"version")==0) { nex_version=atoi(r2); } else if(strcmpi(r1,"deep")==0) { nex_deep=atoi(r2); } else if(strcmpi(r1,"sql_ip")==0) { strcpy(sql_ip,r2); } else if(strcmpi(r1, "sql_port") == 0) { sql_port=atoi(r2); } else if(strcmpi(r1, "sql_id") == 0) { strcpy(sql_id,r2); } else if(strcmpi(r1, "sql_pw") == 0) { strcpy(sql_pw,r2); } else if(strcmpi(r1, "sql_db") == 0) { strcpy(sql_db,r2); } else if(strcmpi(r1, "require_reg") == 0) { require_reg=atoi(r2); } } } fclose(fp); printf("Configuration File (%s) reading finished!\n", cfg_file); return 0; }
/* * Amiga-specific main entry */ int main (int argc, char *argv[]) { fromWB = argc == 0; if (fromWB) set_logfile ("T:E-UAE.log"); init_libs (); #ifdef USE_SDL init_sdl (); #endif real_main (argc, argv); if (fromWB) set_logfile (0); return 0; }
int userlog(int debuglev, const char *file, const char *function, int line, char *fmt, ...) { va_list args; FILE *fp; int i = 0; char tmp[1024]; char alTime[25]; char fname[512]; if (!debuglev) return 0; memset(tmp, 0x00, sizeof(tmp)); memset(fname, 0x00, sizeof(fname)); memset(alTime, 0x00, sizeof(alTime)); GetTime(alTime); //sprintf( fname, "%s\\%s", path, debugfile ); if ((fp = fopen(debugfile, "a+")) == NULL) { //msgbox( "ERROR", MB_OK, " fopen(%s) failed. %s", debugfile, strerror(errno) ); #ifdef WIN32 GetModuleFileName(NULL, fname, sizeof(fname)-1); #else memcpy( fname, "json.log", sizeof(fname)-1 ); #endif set_logfile(fname); if ((fp = fopen(debugfile, "a+")) == NULL) { #ifdef WIN32 msgbox("ERROR", MB_OK, " fopen(%s) failed. %s", debugfile, strerror(errno)); #endif return -1; } } va_start(args, fmt); #ifdef WIN32 fprintf(fp, "[%s][%-10s-L%04d-%-15s-%05d] ", alTime + 2, file, line, function, _getpid()); #else fprintf(fp, "[%s][%-10s-L%04d-%-15s-%05d] ", alTime + 2, file, line, function, getpid()); #endif //vfprintf( fp, "%s->.%d: %s.\n", args ); vfprintf(fp, fmt, args); fprintf(fp, "%s", NEWLINE); va_end(args); fclose(fp); return 0; }
/** * parses command line arguments and assigns values to run time * variables. relies on GNU getopts included with this distribution. */ void parse_cmdline(CONF C, int argc, char *argv[]) { int c = 0; BOOLEAN display = FALSE; while ((c = getopt_long(argc, argv, "Vhvf:CDd:l:p:", long_options, (int *)0)) != EOF) { switch (c) { case 'V': display_version(TRUE); break; case 'h': display_help(EXIT_SUCCESS); case 'v': set_verbose(C, TRUE); break; case 'C': display = TRUE; break; //case 'f': //XXX: parsed separately // set_cfgfile(C, optarg); // break; case 'D': set_debug(C, TRUE); break; case 'd': if (!optarg) { puts("NO OPTARG"); } if (optarg != NULL && !strncasecmp(optarg, "false", 5)) { set_daemon(C, FALSE); } else { set_daemon(C, TRUE); } break; case 'l': set_logfile(C, optarg); break; case 'p': set_pidfile(C, optarg); break; } /* end of switch */ } /* end of while */ if (display) { show(C, TRUE); } return; } /* end of parse_cmdline */
int main(int argc, char **argv) { char mac_addr[ETH_ALEN]; char elan_name[32 + 1]; char preferred_les[ATM_ESA_LEN]; /* LANE2 */ char foreId[255]; /* Max size for a TLV */ char atm2textbuff[100]; char esibuff[20]; int esi_set = 0; int listen_addr_set = 0; int atm_set=0; int proxy_flag = 0; int lane_version = 0; /* LANE2 */ int max_frame_size = MTU_UNSPEC; int lecs_method = LECS_WELLKNOWN; int poll_ret = 0, itf = 0, phys_itf = 0, selector = 0; int daemon_flag = 0; pid_t pid; struct sockaddr_atmsvc manual_atm_addr; struct sockaddr_atmsvc listen_addr; char pidbuf[PATH_MAX + 1]; int fd; int retval; memset(elan_name, '\0', sizeof(elan_name)); memset(foreId, '\0', sizeof(foreId)); memset(preferred_les, 0, ATM_ESA_LEN); memset(&manual_atm_addr, 0, sizeof(struct sockaddr_atmsvc)); memset(&listen_addr, 0, sizeof(struct sockaddr_atmsvc)); listen_addr.sas_family = AF_ATMSVC; set_application("zeppelin"); /* for debug msgs */ while(poll_ret != -1) { poll_ret = getopt(argc, argv, "bc:e:n:s:m:l:i:I:q:12pf:t:F:"); switch(poll_ret) { case 'b': daemon_flag = 1; break; case 'c': if (atm_set) { usage(argv[0]); exit(-1); } if (text2atm(optarg, (struct sockaddr *)&manual_atm_addr, sizeof(struct sockaddr_atmsvc), T2A_NAME) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid LECS address"); usage(argv[0]); exit(-1); } atm2text(atm2textbuff, sizeof(atm2textbuff), (struct sockaddr *)&manual_atm_addr, 0); diag(COMPONENT, DIAG_INFO, "LECS address: %s", atm2textbuff); lecs_method = LECS_MANUAL; atm_set=1; break; case 'e': if(esi_convert(optarg, mac_addr)<0) { diag(COMPONENT, DIAG_ERROR, "Invalid ESI format"); usage(argv[0]); exit(-1); } mac2text(esibuff, mac_addr); diag(COMPONENT, DIAG_DEBUG, "LEC ESI:%s", esibuff); esi_set=1; break; case 'n': if (strlen(optarg) > 32) { diag(COMPONENT, DIAG_ERROR, "ELAN name too long"); exit(-1); } strcpy(elan_name, optarg); diag(COMPONENT, DIAG_INFO, "Vlan name :'%s'", elan_name); break; case 's': if (atm_set) { usage(argv[0]); exit(-1); } if (text2atm(optarg, (struct sockaddr *)&manual_atm_addr, sizeof(struct sockaddr_atmsvc), T2A_NAME) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid LES address"); usage(argv[0]); exit(-1); } atm2text(atm2textbuff, sizeof(atm2textbuff), (struct sockaddr *)&manual_atm_addr, 0); diag(COMPONENT, DIAG_INFO, "LES address: %s", atm2textbuff); lecs_method = LECS_NONE; atm_set=1; break; case 'm': set_verbosity(NULL, DIAG_DEBUG); break; case 'l': if (isdigit(optarg[0]) && strlen(optarg) < 4 && sscanf(optarg, "%d", &selector) && selector >=0 && selector <= 0xff) { listen_addr.sas_addr.prv[ATM_ESA_LEN - 1] = (char) selector; diag(COMPONENT, DIAG_INFO, "Selector byte set " "to %d", selector); } else { if (text2atm(optarg, (struct sockaddr *)&listen_addr, sizeof(struct sockaddr_atmsvc), T2A_NAME) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid ATM listen address"); usage(argv[0]); exit(-1); } listen_addr_set = 1; } break; case 'i': if (sscanf(optarg, "%d", &itf) <= 0 || itf >= MAX_LEC_ITF) { diag(COMPONENT, DIAG_ERROR, "Invalid interface number"); usage(argv[0]); exit(-1); } diag(COMPONENT, DIAG_INFO, "Interface number set to %d", itf); break; case 'I': if (sscanf(optarg, "%d", &phys_itf) <= 0 || phys_itf < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid physical interface number"); usage(argv[0]); exit(-1); } diag(COMPONENT, DIAG_INFO, "Physical interface number set to %d", phys_itf); break; case 'q': #if 0 if (text2qos(optarg,NULL,0) < 0) { diag(COMPONENT, DIAG_ERROR, "Invalid QOS specification"); usage(argv[0]); exit(-1); } qos_spec = optarg; #endif diag(COMPONENT, DIAG_INFO, "-q is deprecated, ignoring it"); break; case '1': lane_version = 1; break; case '2': lane_version = 2; break; case 'p': proxy_flag = 1; break; case 'f': if (strlen(optarg) > 255) { diag(COMPONENT, DIAG_ERROR, "foreId too long"); exit(-1); } memcpy (foreId, optarg, strlen(optarg)); foreId[strlen(optarg)] = '\0'; diag(COMPONENT, DIAG_INFO, "foreId :'%s'", foreId); break; case 't': /* ERIC */ if( !strncmp( optarg, "1516", 4 )) max_frame_size = MTU_1516; else if( !strncmp( optarg, "1580", 4 )) max_frame_size = MTU_1580; else if( !strncmp( optarg, "4544", 4 )) max_frame_size = MTU_4544; else if( !strncmp( optarg, "9234", 4 )) max_frame_size = MTU_9234; else if( !strncmp( optarg, "18190", 5 )) max_frame_size = MTU_18190; break; case 'F': set_logfile(optarg); diag(COMPONENT, DIAG_DEBUG, "logfile set to %s", optarg); break; case -1: break; default: usage(argv[0]); exit(-1); } } if (argc != optind) { usage(argv[0]); exit(1); } if (lane_version == 1 && max_frame_size == MTU_1580) { diag(COMPONENT, DIAG_ERROR, "MTU 1580 not defined with LANEv1"); exit(-1); } /* Reserve signals */ signal(SIGHUP, sig_reset); signal(SIGPIPE, SIG_IGN); if (!esi_set) { if(addr_getesi(mac_addr, phys_itf) < 0) { diag(COMPONENT, DIAG_ERROR, "Can't get ESI from kernel!"); return -1; } mac2text(esibuff, mac_addr); diag(COMPONENT, DIAG_DEBUG, "LEC ESI:%s", esibuff); if (itf != 0) mac_addr[0] = 0x2 | ((itf - 1) << 2); } if ((itf = kernel_init(mac_addr, itf)) < 0 ) { diag(COMPONENT, DIAG_FATAL, "Kernel interface creation failed, exiting..."); return -1; } if (daemon_flag == 1) { daemon_flag = 0; pid = fork(); if (pid < 0) { diag(COMPONENT, DIAG_FATAL, "fork failed, exiting..."); return -1; } if (pid) { /* parent */ return 0; } else { /* child */ if (setsid() < 0) { diag(COMPONENT, DIAG_FATAL, "setsid failed, exiting..."); return -1; } } } sprintf(pidbuf, "/var/run/lec%d.pid", itf); fd = open(pidbuf, O_CREAT | O_WRONLY, 0600); if (fd < 0) { diag(COMPONENT, DIAG_FATAL, "open(%s, ..) failed, %s", pidbuf, strerror(errno)); return -1; } sprintf(pidbuf, "%d\n", getpid()); write(fd, pidbuf, strlen(pidbuf)); close(fd); /* Loop here until the Sun gets cold */ while (1) { if (!listen_addr_set) { char sel = listen_addr.sas_addr.prv[ATM_ESA_LEN - 1]; if (get_listenaddr(listen_addr.sas_addr.prv, phys_itf) < 0) { diag(COMPONENT, DIAG_FATAL, "Could not figure out my ATM address"); exit(-1); } listen_addr.sas_addr.prv[ATM_ESA_LEN - 1] = sel; } atm2text(atm2textbuff, sizeof(atm2textbuff), (struct sockaddr *)&listen_addr, A2T_NAME | A2T_PRETTY | A2T_LOCAL); diag(COMPONENT, DIAG_INFO, "Our ATM address: %s", atm2textbuff); diag(COMPONENT, DIAG_DEBUG, "initializing lec parameters"); init_lec_params(mac_addr, elan_name, listen_addr.sas_addr.prv, itf, foreId, max_frame_size, proxy_flag, lane_version); if (lecs_method != LECS_MANUAL && lecs_method != LECS_NONE) { diag(COMPONENT, DIAG_DEBUG, "trying to get LECS address from ILMI"); /* Not sure why this memset is necessary */ memset(&manual_atm_addr, 0, sizeof(struct sockaddr_atmsvc)); retval = get_lecsaddr(phys_itf, &manual_atm_addr); if (retval <= 0) { diag(COMPONENT, DIAG_DEBUG, "get_lecsaddr failed; not enough " "memory allocated for all addresses " "or no LECS address registered"); } else { diag(COMPONENT, DIAG_DEBUG, "obtained LECS address from ILMI"); lecs_method = LECS_FROM_ILMI; } } diag(COMPONENT, DIAG_DEBUG, "About to connect LECS"); if (lec_configure(lecs_method, &manual_atm_addr, &listen_addr) < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to connect LES"); if (les_connect(lecs_method, &manual_atm_addr, &listen_addr) < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to connect BUS"); if (bus_connect() < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to create data direct listen socket"); if (create_data_listen() < 0) { close_connections(); random_delay(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to tell kernel our LEC_ID %d", lec_params.c14_lec_id); if (set_lec_id(lec_params.c14_lec_id) < 0) { close_connections(); continue; } diag(COMPONENT, DIAG_DEBUG, "About to tell kernel LEC parameters"); if (config_kernel() < 0) { close_connections(); continue; } diag(COMPONENT, DIAG_DEBUG, "Joined ELAN '%s' successfully", lec_params.c5_elan_name); main_loop(); diag(COMPONENT, DIAG_INFO, "Resetting..."); close_connections(); random_delay(); reset = 0; } return 0; /* not reached */ }
/** * @brief * main - the entry point in pbsTclInit.c * * @param[in] argc - argument count. * @param[in] argv - argument variables. * * @return int * @retval 0 : success */ int main(int argc, char *argv[]) { char tcl_libpath[MAXPATHLEN+13]; /* 13 for "TCL_LIBRARY=" + \0 */ int rc; /*the real deal or just pbs_version and exit?*/ execution_mode(argc, argv); if(set_msgdaemonname("pbs_tclsh")) { fprintf(stderr, "Out of memory\n"); return 1; } set_logfile(stderr); #ifdef WIN32 winsock_init(); Tcl_FindExecutable(argv[0]); #endif /* load the pbs conf file */ if (pbs_loadconf(0) == 0) { fprintf(stderr, "%s: Configuration error\n", argv[0]); return (1); } if (!getenv("TCL_LIBRARY")) { if (pbs_conf.pbs_exec_path) { sprintf((char *)tcl_libpath, #ifdef WIN32 "TCL_LIBRARY=%s/lib/tcl%s", #else "TCL_LIBRARY=%s/tcltk/lib/tcl%s", #endif pbs_conf.pbs_exec_path, TCL_VERSION); putenv(tcl_libpath); } } if (pbs_conf.pbs_use_tcp == 1) { char *nodename; struct tpp_config tpp_conf; char my_hostname[PBS_MAXHOSTNAME+1]; fd_set selset; struct timeval tv; if (pbs_conf.pbs_leaf_name) nodename = pbs_conf.pbs_leaf_name; else { if (gethostname(my_hostname, (sizeof(my_hostname) - 1)) < 0) { fprintf(stderr, "Failed to get hostname\n"); return -1; } nodename = my_hostname; } /* We don't want to show logs related to connecting pbs_comm on console * this set this flag to ignore it */ log_mask = SHOW_NONE; /* set tpp function pointers */ set_tpp_funcs(log_tppmsg); /* call tpp_init */ rc = 0; #ifndef WIN32 if (pbs_conf.auth_method == AUTH_MUNGE) rc = set_tpp_config(&pbs_conf, &tpp_conf, nodename, -1, pbs_conf.pbs_leaf_routers, pbs_conf.pbs_use_compression, TPP_AUTH_EXTERNAL, get_ext_auth_data, validate_ext_auth_data); else #endif rc = set_tpp_config(&pbs_conf, &tpp_conf, nodename, -1, pbs_conf.pbs_leaf_routers, pbs_conf.pbs_use_compression, TPP_AUTH_RESV_PORT, NULL, NULL); if (rc == -1) { fprintf(stderr, "Error setting TPP config\n"); return -1; } if ((rpp_fd = tpp_init(&tpp_conf)) == -1) { fprintf(stderr, "rpp_init failed\n"); return -1; } /* * Wait for net to get restored, ie, app to connect to routers */ FD_ZERO(&selset); FD_SET(rpp_fd, &selset); tv.tv_sec = 5; tv.tv_usec = 0; select(FD_SETSIZE, &selset, (fd_set *) 0, (fd_set *) 0, &tv); rpp_poll(); /* to clear off the read notification */ /* Once the connection is established we can unset log_mask */ log_mask &= ~SHOW_NONE; } else { /* set rpp function pointers */ set_rpp_funcs(log_rppfail); } Tcl_Main(argc, argv, pbsTcl_Init); return 0; }
int main(int argc,char **argv) #endif { int c,background; background = 0; while ((c = getopt(argc,argv,"i:a:t:o:eb:l:nV")) != EOF) switch (c) { case 'i': strcpy(local_interface, optarg); break; case 'a': strcpy(local_addr, optarg); break; case 't': strcpy(local_netmask, optarg); break; case 'o': strcpy(local_ip, optarg); break; #if 0 case 'r': strcpy(remote_ip, optarg); break; #endif case 'e': vcc_encap=1; break; case 'b': background = 1; break; case 'l': set_logfile(optarg); break; case 'n': /* @@@ was planned for NSAP matching */ pretty = A2T_PRETTY; break; case 'V': printf("%s\n",VERSION); return 0; default: usage(argv[0]); } if (argc > optind || argc < 2) usage(argv[0]); if (!init_done) rt2684_init(); if (!setup_done) rt2684_setup(); if (background) { pid_t pid; pid = fork(); if (pid < 0) diag(COMPONENT,DIAG_FATAL,"fork: %s",strerror(errno)); if (pid) { diag(COMPONENT,DIAG_DEBUG,"Backgrounding (PID %d)",pid); exit(0); } } while (1) sleep(30); /* to keep the sockets... */ return 0; }
int main(int argc, char **argv) { extern char *optarg; char *str = NULL; int ch; extern char *malloc_options; int i, loop, stack_test, queue_test, dll_test, sll_test, err_test; int strcat_test, array_test, alist_test, ht_test, idle; warnlvl wrn = WARN_NOTIFY; /* * Set malloc options to init memory to zero and always have realloc * actually reallocate memory. Also, all warnings become fatal. * Alloc of size 0 will always return NULL. Always dump core on * errors in malloc family functions. */ malloc_options = "ZAVX"; /* Default options */ stack_test = dll_test = err_test = strcat_test = queue_test = 0; array_test = sll_test = alist_test = ht_test = 0; loop = DEFLOOPCOUNT; idle = 1; /* Set idle, unless a test should be run */ if (argc <= 1) { usage(); return 1; } while ((ch = getopt(argc, argv, "aA:c:d:e:h:l:n:q:r:s:S:v")) != -1) switch ((char)ch) { case 'a': dll_test = stack_test = queue_test = DEFNUM; array_test = sll_test = alist_test = DEFNUM; ht_test = DEFNUM; idle = 0; break; case 'A': alist_test = atoi(optarg); idle = 0; break; case 'c': strcat_test = 1; str = optarg; idle = 0; break; case 'd': dll_test = atoi(optarg); idle = 0; break; case 'e': if (atoi(optarg) >= 0 && atoi(optarg) < NUM_WARNLVLS) wrn = atoi(optarg); else { fprintf(stderr, "Please specifify a " "number between 0 and 4.\n"); exit(1); } idle = 0; err_test = 1; break; case 'h': ht_test = atoi(optarg); idle = 0; break; case 'l': set_logfile(fopen(optarg, "a")); break; case 'n': loop = atoi(optarg); break; case 'q': queue_test = atoi(optarg); idle = 0; break; case 'r': array_test = atoi(optarg); idle = 0; break; case 's': stack_test = atoi(optarg); idle = 0; break; case 'S': sll_test = atoi(optarg); idle = 0; break; case 'v': printf("Using the following Gune version...\n"); printf("Preprocessor value: \t%s\n", PP_STR(GUNE_VERSION)); printf("Human-readable notation:\t%s\n", GUNE_VERSION_STRING); return 0; default: usage(); return 1; } /* Perform `n' tests of each kind */ if (idle == 0) for (i = 0; i < loop; ++i) { printf("========= RUNNING TEST %d =========\n", i + 1); if (alist_test > 0) { printf("\n----> ALIST <----\n"); stress_test_alist(alist_test); } if (ht_test > 0) { printf("\n----> HASH TABLE <----\n"); stress_test_ht(ht_test); } if (dll_test > 0) { printf("\n----> DLL <----\n"); stress_test_dll(dll_test); } if (stack_test > 0) { printf("\n----> STACK <----\n"); stress_test_stack(stack_test); } if (err_test > 0) { printf("\n----> ERR <----\n"); err_tester(wrn); } if (queue_test > 0) { printf("\n----> QUEUE <----\n"); stress_test_queue(queue_test); } if (array_test > 0) { printf("\n----> ARRAY <----\n"); stress_test_array(array_test); } if (strcat_test > 0) { printf("\n----> STR_CAT <----\n"); strcat_tester(str); } if (sll_test > 0) { printf("\n----> SLL <----\n"); stress_test_sll(sll_test); } printf("\n"); } printf("Done\n"); return 0; }
static int sack_init(_SackObject *self, PyObject *args, PyObject *kwds) { g_autoptr(GError) error = NULL; PyObject *custom_class = NULL; PyObject *custom_val = NULL; PycompString cachedir; const char *arch = NULL; const char *rootdir = NULL; PyObject *cachedir_py = NULL; PyObject *logfile_py = NULL; self->log_out = NULL; int make_cache_dir = 0; PyObject *debug_object = nullptr; gboolean all_arch = FALSE; const char *kwlist[] = {"cachedir", "arch", "rootdir", "pkgcls", "pkginitval", "make_cache_dir", "logfile", "logdebug", "all_arch", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OssOOiOO!i", (char**) kwlist, &cachedir_py, &arch, &rootdir, &custom_class, &custom_val, &make_cache_dir, &logfile_py, &PyBool_Type, &debug_object, &all_arch)) return -1; bool debug = debug_object != nullptr && PyObject_IsTrue(debug_object); if (cachedir_py != NULL) { cachedir = PycompString(cachedir_py); if (!cachedir.getCString()) return -1; } int flags = 0; if (make_cache_dir) flags |= DNF_SACK_SETUP_FLAG_MAKE_CACHE_DIR; self->sack = dnf_sack_new(); if (all_arch) { dnf_sack_set_all_arch(self->sack, all_arch); } else { if (!dnf_sack_set_arch(self->sack, arch, &error)) { PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack."); return -1; } } dnf_sack_set_rootdir(self->sack, rootdir); dnf_sack_set_cachedir(self->sack, cachedir.getCString()); if (logfile_py != NULL) { PycompString logfile(logfile_py); if (!logfile.getCString()) return -1; if (!set_logfile(logfile.getCString(), self->log_out, debug)) { PyErr_Format(PyExc_IOError, "Failed to open log file: %s", logfile.getCString()); return -1; } } if (!dnf_sack_setup(self->sack, flags, &error)) { switch (error->code) { case DNF_ERROR_FILE_INVALID: PyErr_SetString(PyExc_IOError, "Failed creating working files for the Sack."); break; case DNF_ERROR_INVALID_ARCHITECTURE: PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack."); break; default: assert(0); } return -1; } if (custom_class && custom_class != Py_None) { if (!PyType_Check(custom_class)) { PyErr_SetString(PyExc_TypeError, "Expected a class object."); return -1; } Py_INCREF(custom_class); self->custom_package_class = custom_class; } if (custom_val && custom_val != Py_None) { Py_INCREF(custom_val); self->custom_package_val = custom_val; } return 0; }
OV_RESULT ov_readConfigFile(ov_options* opts, char* configFile){ char lineStr[256]; char* startRead = NULL; char* temp = NULL; char* temp2 = NULL; char* temp3 = NULL; FILE* cfFile; OV_UINT j; OV_UINT line = 0; /* * parse config file * some memory is allocated on the heap. these variables are used while the server is running * hence this is no memleak. they are freed by the operating system on termination of the server * * * options from the commandline are NOT overwritten * lines starting with # and empty lines are ignored * Space and tab serve as whitespaces * lines are parsed as a whole * lines may be 256 characters long * no multi-line entries * * lines have the pattern * KEY VALUE * e.g. SERVERNAME ov_server1 * * recognized options are: * DBFILE path to database file. set to '-' to use no database * SERVERNAME name of this ov_server * HEAPSIZE size of TLSF heap pool * ID Ticket Identification for server access * PORT server port number * LIBRARY Start server with library. one library per line * LOGFILE logfile name for runtimeserver, you may use stdout, stderr or (on NT-systems) ntlog * ACTIVITYLOCK Locks OV activities (scheduler and accessorfnc). No argument * OPTION text Appends the option text to the * cmdline_options variable in Vendortree * text is mandatory * NOSTARTUP Do not startup the database. No argument * EXIT Exit immediately (test if database loads). No argument * EXEC IDENTIFIER CLASS LIBRARY Executes the first event in the schedulers * queue that matches concerning IDENTIFIER * CLASS and LIBRARY before starting the server. * All parameters are mandatory. Use '/' as wildcard. * ALLOWEDJITTER number of microseconds the scheduler may jitter before incrementing numExceeds in vondortree (the latter documents the realtime behaviour of the system) * KSMAXSTRLENGTH maximum length of strings to process with ks * KSMAXVECLENGTH maximum length of vectors to process with ks * KSMAXITEMSPERREQ maximum number of items per ks-request * DBSIZE db size when need to create * DBUTILLOG logfile name for dbutil, you may use stdout, stderr or (on NT-systems) ntlog * DBNOMAP read database but do not map * DBFORCECREATE force creation of a new database * old database file is removed */ if(!configFile || !(*configFile)){ return EXIT_FAILURE; } cfFile = fopen(configFile, "r"); if(!cfFile) { fprintf(stderr, "Could not open config file"); return EXIT_FAILURE; } clearerr(cfFile); /* get base path from path part of configFile */ #if OV_SYSTEM_NT for(j = strlen(configFile); configFile[j] != '\\' && configFile[j] != '/' && (j>0); j--); #else for(j = strlen(configFile); (configFile[j] != '/') && (j>0); j--); #endif if((j>0)) { opts->configBasePath = malloc(j+2); if(!opts->configBasePath) { ov_logfile_error("Could not reserve memory for basePath. Aborting."); return EXIT_FAILURE; } strncpy(opts->configBasePath, configFile, j+1); opts->configBasePath[j+1] = '\0'; //ov_logfile_debug("BasePath: %s", configBasePath); } /* * loop over lines */ while(fgets(lineStr, sizeof(lineStr), cfFile)) { line++; /* check if line complete */ if(!strchr(lineStr, '\n') && !feof(cfFile)) { ov_logfile_error("Error reading config file: line %u too long", line); return EXIT_FAILURE; } if(isComment(lineStr)) { /* skip line if comment */ continue; } startRead = skipWhiteSpace(lineStr); if(*startRead == '\0') break; /* probably EOF */ if(*startRead == '\n' || *startRead == '\r') continue; /* empty line */ /* set terminating '\0' at occurrence of newline or '#' */ terminateLine(startRead); /********************************************************************************** * parse parameters *********************************************************************************/ /* DBFILE */ if(strstr(startRead, "DBFILE")==startRead) { opt_clear_string(&opts->dbFilename); opts->dbFilename = readValue(startRead); if(!opts->dbFilename || !*opts->dbFilename){ return EXIT_FAILURE; } } /* SERVERNAME */ else if(strstr(startRead, "SERVERNAME")==startRead) { opt_clear_string(&opts->servername); opts->servername = readValue(startRead); if(!opts->servername || !*opts->servername){ return EXIT_FAILURE; } if(!serverNameOk(opts->servername)) { ov_logfile_error("Error parsing SERVERNAME in line %u: only A-Z, a-z, 0-9 and _ allowed in server name.", line); return EXIT_FAILURE; } } /* HEAPSIZE */ else if(strstr(startRead, "HEAPSIZE")==startRead) { #if TLSF_HEAP //ov_logfile_info("TLSF is activated"); temp = readValue(startRead); if(!temp || !*temp) return EXIT_FAILURE; if(!opts->poolsize){ opts->poolsize = strtoul(temp, NULL, 0); } else{ return OV_ERR_HEAPOUTOFMEMORY; } free(temp); #endif } /* ID */ else if(strstr(startRead, "ID")==startRead) { opt_clear_string(&opts->password); opts->password = readValue(startRead); if(!opts->password || !*opts->password){ return EXIT_FAILURE; } } /* PORT */ else if(strstr(startRead, "PORT")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->port = strtol(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for PORT.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* LIBRARY */ else if(strstr(startRead, "LIBRARY")==startRead) { if (opts->libcount<MAX_STARTUP_LIBRARIES) { opts->libraries[opts->libcount] = readValue(startRead); if(!opts->libraries[opts->libcount] || !*opts->libraries[opts->libcount]){ return EXIT_FAILURE; } opts->libcount++; } else ov_logfile_error("Too many libraries in start command and configfile.\n"); } /* LOGFILE */ else if((opts->ctx==ov_runtimeserver && strstr(startRead, "LOGFILE")==startRead )|| (opts->ctx==ov_dbutil && strstr(startRead, "DBUTILLOG")==startRead )) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } set_logfile(opts, temp); free(temp); } /* ACTIVITYLOCK */ else if(strstr(startRead, "ACTIVITYLOCK")==startRead) { opts->activitylock = TRUE; if(*(startRead+12)) { ov_logfile_error("Error parsing line %u: ACTIVITYLOCK does not accept parameters.", line); return EXIT_FAILURE; } } /* OPTION */ else if(strstr(startRead, "OPTION")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } temp2 = temp; while((!isWhiteSpace(temp2)) && *temp2) temp2++; if(*temp2!='\0') { /* whitespaces at line end are stripped: nothing may follow here */ ov_logfile_error("Error parsing OPTION in line %u: no whitespaces allowed in options.", line); free(temp); return EXIT_FAILURE; } if(opts->commandline_options) { temp2 = realloc(opts->commandline_options, strlen(opts->commandline_options)+strlen(temp)+2); //oldlength + new option length + ' ' + '\0' if(temp2) { strcat(temp2, " "); strcat(temp2, temp); opts->commandline_options = temp2; } } else //first time commandline_options is a NULL-pointer --> strlen would crash { opts->commandline_options = malloc(strlen(temp)+1); if(opts->commandline_options) strcpy(opts->commandline_options, temp); } free(temp); } /* NOSTARTUP */ else if(strstr(startRead, "NOSTARTUP")==startRead) { opts->startup = FALSE; if(*(startRead+9)) { ov_logfile_error("Error parsing line %u: NOSTARTUP does not accept parameters.", line); return EXIT_FAILURE; } } /* EXIT */ else if(strstr(startRead, "EXIT")==startRead) { opts->exit = TRUE; if(*(startRead+4)) { ov_logfile_error("Error parsing line %u: EXIT does not accept parameters.", line); return EXIT_FAILURE; } } /* EXEC */ else if(strstr(startRead, "EXEC")==startRead) { if(!opts->exec) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } temp2 = temp; while(!isWhiteSpace(temp2)){ if(!*temp2){ EXECFEWARGUMENTSERROR: ov_logfile_error("Error parsing line %u: not enough arguments to EXEC option.", line); free(temp); return EXIT_FAILURE; } temp2++; } *temp2 = '\0'; if(*temp!='/'){ opt_reassign_string(&opts->execIdent, temp); if(!opts->execIdent){ free(temp); return EXIT_FAILURE; } } else { opt_clear_string(&opts->execIdent); } temp3 = skipWhiteSpace(++temp2); temp2 = temp3; while(!isWhiteSpace(temp2)){ if(!temp2) goto EXECFEWARGUMENTSERROR; temp2++; } *temp2 = '\0'; if(*temp3!='/'){ opt_reassign_string(&opts->execClass, temp3); if(!opts->execClass){ free(temp); return EXIT_FAILURE; } } else { opt_clear_string(&opts->execClass); } temp3 = skipWhiteSpace(++temp2); temp2 = temp3; while(*temp2 && !isWhiteSpace(temp2)) temp2++; if(*temp2){ ov_logfile_error("Error parsing line %u: too many arguments to EXEC option.", line); free(temp); return EXIT_FAILURE; } if(*temp3!='/'){ opt_reassign_string(&opts->execLib, temp3); if(!opts->execLib){ free(temp); return EXIT_FAILURE; } } else { opt_clear_string(&opts->execLib); } opts->exec = TRUE; free(temp); } } /* ALLOWEDJITTER */ else if(strstr(startRead, "ALLOWEDJITTER")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->maxAllowedJitter = strtoul(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for ALLOWEDJITTER.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* MAXSTRLENGTH */ else if(strstr(startRead, "MAXSTRLENGTH")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->maxStringLength = strtoul(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for MAXSTRLENGTH.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* MAXVECLENGTH */ else if(strstr(startRead, "MAXVECLENGTH")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->maxVectorLength = strtoul(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for MAXVECLENGTH.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* MAXNAMELENGTH */ else if(strstr(startRead, "MAXNAMELENGTH")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->maxNameLength = strtoul(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for MAXNAMELENGTH.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* MAXHIERARCHYDEPTH */ else if(strstr(startRead, "MAXHIERARCHYDEPTH")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->maxHierarchyDepth = strtoul(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for MAXHIERARCHYDEPTH.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* KSMAXITEMSPERREQ */ else if(strstr(startRead, "KSMAXITEMSPERREQ")==startRead) { temp = readValue(startRead); if(!temp || !*temp){ return EXIT_FAILURE; } opts->ks_maxItemsPerRequest = strtoul(temp, &temp2, 0); if(*temp2) { ov_logfile_error("Error parsing line %u: too many arguments for KSMAXITEMSPERREQ.", line); free(temp); return EXIT_FAILURE; } free(temp); } /* DBSIZE */ else if(strstr(startRead, "DBSIZE")==startRead) { temp = readValue(startRead); if(!temp || !*temp) return EXIT_FAILURE; opts->dbSize = strtoul(temp, NULL, 0); free(temp); } /* DBNOMAP */ else if(strstr(startRead, "DBNOMAP")==startRead) { opts->dbflags |= OV_DBOPT_NOMAP; } /* DBFORCECREATE */ else if(strstr(startRead, "DBFORCECREATE")==startRead) { opts->dbflags |= OV_DBOPT_FORCECREATE; } /* * default: option unknown */ else { ov_logfile_error("Error parsing line %u: unknown option", line); return EXIT_FAILURE; } } /* getline returns -1 on error or eof. eof is ok, error aborts program */ if(ferror(cfFile)) { fprintf(stderr, "Error reading config file"); fclose(cfFile); return EXIT_FAILURE; } fclose(cfFile); return OV_ERR_OK; }
static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { if (reason == POPT_CALLBACK_REASON_PRE) { set_logfile(con, dyn_LOGFILEBASE); return; } switch(opt->val) { case 'd': if (arg) { debug_parse_levels(arg); AllowDebugChange = False; } break; case 'V': printf( "Version %s\n", SAMBA_VERSION_STRING); exit(0); break; case 'O': if (arg) { pstrcpy(user_socket_options,arg); } break; case 's': if (arg) { pstrcpy(dyn_CONFIGFILE, arg); } break; case 'n': if (arg) { set_global_myname(arg); } break; case 'l': if (arg) { set_logfile(con, arg); override_logfile = True; pstr_sprintf(dyn_LOGFILEBASE, "%s", arg); } break; case 'i': if (arg) { set_global_scope(arg); } break; case 'W': if (arg) { set_global_myworkgroup(arg); } break; } }
int main(int argc, char** argv) { result_t r; memset(g_obj_barrels, 0x00, sizeof(g_obj_barrels)); /* Init core library */ r = core_init(CORE_INIT_ALL); /* After core init, you can set logging options */ log_outputconsole(TRUE); set_logfile(); /* load config file (json) */ init_params* params = app_config_default(); if (params == NULL) { err_sendtolog(FALSE); core_release(FALSE); return -1; } /* Add our stuff to init params * Engine's data directory must be changed */ params->flags |= (ENG_FLAG_CONSOLE | ENG_FLAG_DEV); /* Initialize application (graphics device and rendering window) * Application name will also, be the name of the main window */ r = app_init(APP_NAME, params); if (IS_FAIL(r)) { err_sendtolog(FALSE); core_release(FALSE); app_config_unload(params); return -1; } /* Initialize engine */ r = eng_init(params); /* init params isn't needed anymore */ app_config_unload(params); if (IS_FAIL(r)) { err_sendtolog(FALSE); eng_release(); app_release(); core_release(TRUE); return -1; } if (!init_scene()) { err_sendtolog(FALSE); eng_release(); app_release(); core_release(TRUE); return -1; } /* Set application callbacks */ app_window_setupdatefn(update_callback); app_window_setkeypressfn(keypress_callback); app_window_setactivefn(activate_callback); app_window_setresizefn(resize_callback); gfx_set_debug_renderfunc(debug_view_callback); /* Initialize ok: show the main window */ app_window_show(); /* Enter message loop and update engine */ app_window_run(); /* cleanup */ release_scene(); eng_release(); app_release(); core_release(TRUE); return 0; }
int main (int argc, char **argv) { #ifdef GEKKO printf("\x1b[2;0H"); //initialize libfat library if (fatInitDefault()) printf("FAT subsytem initialized\n\n"); else { printf("Couldn't initialize FAT subsytem\n\n"); sleep(3); exit(0); } DIR *dp; dp = opendir ("sd:/"); if (dp) sdismount = 1; else sdismount = 0; if (sdismount) printf("SD FAT subsytem initialized\n\n"); else printf("Couldn't initialize SD fat subsytem\n\n"); if (sdismount) closedir (dp); usbismount = InitUSB(); default_prefs (&currprefs, 0); cfgfile_load (&currprefs, SMBFILENAME, 0); printf("\n"); if (currprefs.smb_enable) networkisinit = InitNetwork(); if (networkisinit && currprefs.smb_enable) ConnectShare(); sleep(2); if (!(log_quiet = !currprefs.write_logfile)) set_logfile("/uae/uae.log"); #endif write_log("main started\n"); init_sdl (); write_log("sdl inited\n"); gui_init (argc, argv); write_log("Starting real main\n"); real_main (argc, argv); #ifdef GEKKO if (smbismount) CloseShare (); DeInitUSB(); fatUnmount(0); #endif return 0; }
int main(int argc, const char **argv) { int res = -1; UNUSED_ARG(argc); UNUSED_ARG(argv); if(argc>1) print_extra = 1; set_logfile("stdout"); set_system_parameters(0); { const unsigned char reqstc[] = "\x00\x01\x00\x58" "\x21\x12\xa4\x42" "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae" "\x80\x22\x00\x10" "STUN test client" "\x00\x24\x00\x04" "\x6e\x00\x01\xff" "\x80\x29\x00\x08" "\x93\x2f\xf9\xb1\x51\x26\x3b\x36" "\x00\x06\x00\x09" "\x65\x76\x74\x6a\x3a\x68\x36\x76\x59\x20\x20\x20" "\x00\x08\x00\x14" "\x9a\xea\xa7\x0c\xbf\xd8\xcb\x56\x78\x1e\xf2\xb5" "\xb2\xd3\xf2\x49\xc1\xb5\x71\xa2" "\x80\x28\x00\x04" "\xe5\x7a\x3b\xcf"; u08bits buf[sizeof(reqstc)]; memcpy(buf, reqstc, sizeof(reqstc)); {//fingerprintfs etc res = stun_is_command_message_full_check_str(buf, sizeof(reqstc) - 1, 1, NULL); printf("RFC 5769 message fingerprint test(0) result: "); if (res) { printf("success\n"); } else if (res == 0) { printf("failure on fingerprint(0) check\n"); exit(-1); } } {//short-term credentials u08bits uname[33]; u08bits realm[33]; u08bits upwd[33]; strcpy((char*) upwd, "VOkJxbRl1RmTxUk/WvJxBt"); res = stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, sizeof(reqstc) - 1, uname, realm, upwd, shatype); printf("RFC 5769 simple request short-term credentials and integrity test result: "); if (res > 0) { printf("success\n"); } else if (res == 0) { printf("failure on integrity check\n"); exit(-1); } else { printf("failure on message structure check\n"); exit(-1); } } {//negative fingerprint buf[27] = 23; res = stun_is_command_message_full_check_str(buf, sizeof(reqstc) - 1, 1, NULL); printf("RFC 5769 NEGATIVE fingerprint test(0) result: "); if (!res) { printf("success\n"); } else if (res == 0) { printf("failure on NEGATIVE fingerprint check\n"); exit(-1); } } } { const unsigned char reqltc[] = "\x00\x01\x00\x60" "\x21\x12\xa4\x42" "\x78\xad\x34\x33\xc6\xad\x72\xc0\x29\xda\x41\x2e" "\x00\x06\x00\x12" "\xe3\x83\x9e\xe3\x83\x88\xe3\x83\xaa\xe3\x83\x83" "\xe3\x82\xaf\xe3\x82\xb9\x00\x00" "\x00\x15\x00\x1c" "\x66\x2f\x2f\x34\x39\x39\x6b\x39\x35\x34\x64\x36" "\x4f\x4c\x33\x34\x6f\x4c\x39\x46\x53\x54\x76\x79" "\x36\x34\x73\x41" "\x00\x14\x00\x0b" "\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67\x00" "\x00\x08\x00\x14" "\xf6\x70\x24\x65\x6d\xd6\x4a\x3e\x02\xb8\xe0\x71" "\x2e\x85\xc9\xa2\x8c\xa8\x96\x66"; u08bits user[] = "\xe3\x83\x9e\xe3\x83\x88\xe3\x83\xaa\xe3\x83\x83" "\xe3\x82\xaf\xe3\x82\xb9"; u08bits realm[33]; u08bits nonce[29]; u08bits upwd[33]; u08bits buf[sizeof(reqltc)]; memcpy(buf, reqltc, sizeof(reqltc)); u08bits uname[sizeof(user)]; memcpy(uname, user, sizeof(user)); strcpy((char*) realm, "example.org"); strcpy((char*) upwd, "TheMatrIX"); strcpy((char*)nonce,"f//499k954d6OL34oL9FSTvy64sA"); res = stun_check_message_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, sizeof(reqltc) - 1, uname, realm, upwd, shatype); printf("RFC 5769 message structure, long-term credentials and integrity test result: "); if (res > 0) { printf("success\n"); } else if (res == 0) { printf("failure on integrity check\n"); exit(-1); } else { printf("failure on message structure check\n"); exit(-1); } { //encoding test printf("RFC 5769 message encoding test result: "); size_t len = 0; u16bits message_type = STUN_METHOD_BINDING; stun_tid tid; u16bits *buf16 = (u16bits*)buf; u32bits *buf32 = (u32bits*)buf; memcpy(tid.tsx_id,"\x78\xad\x34\x33\xc6\xad\x72\xc0\x29\xda\x41\x2e",12); stun_init_buffer_str(buf,&len); message_type &= (u16bits)(0x3FFF); buf16[0]=nswap16(message_type); buf16[1]=0; buf32[1]=nswap32(STUN_MAGIC_COOKIE); stun_tid_message_cpy(buf, &tid); stun_attr_add_integrity_by_user_str(buf, &len, uname, realm, upwd, nonce, shatype); if(len != (sizeof(reqltc)-1)) { printf("failure: length %d, must be %d\n",(int)len,(int)(sizeof(reqltc)-1)); exit(-1); } if(memcmp(buf,reqltc,len)) { printf("failure: wrong message content\n"); { int lines = 29; int line = 0; int col = 0; int cols = 4; for(line = 0;line<lines;line++) { for(col = 0; col<cols; col++) { u08bits c = buf[line*4+col]; printf(" %2x",(int)c); } printf("\n"); } } exit(-1); } printf("success\n"); } //Negative test: buf[32] = 10; res = stun_check_message_integrity_str(TURN_CREDENTIALS_LONG_TERM, buf, sizeof(reqltc) - 1, uname, realm, upwd, shatype); printf("RFC 5769 NEGATIVE long-term credentials test result: "); if (res == 0) { printf("success\n"); } else { printf("failure on NEGATIVE long-term credentials check\n"); exit(-1); } } { const unsigned char respv4[] = "\x01\x01\x00\x3c" "\x21\x12\xa4\x42" "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae" "\x80\x22\x00\x0b" "\x74\x65\x73\x74\x20\x76\x65\x63\x74\x6f\x72\x20" "\x00\x20\x00\x08" "\x00\x01\xa1\x47\xe1\x12\xa6\x43" "\x00\x08\x00\x14" "\x2b\x91\xf5\x99\xfd\x9e\x90\xc3\x8c\x74\x89\xf9" "\x2a\xf9\xba\x53\xf0\x6b\xe7\xd7" "\x80\x28\x00\x04" "\xc0\x7d\x4c\x96"; u08bits buf[sizeof(respv4)]; memcpy(buf, respv4, sizeof(respv4)); {//fingerprintfs etc res = stun_is_command_message_full_check_str(buf, sizeof(respv4) - 1, 1, NULL); printf("RFC 5769 message fingerprint test(1) result: "); if (res) { printf("success\n"); } else if (res == 0) { printf("failure on fingerprint(1) check\n"); exit(-1); } } {//short-term credentials u08bits uname[33]; u08bits realm[33]; u08bits upwd[33]; strcpy((char*) upwd, "VOkJxbRl1RmTxUk/WvJxBt"); res = stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, sizeof(respv4) - 1, uname, realm, upwd, shatype); printf("RFC 5769 IPv4 response short-term credentials and integrity test result: "); if (res > 0) { printf("success\n"); } else if (res == 0) { printf("failure on integrity check\n"); exit(-1); } else { printf("failure on message structure check\n"); exit(-1); } } {//negative fingerprint buf[27] = 23; res = stun_is_command_message_full_check_str(buf, sizeof(respv4) - 1, 1, NULL); printf("RFC 5769 NEGATIVE fingerprint test(1) result: "); if (!res) { printf("success\n"); } else if (res == 0) { printf("failure on NEGATIVE fingerprint check\n"); exit(-1); } } {//IPv4 addr ioa_addr addr4; ioa_addr addr4_test; printf("RFC 5769 IPv4 encoding result: "); res = stun_attr_get_first_addr_str(buf, sizeof(respv4)-1, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &addr4, NULL); if(res < 0) { printf("failure on message structure check\n"); exit(-1); } make_ioa_addr((const u08bits*)"192.0.2.1", 32853, &addr4_test); if(addr_eq(&addr4,&addr4_test)) { printf("success\n"); } else { printf("failure on IPv4 deconding check\n"); exit(-1); } } } { const unsigned char respv6[] = "\x01\x01\x00\x48" "\x21\x12\xa4\x42" "\xb7\xe7\xa7\x01\xbc\x34\xd6\x86\xfa\x87\xdf\xae" "\x80\x22\x00\x0b" "\x74\x65\x73\x74\x20\x76\x65\x63\x74\x6f\x72\x20" "\x00\x20\x00\x14" "\x00\x02\xa1\x47" "\x01\x13\xa9\xfa\xa5\xd3\xf1\x79" "\xbc\x25\xf4\xb5\xbe\xd2\xb9\xd9" "\x00\x08\x00\x14" "\xa3\x82\x95\x4e\x4b\xe6\x7b\xf1\x17\x84\xc9\x7c" "\x82\x92\xc2\x75\xbf\xe3\xed\x41" "\x80\x28\x00\x04" "\xc8\xfb\x0b\x4c"; u08bits buf[sizeof(respv6)]; { //decoding test memcpy(buf, respv6, sizeof(respv6)); res = stun_is_command_message_full_check_str(buf, sizeof(respv6) - 1, 1, NULL); printf("RFC 5769 message fingerprint test(2) result: "); if (res) { printf("success\n"); } else if (res == 0) { printf("failure on fingerprint(2) check\n"); exit(-1); } } {//short-term credentials test u08bits uname[33]; u08bits realm[33]; u08bits upwd[33]; strcpy((char*) upwd, "VOkJxbRl1RmTxUk/WvJxBt"); res = stun_check_message_integrity_str(TURN_CREDENTIALS_SHORT_TERM, buf, sizeof(respv6) - 1, uname, realm, upwd, shatype); printf("RFC 5769 IPv6 response short-term credentials and integrity test result: "); if (res > 0) { printf("success\n"); } else if (res == 0) { printf("failure on integrity check\n"); exit(-1); } else { printf("failure on message structure check\n"); exit(-1); } } {//negative decoding test buf[27] = 23; res = stun_is_command_message_full_check_str(buf, sizeof(respv6) - 1, 1, NULL); printf("RFC 5769 NEGATIVE fingerprint test(2) result: "); if (!res) { printf("success\n"); } else if (res == 0) { printf("failure on NEGATIVE fingerprint check\n"); exit(-1); } } {//IPv6 deconding test ioa_addr addr6; ioa_addr addr6_test; printf("RFC 5769 IPv6 encoding result: "); res = stun_attr_get_first_addr_str(buf, sizeof(respv6) - 1, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &addr6, NULL); if (res < 0) { printf("failure on message structure check\n"); exit(-1); } make_ioa_addr((const u08bits*) "2001:db8:1234:5678:11:2233:4455:6677", 32853, &addr6_test); if (addr_eq(&addr6, &addr6_test)) { printf("success\n"); } else { printf("failure on IPv6 deconding check\n"); exit(-1); } } } { if(check_oauth()<0) exit(-1); } return 0; }
int main(int argc, char **argv) { int port = 0; int messagenumber = 5; char local_addr[256]; int c; int mclient = 1; char peer_address[129] = "\0"; int peer_port = PEER_DEFAULT_PORT; char rest_api_separator = ':'; int use_null_cipher=0; set_logfile("stdout"); set_execdir(); set_system_parameters(0); ns_bzero(local_addr, sizeof(local_addr)); while ((c = getopt(argc, argv, "d:p:l:n:L:m:e:r:u:w:i:k:z:W:C:E:F:vsyhcxXgtTSAPDNOUHMRIGB")) != -1) { switch (c){ case 'B': random_disconnect = 1; break; case 'G': extra_requests = 1; break; case 'F': STRCPY(cipher_suite,optarg); break; case 'I': no_permissions = 1; break; case 'M': mobility = 1; break; case 'H': shatype = SHATYPE_SHA256; break; case 'E': { char* fn = find_config_file(optarg,1); if(!fn) { fprintf(stderr,"ERROR: file %s not found\n",optarg); exit(-1); } STRCPY(ca_cert_file,fn); } break; case 'O': dos = 1; break; case 'C': rest_api_separator=*optarg; break; case 'D': mandatory_channel_padding = 1; break; case 'N': negative_test = 1; break; case 'R': negative_protocol_test = 1; break; case 'z': RTP_PACKET_INTERVAL = atoi(optarg); break; case 'A': use_short_term = 1; break; case 'u': STRCPY(g_uname, optarg); break; case 'w': STRCPY(g_upwd, optarg); break; case 'g': dont_fragment = 1; break; case 'd': STRCPY(client_ifname, optarg); break; case 'x': default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6; break; case 'X': default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4; break; case 'l': clmessage_length = atoi(optarg); break; case 's': do_not_use_channel = 1; break; case 'n': messagenumber = atoi(optarg); break; case 'p': port = atoi(optarg); break; case 'L': STRCPY(local_addr, optarg); break; case 'e': STRCPY(peer_address, optarg); break; case 'r': peer_port = atoi(optarg); break; case 'v': clnet_verbose = TURN_VERBOSE_NORMAL; break; case 'h': hang_on = 1; break; case 'c': no_rtcp = 1; break; case 'm': mclient = atoi(optarg); break; case 'y': c2c = 1; break; case 't': use_tcp = 1; break; case 'P': passive_tcp = 1; /* implies 'T': */ /* no break */ case 'T': relay_transport = STUN_ATTRIBUTE_TRANSPORT_TCP_VALUE; break; case 'U': use_null_cipher = 1; /* implies 'S' */ /* no break */ case 'S': use_secure = 1; break; case 'W': g_use_auth_secret_with_timestamp = 1; STRCPY(g_auth_secret,optarg); break; case 'i': { char* fn = find_config_file(optarg,1); if(!fn) { fprintf(stderr,"ERROR: file %s not found\n",optarg); exit(-1); } STRCPY(cert_file,fn); free(fn); } break; case 'k': { char* fn = find_config_file(optarg,1); if(!fn) { fprintf(stderr,"ERROR: file %s not found\n",optarg); exit(-1); } STRCPY(pkey_file,fn); free(fn); } break; default: fprintf(stderr, "%s\n", Usage); exit(1); } } if(g_use_auth_secret_with_timestamp) { if(use_short_term) { fprintf(stderr,"ERROR: You cannot use authentication secret (REST API) with short-term credentials mechanism.\n"); exit(-1); } { char new_uname[1025]; const unsigned long exp_time = 3600 * 24; /* one day */ if(g_uname[0]) { snprintf(new_uname,sizeof(new_uname),"%lu%c%s",(unsigned long)time(NULL) + exp_time,rest_api_separator, (char*)g_uname); } else { snprintf(new_uname,sizeof(new_uname),"%lu", (unsigned long)time(NULL) + exp_time); } STRCPY(g_uname,new_uname); } { u08bits hmac[MAXSHASIZE]; unsigned int hmac_len; switch(shatype) { case SHATYPE_SHA256: hmac_len = SHA256SIZEBYTES; break; default: hmac_len = SHA1SIZEBYTES; }; hmac[0]=0; if(stun_calculate_hmac(g_uname, strlen((char*)g_uname), (u08bits*)g_auth_secret, strlen(g_auth_secret), hmac, &hmac_len, shatype)>=0) { size_t pwd_length = 0; char *pwd = base64_encode(hmac,hmac_len,&pwd_length); if(pwd) { if(pwd_length>0) { ns_bcopy(pwd,g_upwd,pwd_length); g_upwd[pwd_length]=0; } } free(pwd); } } } if(is_TCP_relay()) { dont_fragment = 0; no_rtcp = 1; c2c = 1; use_tcp = 1; do_not_use_channel = 1; } if(port == 0) { if(use_secure) port = DEFAULT_STUN_TLS_PORT; else port = DEFAULT_STUN_PORT; } if (clmessage_length < (int) sizeof(message_info)) clmessage_length = (int) sizeof(message_info); const int max_header = 100; if(clmessage_length > (int)(STUN_BUFFER_SIZE-max_header)) { fprintf(stderr,"Message length was corrected to %d\n",(STUN_BUFFER_SIZE-max_header)); clmessage_length = (int)(STUN_BUFFER_SIZE-max_header); } if (optind >= argc) { fprintf(stderr, "%s\n", Usage); exit(-1); } if (!c2c) { if (make_ioa_addr((const u08bits*) peer_address, peer_port, &peer_addr) < 0) return -1; if(peer_addr.ss.sa_family == AF_INET6) default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6; } /* SSL Init ==>> */ if(use_secure) { SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); const char *csuite = "ALL"; //"AES256-SHA" "DH" if(use_null_cipher) csuite = "eNULL"; else if(cipher_suite[0]) csuite=cipher_suite; if(use_tcp) { root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(SSLv23_client_method()); SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite); root_tls_ctx_num++; root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(SSLv3_client_method()); SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite); root_tls_ctx_num++; root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(TLSv1_client_method()); SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite); root_tls_ctx_num++; #if defined(SSL_TXT_TLSV1_1) root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(TLSv1_1_client_method()); SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite); root_tls_ctx_num++; #if defined(SSL_TXT_TLSV1_2) root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(TLSv1_2_client_method()); SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite); root_tls_ctx_num++; #endif #endif } else { #if defined(TURN_NO_DTLS) fprintf(stderr,"ERROR: DTLS is not supported.\n"); exit(-1); #else if(OPENSSL_VERSION_NUMBER < 0x10000000L) { TURN_LOG_FUNC(TURN_LOG_LEVEL_WARNING, "WARNING: OpenSSL version is rather old, DTLS may not be working correctly.\n"); } root_tls_ctx[root_tls_ctx_num] = SSL_CTX_new(DTLSv1_client_method()); SSL_CTX_set_cipher_list(root_tls_ctx[root_tls_ctx_num], csuite); root_tls_ctx_num++; #endif } int sslind = 0; for(sslind = 0; sslind<root_tls_ctx_num; sslind++) { if(cert_file[0]) { if (!SSL_CTX_use_certificate_chain_file(root_tls_ctx[sslind], cert_file)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "\nERROR: no certificate found!\n"); exit(-1); } } if (!SSL_CTX_use_PrivateKey_file(root_tls_ctx[sslind], pkey_file, SSL_FILETYPE_PEM)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "\nERROR: no private key found!\n"); exit(-1); } if(cert_file[0]) { if (!SSL_CTX_check_private_key(root_tls_ctx[sslind])) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "\nERROR: invalid private key!\n"); exit(-1); } } if (ca_cert_file[0]) { if (!SSL_CTX_load_verify_locations(root_tls_ctx[sslind], ca_cert_file, NULL )) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "ERROR: cannot load CA from file: %s\n", ca_cert_file); } /* Set to require peer (client) certificate verification */ SSL_CTX_set_verify(root_tls_ctx[sslind], SSL_VERIFY_PEER, NULL ); /* Set the verification depth to 9 */ SSL_CTX_set_verify_depth(root_tls_ctx[sslind], 9); } else { SSL_CTX_set_verify(root_tls_ctx[sslind], SSL_VERIFY_NONE, NULL ); } if(!use_tcp) SSL_CTX_set_read_ahead(root_tls_ctx[sslind], 1); } } start_mclient(argv[optind], port, client_ifname, local_addr, messagenumber, mclient); return 0; }
OV_RESULT ov_readArgs(ov_options* opts, int argc, char** argv){ char* tempstr = NULL; int i; for(i = 1; i<argc; i++) { /* * set database filename option */ if(!strcmp(argv[i], "-f") || !strcmp(argv[i], "--file")) { i++; if(i<argc) { if(argv[i]) { opts->dbFilename = realloc(opts->dbFilename, strlen(argv[i])+1); if(!opts->dbFilename){ return EXIT_FAILURE; } strcpy(opts->dbFilename, argv[i]); } else { goto HELP; } } else { goto HELP; } } /* * set database backup filename option */ else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--backup")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if(i<argc) { opts->dbBackupFilename = argv[i]; //TODO malloc? } else { goto HELP; } } /* * set server name option */ else if(!strcmp(argv[i], "-s") || !strcmp(argv[i], "--server-name")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if(i<argc) { if(argv[i]) { if(!serverNameOk(argv[i])){ ov_logfile_error("Invalid servername given: only A-Z, a-z, 0-9 and _ allowed."); return EXIT_FAILURE; } opts->servername = realloc(opts->servername, strlen(argv[i])+1); if(!opts->servername){ return EXIT_FAILURE; } strcpy(opts->servername, argv[i]); } else { goto HELP; } } else { goto HELP; } } /* * set config file * parsing of configfile should be done beforehand */ else if(!strcmp(argv[i], "-cf") || !strcmp(argv[i], "--config") || (opts->ctx==ov_runtimeserver && !strcmp(argv[i], "-c"))) { /* -c for legacy compatibility */ i++; if(i<argc){ opts->configFile = argv[i]; } else goto HELP; } /* * set port number option */ else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--port-number")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if(i<argc) { opts->port = strtol(argv[i], NULL, 0); } else { goto HELP; } } /* * set identification */ else if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--identifiy")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if(i<argc) { if(argv[i]) { opts->password = realloc(opts->password, strlen(argv[i])+1); if(!opts->password){ return EXIT_FAILURE; } strcpy(opts->password, argv[i]); } else { goto HELP; } } else { goto HELP; } } /* * set activity lock */ else if(!strcmp(argv[i], "-a") || !strcmp(argv[i], "--activity-lock")) { if(opts->ctx!=ov_runtimeserver) goto HELP; opts->activitylock = TRUE; } /* * handle commandline options */ else if(!strcmp(argv[i], "-o") || !strcmp(argv[i], "--option")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if(i<argc) { if(opts->commandline_options) { tempstr = realloc(opts->commandline_options, strlen(opts->commandline_options)+strlen(argv[i])+2); //oldlength + new option length + ' ' + '\0' if(tempstr) { strcat(tempstr, " "); strcat(tempstr, argv[i]); opts->commandline_options = tempstr; } } else //first time commandline_options is a NULL-pointer --> strlen would crash { opts->commandline_options = malloc(strlen(argv[i])+1); if(opts->commandline_options) strcpy(opts->commandline_options, argv[i]); } } else { goto HELP; } } /* * start with library */ else if(!strcmp(argv[i], "-w") || !strcmp(argv[i], "--start-with")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if (opts->libcount<MAX_STARTUP_LIBRARIES) { if(argv[i]) { opts->libraries[opts->libcount] = malloc(strlen(argv[i])+1); if(!opts->libraries[opts->libcount]){ return EXIT_FAILURE; } strcpy(opts->libraries[opts->libcount], argv[i]); opts->libcount++; } else { goto HELP; } } else ov_logfile_error("Too many libraries in start command and configfile.\n"); } /* * exit immideately */ else if(!strcmp(argv[i], "-x") || !strcmp(argv[i], "--exit")) { if(opts->ctx!=ov_runtimeserver) goto HELP; opts->exit = TRUE; } /* * set logfile option */ else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--logfile")) { i++; //logfileSpecified = TRUE; if(i<argc) { if(set_logfile(opts, argv[i])!=EXIT_SUCCESS) return EXIT_FAILURE; } else { goto HELP; } } #if OV_SYSTEM_RMOS /* * terminate server option */ else if(!strcmp(argv[i], "-t") || !strcmp(argv[i], "--terminate")) { if(opts->ctx!=ov_runtimeserver) goto HELP; i++; if(i<argc) { opts->taskid = strtol(argv[i], NULL, 0); opts->terminate = TRUE; } else { goto HELP; } } #endif /* * no startup option */ else if(!strcmp(argv[i], "-n") || !strcmp(argv[i], "--no-startup")) { if(opts->ctx!=ov_runtimeserver) goto HELP; opts->startup = FALSE; } /* * display version option */ else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { if(opts->version) opts->version(); else fprintf(stderr, "no version information available\n"); ov_logfile_free(); exit(EXIT_SUCCESS); } /* * exec option * before the server is started up ths first event in the schedulers event queue that matchers identifier, class and / or library * is executed ONCE * This is useful to start the RootComTask on a database with set activitylock ("forensic mode" / dead database with communication) */ else if(!strcmp(argv[i], "--exec")) { if(opts->ctx!=ov_runtimeserver) goto HELP; opts->exec = TRUE; i++; if(i<argc) { if(*(argv[i])!='/') //get Identifier { opts->execIdent = realloc(opts->execIdent, strlen(argv[i])+1); if(!opts->execIdent){ return EXIT_FAILURE; } strcpy(opts->execIdent, argv[i]); } else { opt_clear_string(&opts->execIdent); } i++; if(i<argc) { if(*(argv[i])!='/') //get Class { opts->execClass = malloc(strlen(argv[i])+1); if(!opts->execClass){ return EXIT_FAILURE; } strcpy(opts->execClass, argv[i]); } else { opt_clear_string(&opts->execClass); } i++; if(i<argc) { if(*(argv[i])!='/') //get Library { opts->execLib = malloc(strlen(argv[i])+1); if(!opts->execLib){ return EXIT_FAILURE; } strcpy(opts->execLib, argv[i]); } else { opt_clear_string(&opts->execLib); } } else { goto HELP; } } else { goto HELP; } } else { goto HELP; } } /* * set no map flag */ else if(!strcmp(argv[i], "--no-map")) { if(opts->ctx!=ov_runtimeserver) goto HELP; opts->dbflags |= OV_DBOPT_NOMAP; } /* * set force create flag */ else if(!strcmp(argv[i], "--force-create")) { opts->dbflags |= OV_DBOPT_FORCECREATE; } /* * create database option */ else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--create")) { if(opts->ctx!=ov_dbutil) goto HELP; i++; if(i<argc) { opts->dbSize = strtoul(argv[i], NULL, 0); } else { goto HELP; } } /* * display extended information */ else if(!strcmp(argv[i], "-e") || !strcmp(argv[i], "--extended")) { if(opts->ctx!=ov_dbutil) goto HELP; opts->extended = TRUE; } /* * dump database */ else if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "--dump")) { if(opts->ctx!=ov_dbutil) goto HELP; i++; if(i<argc) { opts->dumpfilename = argv[i]; } else { goto HELP; } } /* * change dump format to fbd */ else if(!strcmp(argv[i], "--fbd")) { if(opts->ctx!=ov_dbutil) goto HELP; i++; opts->fbdDump = TRUE; if(i<argc) { if(*argv[i] != '-'){ if(*argv[i] == '/'){ opts->fbdStart = argv[i]; } else { fprintf(stderr, "OV path needs to start with '/'"); return EXIT_FAILURE; } } else { // next arg is an option i--; } } } /* * modify excluded folders for fbd dump */ else if(!strcmp(argv[i], "--dump-expert")) { if(opts->ctx!=ov_dbutil) goto HELP; opts->fbdDumpMode = 1; } /* * display help option */ else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { HELP: if(opts->usage) opts->usage(); else fprintf(stderr, "usage information not available"); ov_logfile_free(); exit(EXIT_FAILURE); } else { goto HELP; } } return OV_ERR_OK; }
static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { if (reason == POPT_CALLBACK_REASON_PRE) { set_logfile(con, get_dyn_LOGFILEBASE()); talloc_set_log_fn(popt_s3_talloc_log_fn); talloc_set_abort_fn(smb_panic); return; } if (reason == POPT_CALLBACK_REASON_POST) { if (PrintSambaVersionString) { printf( "Version %s\n", samba_version_string()); exit(0); } if (is_default_dyn_CONFIGFILE()) { if(getenv("SMB_CONF_PATH")) { set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH")); } } /* Further 'every Samba program must do this' hooks here. */ return; } switch(opt->val) { case OPT_OPTION: if (!lp_set_option(arg)) { fprintf(stderr, "Error setting option '%s'\n", arg); exit(1); } break; case 'd': if (arg) { lp_set_cmdline("log level", arg); } break; case 'V': PrintSambaVersionString = True; break; case 'O': if (arg) { lp_do_parameter(-1, "socket options", arg); } break; case 's': if (arg) { set_dyn_CONFIGFILE(arg); } break; case 'n': if (arg) { lp_set_cmdline("netbios name", arg); } break; case 'l': if (arg) { set_logfile(con, arg); override_logfile = True; set_dyn_LOGFILEBASE(arg); } break; case 'i': if (arg) { lp_set_cmdline("netbios scope", arg); } break; case 'W': if (arg) { lp_set_cmdline("workgroup", arg); } break; } }
int main(int argc, char* argv[]) { std::ifstream scr; //поток файла команд fd_set fdin; //набор дескрипторов, на которых ожидаются входные данные char ipm1[15] = IP_MAD1; char ipm2[15] = IP_MAD2; char ipm3[15] = IP_MAD3; char ipC[15] = IP_CENTER; //порты unsigned int pD = PORT_DATA; unsigned int pM = PORT_MONITOROGRAMM; unsigned int pC = PORT_CONTROL; unsigned int pCen = PORT_CENTRAL; //время сна команды после запуска unsigned int timeSleep = 0; //Инициализация аргументами командной строки соответствующих параметров программы for (int i = 1; i < argc; i += 2) { if (!strcmp("--pD", argv[i])) pD = atoi(argv[i + 1]); else if (!strcmp("--pM", argv[i])) pM = atoi(argv[i + 1]); else if (!strcmp("--pC", argv[i])) pC = atoi(argv[i + 1]); else if (!strcmp("--pCen", argv[i])) pCen = atoi(argv[i + 1]); else if (!strcmp("--s", argv[i])) timeSleep = atoi(argv[i + 1]); else if (!strcmp("--ipm1", argv[i])) strcpy(ipm1, argv[i + 1]); else if (!strcmp("--ipm2", argv[i])) strcpy(ipm2, argv[i + 1]); else if (!strcmp("--ipm3", argv[i])) strcpy(ipm3, argv[i + 1]); else if (!strcmp("--ipC", argv[i])) strcpy(ipC, argv[i + 1]); else if (!strcmp("--scr", argv[i])) { scr.open(argv[i + 1]); if (!scr.is_open()) std::cout << "Программа не смогла открыть входной поток данных\n"; } else printf("%d параметр не поддерживается программой\n", i); } //засыпание перед запуском программы sleep(timeSleep); set_logfile(LOGFILE); std::string str = "Программа запущена" + (" pid = " + std::to_string(getpid())); to_journal(str); center_n::Center Center(ipC, pCen); mad_n::Mad mad[3] = { mad_n::Mad(&Center, 1, ipm1, pD, pM, pC), mad_n::Mad( &Center, 2, ipm2, pD, pM, pC), mad_n::Mad(&Center, 3, ipm3, pD, pM, pC) }; //вычисление наибольшого по значению дескриптора int max_d = mad_n::Mad::getSockData(); if (max_d < mad_n::Mad::getSockMon()) max_d = mad_n::Mad::getSockMon(); if (max_d < mad_n::Mad::getSockCon()) max_d = mad_n::Mad::getSockCon(); //выполнение предварительного файла команд if (scr.is_open()) while (scr) { try { handl_command_line(mad, MAX_NUM_STRING, scr); } catch (const char* str) { std::cout << str << std::endl; } catch (const std::exception& a) { std::cout << a.what() << std::endl; } } scr.close(); //ГЛАВНЫЙ ЦИКЛ int status = 0; printf("hello\n"); for (;;) { FD_ZERO(&fdin); FD_SET(STDIN_FILENO, &fdin); FD_SET(mad_n::Mad::getSockData(), &fdin); FD_SET(mad_n::Mad::getSockMon(), &fdin); FD_SET(mad_n::Mad::getSockCon(), &fdin); //ожидание событий status = select(max_d + 1, &fdin, NULL, NULL, NULL); if (status == -1) { if (errno == EINTR) continue; else { perror("Функция select завершилась крахом\n"); exit(1); } } if (FD_ISSET(mad_n::Mad::getSockData(), &fdin)) mad_n::receiptData(mad); if (FD_ISSET(mad_n::Mad::getSockMon(), &fdin)) mad_n::receiptMon(mad); if (FD_ISSET(STDIN_FILENO, &fdin)) { try { handl_command_line(mad, MAX_NUM_STRING, std::cin); } catch (const char* str) { std::cout << str << std::endl; } catch (const std::exception& a) { std::cout << a.what() << std::endl; } } if (FD_ISSET(mad_n::Mad::getSockCon(), &fdin)) mad_n::receiptCon(mad, 3); } }
static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { if (reason == POPT_CALLBACK_REASON_PRE) { set_logfile(con, get_dyn_LOGFILEBASE()); return; } if (reason == POPT_CALLBACK_REASON_POST) { if (PrintSambaVersionString) { printf( "Version %s\n", samba_version_string()); exit(0); } if (is_default_dyn_CONFIGFILE()) { if(getenv("SMB_CONF_PATH")) { set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH")); } } /* Further 'every Samba program must do this' hooks here. */ return; } switch(opt->val) { case 'd': if (arg) { debug_parse_levels(arg); AllowDebugChange = False; } break; case 'V': PrintSambaVersionString = True; break; case 'O': if (arg) { lp_do_parameter(-1, "socket options", arg); } break; case 's': if (arg) { set_dyn_CONFIGFILE(arg); } break; case 'n': if (arg) { set_global_myname(arg); } break; case 'l': if (arg) { set_logfile(con, arg); override_logfile = True; set_dyn_LOGFILEBASE(arg); } break; case 'i': if (arg) { set_global_scope(arg); } break; case 'W': if (arg) { set_global_myworkgroup(arg); } break; } }