Exemplo n.º 1
0
void ErrorMsgAssertU64 ( JNIEnv * jenv, ctx_t ctx, uint32_t lineno, jlong i )
{
    if ( i < 0 )
    {
        USER_ERROR ( xcIntegerOutOfBounds, "expected unsigned integer but found %ld", i );
        ErrorMsgThrow ( jenv, ctx, lineno, "integer sign violation" );
    }
}
Exemplo n.º 2
0
NormalizeAM::NormalizeAM(char *inFile, char *rttmName)
{
  FeaturePool *featurePool = new FeaturePool(inFile,FILE_TYPE_RAW_DECODING,false,1.0,false,true);  // Only prepare...
  int segID = featurePool->claimSegmentationID();


  char segmentString[60];
  strcpy(segmentString,"SPEECH");
  strcpy(&(segmentString[20]),"SIL");
  strcpy(&(segmentString[40]),"SOUND");
  FILE *inSegFile = fopen(rttmName,"rt");
  if(inSegFile == NULL)
  {
    USER_ERROR("ERROR: Could not read the input RTTM file for decoding!\n");
  }
  featurePool->readRTTM(segID,segmentString,3,20,0,inSegFile);
  fclose(inSegFile);

  featurePool->createNewPool(inFile, NULL, NULL, false, false, segID);
}
Exemplo n.º 3
0
/* prints usage, exits */
static void 
print_usage()
{
	processor_config_t *config = 0;
	p2pship_log_level = -1;
	if ((config = processor_config_new())) {
		if (processor_config_load_defaults(config)) {
			USER_ERROR("Warning: Current configuration completely loaded\n");
		}
		processor_config_load(config, NULL);
	}
	
        USER_ERROR("Usage: p2pship [OPTION]\n\n");
        USER_ERROR("  -v, --verbose              verbosely report info\n");
        USER_ERROR("  -i, --iface [IFACE,..]     list of interfaces to publicly advertise (%s)\n", 
		   processor_config_string(config, P2PSHIP_CONF_IFACES));
#ifdef CONFIG_SIP_ENABLED
        USER_ERROR("  -p [PORT]                  use PORT for the legacy sip proxy (%d)\n", 
		   processor_config_int(config, P2PSHIP_CONF_SIPP_PROXY_PORT));
#endif
        USER_ERROR("  -s [PORT]                  use PORT for SHIP daemon communication (%d)\n", 
		   processor_config_int(config, P2PSHIP_CONF_SHIP_PORT));
        USER_ERROR("  -D                         start as daemon (%s)\n", 
		   (processor_config_is_true(config, P2PSHIP_CONF_DAEMON)? "yes":"no"));
        USER_ERROR("  -c [FILE]                  read configuration from [FILE]\n");
	USER_ERROR("                             (%s)\n", 
		   processor_config_string(config, P2PSHIP_CONF_CONF_FILE));
        USER_ERROR("  -k                         kill existing p2pship for user\n");
        USER_ERROR("  -K                         kill (or try to) ALL existing p2pship instances\n");
        USER_ERROR("  -R                         autoregister previous UAs\n");
        USER_ERROR("  -r [FILE]                  use [FILE] as the autoregister cache\n");
	USER_ERROR("                             (%s)\n", 
		   processor_config_string(config, P2PSHIP_CONF_AUTOREG_FILE));
        USER_ERROR("  -L                         log to file (auto in daemon mode)\n");
        USER_ERROR("      --log [FILE]           use [FILE] as output for file logging\n");
	USER_ERROR("                             (%s)\n", 
		   processor_config_string(config, P2PSHIP_CONF_LOG_FILE));
        USER_ERROR("      --threads=THREADS      set the number of worker threads (%d)\n", 
		   processor_config_int(config, P2PSHIP_CONF_WORKER_THREADS));
	USER_ERROR("      --help                 print help\n");
#ifdef CONFIG_SIP_ENABLED
	USER_ERROR("      --no-mp                disables the mediaproxy functionality (%s)\n", 
		   (processor_config_is_false(config,  P2PSHIP_CONF_SIPP_MEDIA_PROXY)? "on":"off"));
	USER_ERROR("      --tunnel-mp            forces tunnelled proxy mode (%s)\n", 
		   (processor_config_is_true(config, P2PSHIP_CONF_SIPP_TUNNEL_PROXY)? "on":"off"));
	USER_ERROR("      --force-mp             forces media proxy for ipv4 (%s)\n", 
		   (processor_config_is_true(config, P2PSHIP_CONF_SIPP_FORCE_PROXY)? "on":"off"));
        USER_ERROR("      --allow-unknown        allow unknown identities to register (%s)\n", 
		   (processor_config_is_true(config, P2PSHIP_CONF_IDENT_ALLOW_UNKNOWN_REGISTRATIONS)? "yes":"no"));
        USER_ERROR("      --proxy-iface          a list of interfaces to listen to for the proxy (%s)\n",
		   processor_config_string(config, P2PSHIP_CONF_SIPP_PROXY_IFACES));
        USER_ERROR("\n");
        USER_ERROR("      --allow-untrusted      allow untrusted peers to connect (%s)\n", 
		   (processor_config_is_true(config, P2PSHIP_CONF_IDENT_ALLOW_UNTRUSTED)? "yes":"no"));
#endif
	USER_ERROR("      --list-ca              list all trusted CA's\n");
        USER_ERROR("      --import-ca [file]     import a new ca\n");
        USER_ERROR("      --remove-ca [ca name]  remove the given trusted CA\n");
        USER_ERROR("      --list                 list all my identities\n");
        USER_ERROR("      --import [file]        import a new identity\n");
        USER_ERROR("      --remove [sip aor]     remove the identity\n");
        USER_ERROR("      --idents [file]        use [file] for identities\n");
	USER_ERROR("                             (%s)\n",
		   processor_config_string(config, P2PSHIP_CONF_IDENTS_FILE));
        USER_ERROR("\n");
#ifdef CONFIG_OPENDHT_ENABLED
        USER_ERROR("      --opendht [host:port]  use [host:port] as the opendht proxy\n");
	USER_ERROR("                             (%s)\n", 
		   processor_config_string(config, P2PSHIP_CONF_OPENDHT_PROXY));
        USER_ERROR("\n");
#endif
#ifdef CONFIG_BROADCAST_ENABLED
        USER_ERROR("      --bc-addr [addr:port]  use [host:port] as the broadcast. Either \n");
	USER_ERROR("                             host or port can be omitted in case\n");
 	USER_ERROR("                             address %s will be used.\n",
 		   processor_config_string(config, P2PSHIP_CONF_BC_ADDR));
        USER_ERROR("\n");
#endif
#ifdef CONFIG_WEBCONF_ENABLED
        USER_ERROR("      --webconf [addr:port]  use [host:port] as the webconf interface\n");
        USER_ERROR("                             (%s)\n",
		   processor_config_string(config, P2PSHIP_CONF_WEBCONF_SS));
#endif
#ifdef CONFIG_HIP_ENABLED
        USER_ERROR("      --list-hits            display the available hits & exit\n");
	USER_ERROR("      --rvs hit,ip;hit2,ip2  register to the specified RVS's\n");
	if (processor_config_string(config, P2PSHIP_CONF_RVS)) {
		USER_ERROR("                             (%s)\n", 
			   processor_config_string(config, P2PSHIP_CONF_RVS));
	}
        USER_ERROR("\n");
#endif
#ifdef CONFIG_PYTHON_ENABLED
	USER_ERROR("      --shell                Starts a new Python shell on stdin\n");
	USER_ERROR("      --console              Usees only console-UI\n");
	USER_ERROR("      --run [file]           Runs the given script in a Python environment\n");
#endif
        USER_ERROR("Bug reports to %s\n", PACKAGE_BUGREPORT);

	processor_config_free(config);
}
Exemplo n.º 4
0
/* point-of-entry */
int 
main(int argc, char **argv)
{
	int ret = -1, c, index, action = ACTION_NONE, tmp;
	char *action_param = NULL;
        processor_config_t *config = 0, *config2 = 0;
	char *conf_file = 0;
	int load_autoreg = 0;
	int flag_quiet = 0;
	int log_to_file = 0;
	int console_only = 0;
	int do_test = 0; // do whatever the test of the day is

	xmlInitParser();
	xmlInitThreads();
	//initGenericErrorDefaultFunc((xmlGenericErrorFunc *)xml_error_func);

        /* the getopt values */
        static struct option long_options[] =
                {                        
                        {"verbose", no_argument, 0, 0},
                        {"iface", required_argument, 0, 0},
                        {"threads", required_argument, 0, 0},
                        {"help", no_argument, 0, 0},
                        {"version", no_argument, 0, 0},
                        {"console", no_argument, 0, 0},
#ifdef CONFIG_PYTHON_ENABLED
                        {"shell", no_argument, 0, 0},
                        {"run", required_argument, 0, 0},
                        {"no-scripts", no_argument, 0, 0},
#endif
#ifdef CONFIG_SIP_ENABLED
                        {"proxy-iface", required_argument, 0, 0},
                        {"no-mp", no_argument, 0, 0},
                        {"tunnel-mp", no_argument, 0, 0},
                        {"force-mp", no_argument, 0, 0},
                        {"allow-unknown", no_argument, 0, 0},
                        {"allow-untrusted", no_argument, 0, 0},
#endif
                        {"list-ca", no_argument, 0, 0},
                        {"import-ca", required_argument, 0, 0},
                        {"remove-ca", required_argument, 0, 0},
                        {"list", no_argument, 0, 0},
                        {"import", required_argument, 0, 0},
                        {"remove", required_argument, 0, 0},
                        {"idents", required_argument, 0, 0},
                        {"log", required_argument, 0, 0},
#ifdef CONFIG_BROADCAST_ENABLED
                        {"bc-addr", required_argument, 0, 0},
#endif
#ifdef CONFIG_WEBCONF_ENABLED
                        {"webconf", required_argument, 0, 0},
#endif
#ifdef CONFIG_OPENDHT_ENABLED
                        {"opendht", required_argument, 0, 0},
#endif
#ifdef CONFIG_HIP_ENABLED
                        {"list-hits", no_argument, 0, 0},
                        {"rvs", required_argument, 0, 0},
                        {"provide-rvs", no_argument, 0, 0},
#endif
                        {0, 0, 0, 0}
                };        

#ifdef LOCK_DEBUG
	debug2_init();
#endif
#ifdef REF_DEBUG2
	ship_debug_initref();
#endif


	if (!(config = processor_config_new()) || !(config2 = processor_config_new())) {
                USER_ERROR("Error loading application\n");
		goto err;
	}

	if (processor_config_load_defaults(config2)) {
                USER_ERROR("Error loading default configurations\n");
                goto err;
	}
	processor_config_get_string(config2, P2PSHIP_CONF_CONF_FILE, &conf_file);

        opterr = 0;
        while ((c = getopt_long(argc, argv, "LqvhDVs:c:p:i:Rr:kKt", long_options, &index)) != -1) {
                
                if (!c) {
                        if (!strcmp(long_options[index].name, "threads")) {
				processor_config_set_int(config, P2PSHIP_CONF_WORKER_THREADS, atoi(optarg));
                        } else if (!strcmp(long_options[index].name, "help")) {
                                c = '?';
                        } else if (!strcmp(long_options[index].name, "version")) {
                                c = 'V';
                        } else if (!strcmp(long_options[index].name, "verbose")) {
                                c = 'v';
                        } else if (!strcmp(long_options[index].name, "iface")) {
                                c = 'i';
                        } else if (!strcmp(long_options[index].name, "console")) {
				console_only = 1;
#ifdef CONFIG_PYTHON_ENABLED
                        } else if (!strcmp(long_options[index].name, "shell")) {
				processor_config_set_true(config, P2PSHIP_CONF_START_SHELL);
                        } else if (!strcmp(long_options[index].name, "run")) {
				processor_config_set_string(config, P2PSHIP_CONF_RUN_SCRIPT, optarg);
                        } else if (!strcmp(long_options[index].name, "no-scripts")) {
				processor_config_set_false(config, P2PSHIP_CONF_STARTUP_SCRIPTS);
#endif
#ifdef CONFIG_SIP_ENABLED
                        } else if (!strcmp(long_options[index].name, "proxy-iface")) {
				processor_config_set_string(config, P2PSHIP_CONF_SIPP_PROXY_IFACES, optarg);
                        } else if (!strcmp(long_options[index].name, "no-mp")) {
				processor_config_set_string(config, P2PSHIP_CONF_SIPP_MEDIA_PROXY, "no");
                        } else if (!strcmp(long_options[index].name, "tunnel-mp")) {
				processor_config_set_string(config, P2PSHIP_CONF_SIPP_TUNNEL_PROXY, "yes");
                        } else if (!strcmp(long_options[index].name, "force-mp")) {
				processor_config_set_string(config, P2PSHIP_CONF_SIPP_FORCE_PROXY, "yes");
                        } else if (!strcmp(long_options[index].name, "allow-unknown")) {
				processor_config_set_string(config, P2PSHIP_CONF_IDENT_ALLOW_UNKNOWN_REGISTRATIONS, "yes");
                        } else if (!strcmp(long_options[index].name, "allow-untrusted")) {
				processor_config_set_string(config, P2PSHIP_CONF_IDENT_ALLOW_UNTRUSTED, "yes");
#endif
                        } else if (!action && !strcmp(long_options[index].name, "list-ca")) {
				action = ACTION_LIST_CA;
                        } else if (!action && !strcmp(long_options[index].name, "remove-ca")) {
				action = ACTION_REMOVE_CA;
				if (!action_param) action_param = strdup(optarg);
                        } else if (!action && !strcmp(long_options[index].name, "import-ca")) {
				action = ACTION_IMPORT_CA;
				if (!action_param) action_param = strdup(optarg);
			} else if (!action && !strcmp(long_options[index].name, "list")) {
				action = ACTION_LIST;
                        } else if (!action && !strcmp(long_options[index].name, "remove")) {
				action = ACTION_REMOVE;
				if (!action_param) action_param = strdup(optarg);
                        } else if (!action && !strcmp(long_options[index].name, "import")) {
				action = ACTION_IMPORT;
				if (!action_param) action_param = strdup(optarg);
                        } else if (!strcmp(long_options[index].name, "idents")) {
				processor_config_set_string(config, P2PSHIP_CONF_IDENTS_FILE, optarg);
                        } else if (!strcmp(long_options[index].name, "log")) {
				processor_config_set_string(config, P2PSHIP_CONF_LOG_FILE, optarg);
#ifdef CONFIG_BROADCAST_ENABLED
                        } else if (!strcmp(long_options[index].name, "bc-addr")) {
				processor_config_set_string(config, P2PSHIP_CONF_BC_ADDR, optarg);
#endif
#ifdef CONFIG_OPENDHT_ENABLED
                        } else if (!strcmp(long_options[index].name, "opendht")) {
				processor_config_set_string(config, P2PSHIP_CONF_OPENDHT_PROXY, optarg);
#endif
#ifdef CONFIG_HIP_ENABLED
                        } else if (!strcmp(long_options[index].name, "list-hits")) {
				action = ACTION_LIST_HITS;
                        } else if (!strcmp(long_options[index].name, "rvs")) {
				processor_config_set_string(config, P2PSHIP_CONF_RVS, optarg);
                        } else if (!strcmp(long_options[index].name, "provide-rvs")) {
				processor_config_set_string(config, P2PSHIP_CONF_PROVIDE_RVS, "yes");
#endif
#ifdef CONFIG_WEBCONF_ENABLED
                        } else if (!strcmp(long_options[index].name, "webconf")) {
				processor_config_set_string(config, P2PSHIP_CONF_WEBCONF_SS, optarg);
#endif
			} else {
				c  = '?';
			}
		}

                switch (c) {    
                case 0:
                        /* already processed */
                        break;
                case 'v':
                        if (p2pship_log_level > -1)
                                p2pship_log_level++;
                        break;
                case 'q':
                        flag_quiet = 1;
                        p2pship_log_level = -1;
                        break;
                case 'D':
			log_to_file = 1;
			processor_config_set_string(config, P2PSHIP_CONF_DAEMON, "yes");
                        break;
                case 'c':
                        conf_file = optarg;
			processor_config_set_string(config, P2PSHIP_CONF_CONF_FILE, conf_file);
                        break;
                case 'i':
			processor_config_set_string(config, P2PSHIP_CONF_IFACES, optarg);
                        break;
#ifdef CONFIG_SIP_ENABLED
                case 'p':
                        if (sscanf(optarg, "%u", &tmp) != 1) {
                                USER_ERROR("Invalid port %s\n", optarg);
                                return 1;
                        } else {
				processor_config_set_int(config, P2PSHIP_CONF_SIPP_PROXY_PORT, tmp);
			}
                        break;
#endif
                case 's':
                        if (sscanf(optarg, "%u", &tmp) != 1) {
                                USER_ERROR("Invalid port %s\n", optarg);
                                return 1;
                        } else {
				processor_config_set_int(config, P2PSHIP_CONF_SHIP_PORT, tmp);
			}
                        break;
                case 'V':
                        print_version();
                        return 0;
		case 'R':
			load_autoreg = 1;
			break;
		case 'r':
			processor_config_set_string(config, P2PSHIP_CONF_AUTOREG_FILE, optarg);
			break;
		case 'L':
			log_to_file = 1;
			break;
                case 'k':
			processor_kill_existing_pid();
			break;
                case 'K':
			processor_kill_all_existing();
			break;
                case 't':
			do_test = 1;
			break;
                case 'h':
                case '?':
                default:
                        print_version();
                        print_usage();
                        return 1;
                }
        }
        
        if (!flag_quiet)
                print_version();
     
        /* 1. load the defaults (done already), 2. load the conf file, 3. put on the manual overrides */
	/* ensure that we have a config file! */
	if (ship_ensure_file(conf_file, "# Autocreated\n\n") || 
	    processor_config_load(config2, conf_file)) {
		USER_ERROR("Error processing config file %s\n", conf_file);
		goto err;
	}
        
        if (processor_config_transfer(config2, config)) {
                USER_ERROR("Error processing configs\n");
                goto err;
        }

	/* transfer */
	processor_config_free(config);
	config = config2;
	config2 = NULL;

	/* ok, ready to rock! */
	processor_config_ensure_configs(config);
	if (log_to_file) {
		p2pship_log_file = processor_config_string(config, P2PSHIP_CONF_LOG_FILE);
	}

#ifdef CONFIG_START_GLIB_MAIN_LOOP
	if (!g_thread_supported())
		g_thread_init(NULL);
#endif
#ifdef CONFIG_START_GTK
	gdk_threads_init();
	gdk_threads_enter();
	gtk_init(&argc, &argv);
#endif

#ifdef CALL_DEBUG
	calldebug_init();
#endif
	/* mark starttime for uptime calcs */
	time(&p2pship_start);

	/* register each modules */
	ASSERT_ZERO(processor_init(config), err);
#ifdef CONFIG_HIP_ENABLED
	hipapi_register();
#endif
#ifdef CONFIG_SIP_ENABLED
	sipp_register();
#endif
	ident_addr_register();
	ident_register();
#ifdef CONFIG_WEBCONF_ENABLED
	webconf_register();
#endif
#ifdef CONFIG_EXTAPI_ENABLED
	extapi_register();
#endif
#ifdef CONFIG_WEBCACHE_ENABLED
	webcache_register();
#endif
	resourceman_register();
	olclient_register();
	conn_register();
	netio_register();
	netio_events_register();
	netio_ff_register();
	netio_man_register();
	netio_http_register();
	ui_register();
	ui_stdin_register();
	processor_init_module("ui_stdin", config);
	
#ifdef CONFIG_DBUS_ENABLED
	dbus_register();
#endif

	if (!console_only) {
#ifdef CONFIG_GTKUI_ENABLED
		ui_gtk_register();
		processor_init_module("ui_gtk", config);
#endif
	}
	addrbook_register();
#ifdef CONFIG_PYTHON_ENABLED
	pymod_register();	
#endif

#ifdef CONFIG_MEDIA_ENABLED
	media_register();
#endif
	/* check what we actually should do */
	switch (action) {
	case ACTION_LIST_CA: { /* list ca */
		if (processor_init_module("ident", config)) {
			USER_ERROR("Error initializing system\n");
		} else {
			ident_data_print_cas(ident_get_cas());
		}
		break;
	}

	case ACTION_REMOVE_CA: { /* remove ca */
		if (processor_init_module("ident", config)) {
			USER_ERROR("Error initializing system\n");
		} else {
			ident_remove_ca(action_param);
		}
		break;
	}

	case ACTION_LIST: { /* list */
		if (processor_init_module("ident", config)) {
			USER_ERROR("Error initializing system\n");
		} else {
			ident_data_print_idents(ident_get_identities());
		}
		break;
	}

	case ACTION_REMOVE: { /* remove */
		if (processor_init_module("ident", config)) {
			USER_ERROR("Error initializing system\n");
		} else {
			ident_remove_ident(action_param);
		}
		break;
	}

	case ACTION_IMPORT:  /* import */
	case ACTION_IMPORT_CA: { /* import ca */
		if (processor_init_module("ident", config)) {
			USER_ERROR("Error initializing system\n");
		} else {
			if (ident_import_file(action_param, 1)) {
				USER_ERROR("Error loading processing file %s\n", action_param);
			}
		}
		break;
	}
		
#ifdef CONFIG_HIP_ENABLED
	case ACTION_LIST_HITS: {
		if (processor_init_module("hipapi", config)) {
			USER_ERROR("Error initializing system\n");
		} else {
			hipapi_list_hits();
		}
		break;
	}
#endif
	case ACTION_NONE:
	default: {
		struct rlimit rl;
		int result;
		
#ifdef CONFIG_PYTHON_ENABLED
		if (processor_config_is_true(config, P2PSHIP_CONF_START_SHELL))
			processor_config_set_false(config, P2PSHIP_CONF_DAEMON);
#endif
		/* go daemon (..whee!) */
		if (processor_config_is_true(config, P2PSHIP_CONF_DAEMON)) {
			if (fork())
				goto err;			
		}
		
		/* check the stack size */
		if (!(result = getrlimit(RLIMIT_STACK, &rl))) {
			const rlim_t stacksize = 32L * 1024L * 1024L;
			if (rl.rlim_cur < stacksize) {
				LOG_INFO("increasing stack size to %d\n", stacksize);
				rl.rlim_cur = stacksize;
				if (setrlimit(RLIMIT_STACK, &rl)) {
					LOG_ERROR("could not set new stack size!\n");
				}
			}
		} else {
			LOG_ERROR("error checking stack size\n");
		}

		if (processor_init_modules(config) ||
		    (load_autoreg && ident_autoreg_load())) {
			USER_ERROR("Error initializing system\n");
		} else {
#ifdef REMOTE_DEBUG
			ship_remote_debug_init(config);
#endif
			/* start the main loop, blocks */
#ifdef REF_DEBUG2
			//			processor_tasks_add_periodic(ship_debug_reportref, 10000);
#endif

			if (do_test) {
				LOG_DEBUG("Run tests..\n");
			}

			processor_run();
		}
	}
	}
        
	ret = 0;
 err:
#ifdef REF_DEBUG2
	ship_debug_reportref();
#endif
	processor_close();
	freez(action_param);
	processor_config_free(config);
	processor_config_free(config2);

#ifdef LOCK_DEBUG
	debug2_close();
#endif
#ifdef REF_DEBUG2
	ship_debug_closeref();
#endif

	xmlCleanupThreads();
        if (!ret && !flag_quiet)
                USER_ERROR("ending ok\n");

	processor_cleanup_pid();
        return ret;
}
Exemplo n.º 5
0
static inline void 
print_version()
{
        USER_ERROR("%s version %s (%s)\n", PACKAGE_NAME, VERSION, P2PSHIP_BUILD_VERSION);
}
Exemplo n.º 6
0
PhoneFileReader::PhoneFileReader(char *phoneListFile, DataStats **data, int *numberOfPhones, int *numberOfSil)
{
  int  i = 0;
  int  state = 0;
  char str[MAXSTR];
  int  phoneNum = 0;
  
  printf("Reading phones...\n");
  FILE *inFile = fopen(phoneListFile,"rt");
  while(!feof(inFile))
  {          
          char *resChar = fgets(str,MAXSTR,inFile);
          assert(resChar != NULL);
          switch(state)
          {
            case 0:        
              if(strncmp(str,"Number of phones:",17) == 0)
              {
                *numberOfPhones = atoi(&(str[18]));
                if(*numberOfPhones >= 1)
                {                
                  (*data) = new DataStats[*numberOfPhones];
                } 
                else
                {
                  USER_ERROR("The phonelist file is corrupt. Number of phones is smaller than one!");
                }            
                state++;
              }
              else
              {
                USER_ERROR("The phonelist file is corrupt! First line shout be: 'Number of phones: [number]'");
              }
              break;
            case 1:
              if(strncmp(str,"Number of SIL's: ",17) == 0)
              {
                *numberOfSil = atoi(&(str[18]));
                if(*numberOfSil < 1)
                {                
                  USER_ERROR("The phonelist file is corrupt. Number of SIL phones is smaller than one!");
                }            
                state++;
              }
              else
              {
                USER_ERROR("The phonelist file is corrupt! Second line shout be: 'Number of SIL's: [number]'");
              }
              break;
            case 2:
              if(phoneNum < *numberOfPhones)
              {            
                if(strlen(str) > 9)
                {
                  USER_ERROR("Sorry, the length of a phone name may not exceed 9.");
                }
                i=0;
                while(i<10)
                {
                  if(str[i] == '\r' || str[i] == ' ' || str[i] == '\t' || str[i] == '\n' || str[i] == 0)
                  {
                    while(i<10)
                    {
                      str[i] = ' '; 
                      i++;                     
                    }
                  } 
                  i++;
                }       
                str[10] = 0;
                strncpy((*data)[phoneNum].name,str,11);
                phoneNum++;
              }
              break;
            default:
              USER_ERROR("The phonelist file is corrupt!");
              break;
          }
  }
  fclose(inFile);    
}
Exemplo n.º 7
0
/* loads up all the contacts we already have imported */
int
addrbook_load_imported(ship_list_t *list)
{
	int ret = -1;
	struct stat sdata;
	FILE *f = 0;
	
	if (stat(contacts_file, &sdata)) {
		LOG_WARN("Contacts log file %s does not exist\n", contacts_file);
		return -2;
	}
		
	/* load file .. */
	ship_lock(addrbook_lock);
	f = fopen(contacts_file, "r");
	if (f) {
		char *buf = NULL;
		size_t len = 0;
		ssize_t got = 0;
		while ((got = getline(&buf, &len, f)) > -1) {
			/* check what we've got.. */
			buf = trim(buf);
			switch (*buf) {
			case '#':
			case ';':
			case '/':
			case 0:
				/* skip empty / comments */
				break;
			default: {
				char **tokens = 0;
				int toklen = 0;
				int ct = 0;
				if (!ship_tokenize(buf, strlen(buf), &tokens, &toklen, ',')) {
					contact_t *c = ident_contact_new();
					if (c && toklen > 3) {
						ship_urldecode(tokens[0]);
						ship_urldecode(tokens[1]);
						ship_urldecode(tokens[2]);

						ASSERT_TRUE(c->sip_aor = strdup(tokens[0]), cerr);
						ASSERT_TRUE(c->name = strdup(tokens[1]), cerr);
						ASSERT_TRUE(c->db_id = strdup(tokens[2]), cerr);
						c->added = atoi(tokens[3]);

						/* todo: load the optional stuff */
						for (ct = 4; ct < toklen; ct++) {
							char *p = strchr(tokens[ct], '=');
							if (p) {
								p[0] = 0;
								p++;

								ship_urldecode(tokens[ct]);
								ship_urldecode(p);
								
								ship_ht_put_string(c->params, tokens[ct], strdup(p));
							}
						}

						LOG_DEBUG("Loaded %s <%s>\n", c->name, c->sip_aor);
						ship_list_add(list, c);
						c = 0;
					}
				cerr:
					ship_tokens_free(tokens, toklen);
					ident_contact_free(c);
				}
			} break;
			}
		}
		fclose(f);
		freez(buf);
		ret = 0;
	} else {
		USER_ERROR("Failed to open contacts file %s\n", contacts_file);
	}
	
	LOG_DEBUG("Loaded %d entries\n", ship_list_length(list));
	ship_unlock(addrbook_lock);
	return ret;
}