Exemplo n.º 1
0
int main(int argc, char **argv) {
    void *mod_routing = NULL;
    char *conffile = NULL;
    FILE *file = NULL;
    int nofork = 1;
    char str[100];
    int c = 0;
    char b_log  = 1;
    char b_fork = 1;
    memset(&str, 0, 100*sizeof(char));
    log_init("logFile",NULL);
    log2display(LOG_ALERT);

    p_threadpool = threadpool_create(5, 8096, 0);

    init_maps();
    init_call_id(NULL);

    while((c=getopt(argc, argv, "c:vP:fhD:"))!=-1) {
        switch(c) {
        case 'c':
            conffile = optarg;
            break;
        case 'v':
            printf("sip2smpp version: %s\n", VERSION);
            exit(0);
            break;
        case 'P':
            pid_file = optarg;
            break;
        case 'f':
            nofork = 0;
            b_fork = 0;
            break;
        case 'h':
            usage(0);
            break;
        case 'D':
        {
            char log = atoi(optarg);
            if(log >= 0 && log <= 8) {
                log2display((Loglevel)log);
                b_log = 0;
            }
            break;
        }
        default:
            abort();
        }
    }

    if(!conffile) {
        conffile = (char*)malloc(sizeof(char)*strlen(DEFAULT_CONFIG)+1);
        strcpy(conffile,DEFAULT_CONFIG);
    }

    if((file = fopen(conffile,"r")) != NULL) {
        fclose(file);
    } else {
        ERROR(LOG_FILE | LOG_SCREEN,"The INI file isn't found!");
        handler(-1);
    }

    if(load_config_file((uint8_t*)conffile, CONFIG_ALL, NULL) == -1) {
        ERROR(LOG_FILE | LOG_SCREEN,"There are errors in the INI file!");
        free_config_file(CONFIG_ALL, NULL);
        handler(-1);
    }

    if(b_log) {
        log2display((Loglevel)cfg_main->log_level);
    }

    if(b_fork) {
        nofork = !cfg_main->fork;
    }

    if(daemonize(nofork) != 0) {
        ERROR(LOG_FILE | LOG_SCREEN,"Daemoniize failed");
        exit(-1);
    }

    //Load routing module
    void* functions[2] = { send_sms_to_smpp, send_sms_to_sip };
    void* cfgs[2] = { cfg_smpp, cfg_sip };
    if(cfg_main->routing_module) {
        mod_routing = dlopen(cfg_main->routing_module, RTLD_NOW | RTLD_GLOBAL);
        if(!mod_routing) {
            ERROR(LOG_SCREEN | LOG_FILE, "%s", dlerror());
            handler(-1);
        }
        f_start_routing = dlsym(mod_routing, "start_routing");
        f_routing       = dlsym(mod_routing, "routing");
        f_close_routing = dlsym(mod_routing, "close_routing");
    } else {
        f_start_routing = default_start_routing;
        f_routing       = default_routing;
        f_close_routing = default_close_routing;
    }

    if(db_init() == -1) {
        ERROR(LOG_FILE | LOG_SCREEN,"There are errors when the DB connection!");
        handler(-1);
    } else {
        //TODO: send sms saved in db
    }

    if(f_start_routing(functions, cfgs) != 0) {
        ERROR(LOG_FILE | LOG_SCREEN, "Routing loading failed");
        handler(-1);
    }

    if(cfg_main && cfg_main->launch_msg) {
        printf("\033[0;36m%s\033[0m\n", cfg_main->launch_msg);
    }

    printf("SIP 2 SMPP Version  [%s]\n", VERSION);
    printf("Pid file            [%s]\n", pid_file);
    printf("Config File         [%s]\n", conffile);

    display_config_file(CONFIG_ALL, NULL);

    start_all_threads_interfaces();

    join_all_threads();

    threadpool_destroy(p_threadpool, threadpool_graceful);

    f_close_routing();

    if(cfg_main->routing_module) {
        dlclose(mod_routing);
    }

    free_config_file(CONFIG_ALL, NULL);

    handler(0);

    return 0;
}
Exemplo n.º 2
0
void load_config(){
    struct stat info;
    char cur_extra_section[PATHMAX];
    struct config_handle my_conf_handle;
    int i_tmp;
    long l_tmp;
    //Check if config file exists
    if (stat(CRASHLOG_CONF_PATH, &info) == 0) {
        LOGI("Loading specific crashlog config\n");

        my_conf_handle.first=NULL;
        my_conf_handle.current=NULL;
        if (init_config_file(CRASHLOG_CONF_PATH, &my_conf_handle)>=0){
            //General config - uptime
            //TO IMPROVE : general config strategy to define properly
            if (sk_exists(GENERAL_CONF_PATTERN,"uptime_frequency",&my_conf_handle)){
                char *tmp = get_value(GENERAL_CONF_PATTERN,"uptime_frequency",&my_conf_handle);
                if (tmp){
                    i_tmp = atoi(tmp);
                    if (i_tmp > 0){
                        gcurrent_uptime_hour_frequency = i_tmp;
                    }
                }
            }
            if (sk_exists(GENERAL_CONF_PATTERN,"sd_size_limit",&my_conf_handle)){
                char *tmp = get_value(GENERAL_CONF_PATTERN,"sd_size_limit",&my_conf_handle);
                if (tmp){
                    l_tmp = atol(tmp);
                    if (l_tmp > 0){
                        current_sd_size_limit = l_tmp;
                    }
                }
            }
            if (sk_exists(GENERAL_CONF_PATTERN,"serial_device_id",&my_conf_handle)){
                char *tmp = get_value(GENERAL_CONF_PATTERN,"serial_device_id",&my_conf_handle);
                if (tmp){
                    i_tmp = atoi(tmp);
                    if (i_tmp > 0){
                        g_current_serial_device_id = 1;
                    }
                }
            }
            if (sk_exists(GENERAL_CONF_PATTERN,"check_modem_version",&my_conf_handle)){
                char *tmp = get_value(GENERAL_CONF_PATTERN,"check_modem_version",&my_conf_handle);
                if (tmp){
                    i_tmp = atoi(tmp);
                    if (i_tmp > 0){
                        check_modem_version = 1;
                    } else {
                        check_modem_version = 0;
                    }
                    LOGI("Check modem version: %d", check_modem_version);
                }
            }
            load_config_by_pattern(NOTIFY_CONF_PATTERN,"matching_pattern",my_conf_handle);
            //ADD other config pattern HERE
            free_config_file(&my_conf_handle);
        }else{
            LOGI("specific crashlog config not found\n");
        }
    }
}