Esempio n. 1
0
int drv_generic_i2c_open(const char *section, const char *driver)
{
    int dev;
    char *bus, *device;
    udelay_init();
    Section = (char *) section;
    Driver = (char *) driver;
    bus = cfg_get(Section, "Port", NULL);
    device = cfg_get(Section, "Device", NULL);
    dev = atoi(device);
    info("%s: initializing I2C bus %s", Driver, bus);
    if ((i2c_device = open(bus, O_WRONLY)) < 0) {
	error("%s: I2C bus %s open failed !\n", Driver, bus);
	goto exit_error;
    }
    info("%s: selecting slave device 0x%x", Driver, dev);
    if (ioctl(i2c_device, I2C_SLAVE, dev) < 0) {
	error("%s: error selecting slave device 0x%x\n", Driver, dev);
	goto exit_error;
    }

    info("%s: initializing I2C slave device 0x%x", Driver, dev);
    if (i2c_smbus_write_quick(i2c_device, I2C_SMBUS_WRITE) < 0) {
	error("%s: error initializing device 0x%x\n", Driver, dev);
	close(i2c_device);
    }

    return 0;

  exit_error:
    free(bus);
    free(device);
    close(i2c_device);
    return -1;
}
Esempio n. 2
0
/*
 * Load all configuration directives that are common for all database
 * types that use the 'dlr-db' group to define which attributes are 
 * used in the table
 */
struct dlr_db_fields *dlr_db_fields_create(CfgGroup *grp)
{
    struct dlr_db_fields *ret = NULL;

    ret = gw_malloc(sizeof(*ret));
    gw_assert(ret != NULL);
    memset(ret, 0, sizeof(*ret));

    if (!(ret->table = cfg_get(grp, octstr_imm("table"))))
   	    panic(0, "DLR: DB: directive 'table' is not specified!");
    if (!(ret->field_smsc = cfg_get(grp, octstr_imm("field-smsc"))))
   	    panic(0, "DLR: DB: directive 'field-smsc' is not specified!");
    if (!(ret->field_ts = cfg_get(grp, octstr_imm("field-timestamp"))))
        panic(0, "DLR: DB: directive 'field-timestamp' is not specified!");
    if (!(ret->field_src = cfg_get(grp, octstr_imm("field-source"))))
   	    panic(0, "DLR: DB: directive 'field-source' is not specified!");
    if (!(ret->field_dst = cfg_get(grp, octstr_imm("field-destination"))))
   	    panic(0, "DLR: DB: directive 'field-destination' is not specified!");
    if (!(ret->field_serv = cfg_get(grp, octstr_imm("field-service"))))
   	    panic(0, "DLR: DB: directive 'field-service' is not specified!");
    if (!(ret->field_url = cfg_get(grp, octstr_imm("field-url"))))
   	    panic(0, "DLR: DB: directive 'field-url' is not specified!");
    if (!(ret->field_mask = cfg_get(grp, octstr_imm("field-mask"))))
        panic(0, "DLR: DB: directive 'field-mask' is not specified!");
    if (!(ret->field_status = cfg_get(grp, octstr_imm("field-status"))))
   	    panic(0, "DLR: DB: directive 'field-status' is not specified!");
    if (!(ret->field_boxc = cfg_get(grp, octstr_imm("field-boxc-id"))))
   	    panic(0, "DLR: DB: directive 'field-boxc-id' is not specified!");

    return ret;
}
Esempio n. 3
0
static int blst_add_f(struct sip_msg* msg, char* to, char* foo)
{
#ifdef USE_DST_BLACKLIST
	int t;
	struct dest_info src;
	
	if (likely(cfg_get(core, core_cfg, use_dst_blacklist))){
		t=0;
		if (unlikely( to && (get_int_fparam(&t, msg, (fparam_t*)to)<0)))
			return -1;
		if (t==0)
			t=cfg_get(core, core_cfg, blst_timeout);
		init_dest_info(&src);
		src.send_sock=0;
		src.to=msg->rcv.src_su;
		src.id=msg->rcv.proto_reserved1;
		src.proto=msg->rcv.proto;
		dst_blacklist_force_add_to(BLST_ADM_PROHIBITED, &src, msg,
									S_TO_TICKS(t));
		return 1;
	}else{
		LOG(L_WARN, "WARNING: blst: blst_add: blacklist support disabled\n");
	}
#else /* USE_DST_BLACKLIST */
	LOG(L_WARN, "WARNING: blst: blst_add: blacklist support not compiled-in"
			" - no effect -\n");
#endif /* USE_DST_BLACKLIST */
	return 1;
}
Esempio n. 4
0
/*
 * Add reroute information to the connection data. Where the priority
 * is in the order: reroute, reroute-smsc-id, reroute-receiver.
 */
static void init_reroute(SMSCConn *conn, CfgGroup *grp)
{
    Octstr *rule;
    long i;

    if (cfg_get_bool(&conn->reroute_dlr, grp, octstr_imm("reroute-dlr")) == -1)
        conn->reroute_dlr = 0;
    info(0, "DLR rerouting for smsc id <%s> %s.", octstr_get_cstr(conn->id), (conn->reroute_dlr?"enabled":"disabled"));

    if (cfg_get_bool(&conn->reroute, grp, octstr_imm("reroute")) != -1) {
        debug("smscconn",0,"Adding general internal routing for smsc id <%s>",
              octstr_get_cstr(conn->id));
        return;
    }

    if ((conn->reroute_to_smsc = cfg_get(grp, octstr_imm("reroute-smsc-id"))) != NULL) {
        /* reroute all messages to a specific smsc-id */
        debug("smscconn",0,"Adding internal routing: smsc id <%s> to smsc id <%s>",
              octstr_get_cstr(conn->id), octstr_get_cstr(conn->reroute_to_smsc));
        return;
    }

    if ((rule = cfg_get(grp, octstr_imm("reroute-receiver"))) != NULL) {
        List *routes;

        /* create hash disctionary for this smsc-id */
        conn->reroute_by_receiver = dict_create(100, (void(*)(void *)) octstr_destroy);

        routes = octstr_split(rule, octstr_imm(";"));
        for (i = 0; i < list_len(routes); i++) {
            Octstr *item = list_get(routes, i);
            Octstr *smsc, *receiver;
            List *receivers;

            /* first word is the smsc-id, all other are the receivers */
            receivers = octstr_split(item, octstr_imm(","));
            smsc = list_extract_first(receivers);
            if (smsc)
                octstr_strip_blanks(smsc);

            while((receiver = list_extract_first(receivers))) {
                octstr_strip_blanks(receiver);
                debug("smscconn",0,"Adding internal routing for smsc id <%s>: "
                      "receiver <%s> to smsc id <%s>",
                      octstr_get_cstr(conn->id), octstr_get_cstr(receiver),
                      octstr_get_cstr(smsc));
                if (!dict_put_once(conn->reroute_by_receiver, receiver, octstr_duplicate(smsc)))
                    panic(0, "Could not set internal routing for smsc id <%s>: "
                          "receiver <%s> to smsc id <%s>, because receiver has already routing entry!",
                          octstr_get_cstr(conn->id), octstr_get_cstr(receiver),
                          octstr_get_cstr(smsc));
                octstr_destroy(receiver);
            }
            octstr_destroy(smsc);
            list_destroy(receivers, octstr_destroy_item);
        }
        octstr_destroy(rule);
        list_destroy(routes, octstr_destroy_item);
    }
}
Esempio n. 5
0
static void sr_ssl_ctx_info_callback(const SSL *ssl, int event, int ret)
{
	struct tls_extra_data* data = 0;
	int tls_dbg;

	if (event & SSL_CB_HANDSHAKE_START) {
		tls_dbg = cfg_get(tls, tls_cfg, debug);
		LOG(tls_dbg, "SSL handshake started\n");
		if(data==0)
			data = (struct tls_extra_data*)SSL_get_app_data(ssl);
		if(data->flags & F_TLS_CON_HANDSHAKED) {
			LOG(tls_dbg, "SSL renegotiation initiated by client\n");
			data->flags |= F_TLS_CON_RENEGOTIATION;
		}
	}
	if (event & SSL_CB_HANDSHAKE_DONE) {
		tls_dbg = cfg_get(tls, tls_cfg, debug);
		if(data==0)
			data = (struct tls_extra_data*)SSL_get_app_data(ssl);
		LOG(tls_dbg, "SSL handshake done\n");
		/* CVE-2009-3555 - disable renegotiation */
		if (ssl->s3) {
			LOG(tls_dbg, "SSL disable renegotiation\n");
			ssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
		}
		data->flags |= F_TLS_CON_HANDSHAKED;
	}
}
Esempio n. 6
0
void conn_config_ssl (CfgGroup *grp)
{
    Octstr *ssl_client_certkey_file = NULL;
    Octstr *ssl_server_cert_file    = NULL;
    Octstr *ssl_server_key_file     = NULL;
    Octstr *ssl_trusted_ca_file     = NULL;

    /*
     * check if SSL is desired for HTTP servers and then
     * load SSL client and SSL server public certificates 
     * and private keys
     */    
    ssl_client_certkey_file = cfg_get(grp, octstr_imm("ssl-client-certkey-file"));
    if (ssl_client_certkey_file != NULL) 
        use_global_client_certkey_file(ssl_client_certkey_file);
    
    ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file"));
    ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file"));
    
    if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) {
        use_global_server_certkey_file(ssl_server_cert_file, 
				       ssl_server_key_file);
    }

    ssl_trusted_ca_file = cfg_get(grp, octstr_imm("ssl-trusted-ca-file"));
    
    use_global_trusted_ca_file(ssl_trusted_ca_file);

    octstr_destroy(ssl_client_certkey_file);
    octstr_destroy(ssl_server_cert_file);
    octstr_destroy(ssl_server_key_file);
    octstr_destroy(ssl_trusted_ca_file);
}
Esempio n. 7
0
/* Dumps pkg memory status.
 * Per-child process callback that is called
 * when mem_dump_pkg cfg var is changed.
 */
void mem_dump_pkg_cb(str *gname, str *name)
{
	int	old_memlog;
	int memlog;

	if (cfg_get(core, core_cfg, mem_dump_pkg) == my_pid()) {
		/* set memlog to ALERT level to force
		printing the log messages */
		old_memlog = cfg_get(core, core_cfg, memlog);
		memlog = L_ALERT;
		/* ugly hack to temporarily switch memlog to something visible,
		 * possible race with a parallel cfg_set */
		((struct cfg_group_core*)core_cfg)->memlog=memlog;

		if (cfg_get(core, core_cfg, mem_summary) & 1) {
			LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
			pkg_status();
		}
		if (cfg_get(core, core_cfg, mem_summary) & 4) {
			LOG(memlog, "Memory still-in-use summary (pkg) of process %d:\n",
					my_pid());
			pkg_sums();
		}

		((struct cfg_group_core*)core_cfg)->memlog=old_memlog;
	}
}
Esempio n. 8
0
static void init_naptr_proto_prefs()
{
	int ignore_rfc, udp, tcp, tls, sctp;

	if ((PROTO_UDP > PROTO_LAST) || (PROTO_TCP > PROTO_LAST) ||
		(PROTO_TLS > PROTO_LAST) || (PROTO_SCTP > PROTO_LAST)){
		BUG("init_naptr_proto_prefs: array too small \n");
		return;
	}

	ignore_rfc = cfg_get(core, core_cfg, dns_naptr_ignore_rfc);
	udp = cfg_get(core, core_cfg, dns_udp_pref);
	tcp = cfg_get(core, core_cfg, dns_tcp_pref);
	tls = cfg_get(core, core_cfg, dns_tls_pref);
	sctp = cfg_get(core, core_cfg, dns_sctp_pref);

	/* Old implementation ignored the Order field in the NAPTR RR and
	 * thus violated a MUST in RFC 2915. Currently still the default. */
	if (ignore_rfc) {
		naptr_proto_pref[PROTO_UDP] = udp;
		naptr_proto_pref[PROTO_TCP] = tcp;
		naptr_proto_pref[PROTO_TLS] = tls;
		naptr_proto_pref[PROTO_SCTP] = sctp;
	} else {
		/* If value is less than 0, proto is disabled, otherwise
		 * ignored. */
		naptr_proto_pref[PROTO_UDP] = udp < 0 ? udp : 1;
		naptr_proto_pref[PROTO_TCP] = tcp < 0 ? tcp : 1;
		naptr_proto_pref[PROTO_TLS] = tls < 0 ? tls : 1;
		naptr_proto_pref[PROTO_SCTP] = sctp < 0 ? sctp : 1;
	}
}
Esempio n. 9
0
void sqlbox_configure_mysql(Cfg* cfg)
{
    CfgGroup *grp;
    Octstr *sql;

    if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox"))))
        panic(0, "SQLBOX: MySQL: group 'sqlbox' is not specified!");

    sqlbox_logtable = cfg_get(grp, octstr_imm("sql-log-table"));
    if (sqlbox_logtable == NULL) {
        panic(0, "No 'sql-log-table' not configured.");
    }
    sqlbox_insert_table = cfg_get(grp, octstr_imm("sql-insert-table"));
    if (sqlbox_insert_table == NULL) {
        panic(0, "No 'sql-insert-table' not configured.");
    }

    /* create send_sms && sent_sms tables if they do not exist */
    sql = octstr_format(SQLBOX_MYSQL_CREATE_LOG_TABLE, sqlbox_logtable);
    sql_update(sql);
    octstr_destroy(sql);
    sql = octstr_format(SQLBOX_MYSQL_CREATE_INSERT_TABLE, sqlbox_insert_table);
    sql_update(sql);
    octstr_destroy(sql);
    /* end table creation */
}
Esempio n. 10
0
/* rpc functions */
void dst_blst_mem_info(rpc_t* rpc, void* ctx)
{
	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
		rpc->fault(ctx, 500, "dst blacklist support disabled");
		return;
	}
	rpc->add(ctx, "dd",  *blst_mem_used, cfg_get(core, core_cfg, blst_max_mem));
}
Esempio n. 11
0
static void init_smpp_server_box(Cfg *cfg) {
	CfgGroup *cfg_group;
	Octstr *log_file;
	long log_level;

	log_file = NULL;
	log_level = 0;

	debug("httpClient", 0, "********** HTTP Client Box Configuration Initialization **********");

	/* initialize low level PDUs */
	if (smpp_pdu_init(cfg) == -1)
		panic(0, "Connot start with PDU init failed.");

	/*
	 * first we take the port number in bearerbox and other values from the
	 * httpClient group in configuration file
	 */

	cfg_group = cfg_get_single_group(cfg, octstr_imm("httpClient"));
	if (cfg_group == NULL)
		panic(0, "No 'httpClient' group in configuration");

	httpBoxId = cfg_get(cfg_group, octstr_imm("httpClient-id"));

	/* setup logfile stuff */
	log_file = cfg_get(cfg_group, octstr_imm("log-file"));

	cfg_get_integer(&log_level, cfg_group, octstr_imm("log-level"));

	if (log_file != NULL) {
		info(0, "Starting to log to file %s level %ld", octstr_get_cstr(log_file), log_level);
		log_open(octstr_get_cstr(log_file), log_level, GW_NON_EXCL);

	}

	if (cfg_get_integer(&timeOut, cfg_group, octstr_imm("time-out")) == -1)
		timeOut = TIMEOUT_SECONDS;

	integratorId = cfg_get(cfg_group, octstr_imm("integrator-id"));
	integratorQueueId = cfg_get(cfg_group, octstr_imm("integrator-queue-id"));

	debug("httpClient", 0, "==========Configuration Parameters============");
	debug("httpClient", 0, "===> httpClient-id:          %s ", octstr_get_cstr(httpBoxId));
	debug("httpClient", 0, "===> integrator-id:          %s ", octstr_get_cstr(integratorId));
	debug("httpClient", 0, "===> integrator-queue-id:    %s ", octstr_get_cstr(integratorQueueId));
	debug("httpClient", 0, "===> log-file:               %s ", octstr_get_cstr(log_file));
	debug("httpClient", 0, "===> log-level:              %ld", log_level);
	debug("httpClient", 0, "===> timeout:                %ld ", timeOut);
	debug("httpClient", 0, "==============================================");

	octstr_destroy(log_file);
	gw_smpp_enter(cfg);
	httpbox_status = SMPP_RUNNING;
	debug("httpClient", 0, "http_status: %d ", httpbox_status);
	debug("httpClient", 0, "********** HTTP Client Box Configuration End **********");
}
Esempio n. 12
0
/*! \brief
 *  Return an expire value in the range [ default_expires - range%, default_expires + range% ]
 */
static inline int get_expire_val(void)
{
	int expires = cfg_get(registrar, registrar_cfg, default_expires);
	int range = cfg_get(registrar, registrar_cfg, default_expires_range);
	/* if no range is given just return default_expires */
	if(range == 0) return expires;
	/* select a random value in the range */
	return expires - (float)range/100 * expires + (float)(rand()%100)/100 * 2 * (float)range/100 * expires;
}
Esempio n. 13
0
/** init tls specific data in a tcp connection.
 * Called when a new tcp connection is accepted or connected.
 * It completes the tcp connection initialisation by setting the tls
 * specific parts.
 * Note that ssl context creation and other expensive operation are left
 * out (they are delayed until the first read/write).
 * No locking is needed (when the connection is created no other process
 * can access it).
 * @param c - tcp connection.
 * @param sock - socket (unused for now).
 * @return  0 on success, < 0 on error.
 */
int tls_h_tcpconn_init(struct tcp_connection *c, int sock)
{
	c->type = PROTO_TLS;
	c->rcv.proto = PROTO_TLS;
	c->timeout = get_ticks_raw() + cfg_get(tls, tls_cfg, con_lifetime);
	c->lifetime = cfg_get(tls, tls_cfg, con_lifetime);
	c->extra_data = 0;
	return 0;
}
Esempio n. 14
0
int udp_start(Cfg *cfg)
{
    CfgGroup *grp;
    Octstr *iface;
    List *ifs;
    int allow_wtls;
    
    if (udp_running) return -1;
    
    debug("bb.udp", 0, "starting UDP sender/receiver module");

    grp = cfg_get_single_group(cfg, octstr_imm("core"));
    iface = cfg_get(grp, octstr_imm("wdp-interface-name"));
    if (iface == NULL) {
        error(0, "Missing wdp-interface-name variable, cannot start UDP");
        return -1;
    }

    allow_ip = cfg_get(grp, octstr_imm("udp-allow-ip"));
    deny_ip = cfg_get(grp, octstr_imm("udp-deny-ip"));

    /*  we'll activate WTLS as soon as we have a 'wtls' config group */
    grp = cfg_get_single_group(cfg, octstr_imm("wtls"));
    allow_wtls = grp != NULL ? 1 : 0;

    udpc_list = gwlist_create();	/* have a list of running systems */

    ifs = octstr_split(iface, octstr_imm(";"));
    octstr_destroy(iface);
    while (gwlist_len(ifs) > 0) {
        iface = gwlist_extract_first(ifs);
	info(0, "Adding interface %s", octstr_get_cstr(iface));
        add_service(9200, octstr_get_cstr(iface));   /* wsp 	*/
        add_service(9201, octstr_get_cstr(iface));   /* wsp/wtp	*/
    
#ifdef HAVE_WTLS_OPENSSL
        if (allow_wtls) {
             add_service(9202, octstr_get_cstr(iface));   /* wsp/wtls	*/
             add_service(9203, octstr_get_cstr(iface));   /* wsp/wtp/wtls */
        }
#else
        if (allow_wtls)
    	     error(0, "These is a 'wtls' group in configuration, but no WTLS support compiled in!");
#endif
    /* add_service(9204, octstr_get_cstr(interface_name));  * vcard	*/
    /* add_service(9205, octstr_get_cstr(interface_name));  * vcal	*/
    /* add_service(9206, octstr_get_cstr(interface_name));  * vcard/wtls */
    /* add_service(9207, octstr_get_cstr(interface_name));  * vcal/wtls	*/
        octstr_destroy(iface);
    }
    gwlist_destroy(ifs, NULL);
    
    gwlist_add_producer(incoming_wdp);
    udp_running = 1;
    return 0;
}
Esempio n. 15
0
static int configure_mpd(void)
{
    static int configured = 0;

    char *s;

    if (configured != 0)
	return configured;

    /* read enabled */
    if (cfg_number(Section, "enabled", 0, 0, 1, &plugin_enabled) < 1) {
	plugin_enabled = 0;
    }

    if (plugin_enabled != 1) {
	info("[MPD] WARNING: Plugin is not enabled! (set 'enabled 1' to enable this plugin)");
	configured = 1;
	return configured;
    }

    /* read server */
    s = cfg_get(Section, "server", "localhost");
    if (!s || *s == '\0') {
	info("[MPD] empty '%s.server' entry from %s, assuming 'localhost'", Section, cfg_source());
	strcpy(host, "localhost");
    } else
	strcpy(host, s);
    if (s)
	free(s);

    /* read port */
    if (cfg_number(Section, "port", 6600, 1, 65536, &iport) < 1) {
	info("[MPD] no '%s.port' entry from %s using MPD's default", Section, cfg_source());
    }

    /* read minUpdateTime in ms */
    if (cfg_number(Section, "minUpdateTime", 500, 1, 10000, &waittime) < 1) {
	info("[MPD] no '%s.minUpdateTime' entry from %s using MPD's default", Section, cfg_source());
    }


    /* read password */
    s = cfg_get(Section, "password", "");
    if (!s || *s == '\0') {
	info("[MPD] empty '%s.password' entry in %s, assuming none", Section, cfg_source());
	memset(pw, 0, sizeof(pw));
    } else
	strcpy(pw, s);
    if (s)
	free(s);

    debug("[MPD] connection detail: [%s:%d]", host, iport);
    configured = 1;
    return configured;
}
Esempio n. 16
0
/**
 * init module function
 */
static int mod_init(void)
{
	int fl;
	if (_dbg_cfgtrace_facility_str!=NULL)
	{
		fl = str2facility(_dbg_cfgtrace_facility_str);
		if (fl != -1)
		{
			_dbg_cfgtrace_facility = fl;
		} else {
			LM_ERR("invalid log facility configured");
			return -1;
		}
	}

	if(dbg_init_rpc()!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if(cfg_declare("dbg", dbg_cfg_def, &default_dbg_cfg, cfg_sizeof(dbg), &dbg_cfg))
	{
		LM_ERR("Fail to declare the configuration\n");
		return -1;
	}
	LM_DBG("cfg level_mode:%d hash_size:%d\n",
		cfg_get(dbg, dbg_cfg, mod_level_mode),
		cfg_get(dbg, dbg_cfg, mod_hash_size));

	if(dbg_init_mod_levels(cfg_get(dbg, dbg_cfg, mod_hash_size))<0)
	{
		LM_ERR("failed to init per module log level\n");
		return -1;
	}

	if(_dbg_log_assign>0)
	{
		if(dbg_init_pvcache()!=0)
		{
			LM_ERR("failed to create pvcache\n");
			return -1;
		}
	}
	if(_dbg_reset_msgid==1)
	{
		unsigned int ALL = REQUEST_CB+FAILURE_CB+ONREPLY_CB
		  +BRANCH_CB+ONSEND_CB+ERROR_CB+LOCAL_CB+EVENT_CB+BRANCH_FAILURE_CB;
		if (register_script_cb(dbg_msgid_filter, PRE_SCRIPT_CB|ALL, 0) != 0) {
			LM_ERR("could not insert callback");
			return -1;
		}
	}
	return dbg_init_bp_list();
}
Esempio n. 17
0
void init_naptr_proto_prefs()
{
	if ((PROTO_UDP > PROTO_LAST) || (PROTO_TCP > PROTO_LAST) ||
		(PROTO_TLS > PROTO_LAST) || (PROTO_SCTP > PROTO_LAST)){
		BUG("init_naptr_proto_prefs: array too small \n");
		return;
	}
	naptr_proto_pref[PROTO_UDP]=cfg_get(core, core_cfg, dns_udp_pref);
	naptr_proto_pref[PROTO_TCP]=cfg_get(core, core_cfg, dns_tcp_pref);
	naptr_proto_pref[PROTO_TLS]=cfg_get(core, core_cfg, dns_tls_pref);
	naptr_proto_pref[PROTO_SCTP]=cfg_get(core, core_cfg, dns_sctp_pref);
}
Esempio n. 18
0
void
logprint(char *fmt,...)
{
  time_t result;
  FILE *logptr;
  va_list ap;
  char *p, *sval, *ts;

  int ival;
  double dval;

  result = time(NULL);
  logptr = fopen(cfg_get("logfile"), "a");
  
  if(logptr == NULL) {
    fprintf(stderr, "Could not open log file %s for writing\n", cfg_get("logfile"));
    return;
  }  

  ts = malloc(255);
  strftime(ts, 255, "%Y%m%d %H:%M.%S", localtime(&result));

  fprintf(logptr, "%s: ", ts); 
  va_start(ap, fmt);
  for(p = fmt; *p; p++) {
    if (*p != '%') {
      fputc(*p, logptr);
      continue;
    }
    switch(*++p) {
    case 'd':
      ival = va_arg(ap, int);
      fprintf(logptr, "%d", ival);
      break;
    case 'f':
      dval = va_arg(ap, double);
      fprintf(logptr, "%f", dval);
      break;
    case 's':
      for(sval = va_arg(ap, char*); *sval; sval++)
	fputc(*sval, logptr);
      break;
    default:
      fputc(*p, logptr);
      break;
    }
  }
  va_end(ap);

  fclose(logptr);
}
Esempio n. 19
0
/* Adds a new entry to the blacklist */
void dst_blst_add(rpc_t* rpc, void* ctx)
{
	str ip;
	int port, proto, flags;
	unsigned char err_flags;
	struct ip_addr *ip_addr;

	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
		rpc->fault(ctx, 500, "dst blacklist support disabled");
		return;
	}
	if (rpc->scan(ctx, "Sddd", &ip, &port, &proto, &flags) < 4)
		return;

	err_flags = (unsigned char)flags;
	/* sanity checks */
	if ((unsigned char)proto > PROTO_SCTP) {
		rpc->fault(ctx, 400, "Unknown protocol");
		return;
	}

	if (err_flags & BLST_IS_IPV6) {
#ifdef USE_IPV6
		/* IPv6 address is specified */
		ip_addr = str2ip6(&ip);
#else  /* USE_IPV6 */
		rpc->fault(ctx, 400, "IPv6 support disabled");
		return;
#endif /* USE_IPV6 */
	} else {
		/* try IPv4 first, than IPv6 */
		ip_addr = str2ip(&ip);
		if (!ip_addr) {
#ifdef USE_IPV6
			ip_addr = str2ip6(&ip);
			err_flags |= BLST_IS_IPV6;
#else  /* USE_IPV6 */
			rpc->fault(ctx, 400, "Malformed or IPv6 ip address");
			return;
#endif /* USE_IPV6 */
		}
	}
	if (!ip_addr) {
		rpc->fault(ctx, 400, "Malformed ip address");
		return;
	}

	if (dst_blacklist_add_ip(err_flags, proto, ip_addr, port, 
				    S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout))))
		rpc->fault(ctx, 400, "Failed to add the entry to the blacklist");
}
Esempio n. 20
0
int reg_get_crt_max_contacts(void)
{
	int n;
	sr_xavp_t *ravp=NULL;
	sr_xavp_t *vavp=NULL;
	str vname = {"max_contacts", 12};

	n = 0;

	if(reg_xavp_cfg.s!=NULL)
	{
		ravp = xavp_get(&reg_xavp_cfg, NULL);
		if(ravp!=NULL && ravp->val.type==SR_XTYPE_XAVP)
		{
			vavp = xavp_get(&vname, ravp->val.v.xavp);
			if(vavp!=NULL && vavp->val.type==SR_XTYPE_INT)
			{
				n = vavp->val.v.i;
				LM_ERR("using max contacts value from xavp: %d\n", n);
			} else {
				ravp = NULL;
			}
		} else {
			ravp = NULL;
		}
	}

	if(ravp==NULL)
	{
		n = cfg_get(registrar, registrar_cfg, max_contacts);
	}

	return n;
}
Esempio n. 21
0
/* dumps the content of the blacklist in a human-readable format */
void dst_blst_view(rpc_t* rpc, void* ctx)
{
	int h;
	int expires;
	struct dst_blst_entry* e;
	ticks_t now;
	struct ip_addr ip;

	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
		rpc->fault(ctx, 500, "dst blacklist support disabled");
		return;
	}
	now=get_ticks_raw();
	for(h=0; h<DST_BLST_HASH_SIZE; h++) {
		LOCK_BLST(h);
		for(e=dst_blst_hash[h].first; e; e=e->next) {
			expires = (s_ticks_t)(now-e->expire)<=0?
			           TICKS_TO_S(e->expire-now): -TICKS_TO_S(now-e->expire);
			/* don't include expired entries into view report */
			if (expires < 0) {
				continue;
			}
			dst_blst_entry2ip(&ip, e);
			rpc->printf(ctx, "{\n    protocol: %s", get_proto_name(e->proto));
			rpc->printf(ctx, "    ip: %s", ip_addr2a(&ip));
			rpc->printf(ctx, "    port: %d", e->port);
			rpc->printf(ctx, "    expires in (s): %d", expires); 
			rpc->printf(ctx, "    flags: %d\n}", e->flags);
		}
		UNLOCK_BLST(h);
	}
}
Esempio n. 22
0
int reg_get_crt_max_contacts(void)
{
	int n;
	sr_xavp_t *vavp=NULL;
	str vname = {"max_contacts", 12};

	n = 0;

	if(reg_xavp_cfg.s!=NULL)
	{
		vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &vname);
		if(vavp!=NULL)
		{
			n = vavp->val.v.i;
			LM_DBG("using max contacts value from xavp: %d\n", n);
		}
	}

	if(vavp==NULL)
	{
		n = cfg_get(registrar, registrar_cfg, max_contacts);
	}

	return n;
}
Esempio n. 23
0
/* only for debugging, it helds the lock too long for "production" use */
void dst_blst_debug(rpc_t* rpc, void* ctx)
{
	int h;
	struct dst_blst_entry* e;
	ticks_t now;
	struct ip_addr ip;

	if (!cfg_get(core, core_cfg, use_dst_blacklist)){
		rpc->fault(ctx, 500, "dst blacklist support disabled");
		return;
	}
	now=get_ticks_raw();
		for(h=0; h<DST_BLST_HASH_SIZE; h++){
			LOCK_BLST(h);
			for(e=dst_blst_hash[h].first; e; e=e->next){
				dst_blst_entry2ip(&ip, e);
				rpc->add(ctx, "ssddd", get_proto_name(e->proto),
										ip_addr2a(&ip), e->port,
										(s_ticks_t)(now-e->expire)<=0?
										TICKS_TO_S(e->expire-now):
										-TICKS_TO_S(now-e->expire) ,
										e->flags);
			}
			UNLOCK_BLST(h);
		}
}
Esempio n. 24
0
/*! \brief
 * Calculate contact q value as follows:
 * 1) If xavp_cfg q has been defined, use it
 * 2) If q parameter exists in contact, use it
 * 3) If the parameter doesn't exist in contact, use the default value
 */
int calc_contact_q(param_t* _q, qvalue_t* _r)
{
	sr_xavp_t *vavp = NULL;
	str xqname = str_init("q");

	if (reg_xavp_cfg.s != NULL)
		vavp = xavp_get_child_with_ival(&reg_xavp_cfg, &xqname);

	if (vavp != NULL) {
		if ((vavp->val.v.i >= 0) && (vavp->val.v.i <= 1000)) {
			*_r = vavp->val.v.i;
			return 0;
		} else {
			rerrno = R_INV_Q; /* Invalid q parameter */
			LM_ERR("invalid q parameter\n");
			return -1;
		}
	}

	if (!_q || (_q->body.len == 0)) {
		*_r = cfg_get(registrar, registrar_cfg, default_q);
	} else {
		if (str2q(_r, _q->body.s, _q->body.len) < 0) {
			rerrno = R_INV_Q; /* Invalid q parameter */
			LM_ERR("invalid q parameter\n");
			return -1;
		}
	}

	return 0;
}
Esempio n. 25
0
unsigned char drv_generic_i2c_wire(const char *name, const char *deflt)
{
    unsigned char w;
    char wire[256];
    char *s;
    qprintf(wire, sizeof(wire), "Wire.%s", name);
    s = cfg_get(Section, wire, deflt);
    if (strlen(s) == 3 && strncasecmp(s, "DB", 2) == 0 && s[2] >= '0' && s[2] <= '7') {
	w = s[2] - '0';
    } else if (strcasecmp(s, "GND") == 0) {
	w = 0;
    } else {
	error("%s: unknown signal <%s> for wire <%s>", Driver, s, name);
	error("%s: should be DB0..7 or GND", Driver);
	return 0xff;
    }
    free(s);
    if (w == 0) {
	info("%s: wiring: [DISPLAY:%s]<==>[i2c:GND]", Driver, name);
    } else {
	info("%s: wiring: [DISPLAY:%s]<==>[i2c:DB%d]", Driver, name, w);
    }
    w = 1 << w;
    return w;
}
Esempio n. 26
0
/*
 * Initialize dlr_waiting_list and return out storage handles.
 */
struct dlr_storage *dlr_init_spool(Cfg *cfg)
{
	CfgGroup *grp;

    if (!(grp = cfg_get_single_group(cfg, octstr_imm("core"))))
        panic(0, "DLR: spool: group 'core' is not specified!");

    if (!(spool_dir = cfg_get(grp, octstr_imm("dlr-spool"))))
   	    panic(0, "DLR: spool: directive 'dlr-spool' is not specified!");

#ifdef HAVE_LIBSSL
    OpenSSL_add_all_digests();
#endif

    counter = counter_create();

    /* we need to traverse the DLR spool to determine how
     * many entries we have. */
#ifdef VERIFIED
    for_each_file(spool_dir, 1, verified_file);
#else
    for_each_file(spool_dir, 1, non_verified_file);
#endif

    return &handles;
}
Esempio n. 27
0
int cfg_get_bool(int *n, CfgGroup *grp, Octstr *varname)
{
    Octstr *os;

    os = cfg_get(grp, varname);
    if (os == NULL) {
	*n = 0;
    	return -1;
    }
    if (octstr_case_compare(os, octstr_imm("true")) == 0
	|| octstr_case_compare(os, octstr_imm("yes")) == 0
	|| octstr_case_compare(os, octstr_imm("on")) == 0
	|| octstr_case_compare(os, octstr_imm("1")) == 0)
    {	    
	*n = 1;
    } else if (octstr_case_compare(os, octstr_imm("false")) == 0
	|| octstr_case_compare(os, octstr_imm("no")) == 0
	|| octstr_case_compare(os, octstr_imm("off")) == 0
	|| octstr_case_compare(os, octstr_imm("0")) == 0)
    {
	*n = 0;
    }
    else {
	*n = 1;
	warning(0, "bool variable set to strange value, assuming 'true'");
    }
    octstr_destroy(os);
    return 0;
}
Esempio n. 28
0
/** wrapper over tls_ct_q_add().
 * Besides doing a tls_ct_q_add it also keeps track of queue size and
 * total queued bytes. If the maximum queue size is exceeded => error.
 * @return 0 on success, < 0 on error (-1 memory allocation, -2 queue size
 *         too big).
 */
int tls_ct_wq_add(tls_ct_q** ct_q, const void* data, unsigned int size)
{
	int ret;
	
	if (unlikely( (*ct_q && (((*ct_q)->queued + size) >
						cfg_get(tls, tls_cfg, con_ct_wq_max))) ||
				(atomic_get(tls_total_ct_wq) + size) >
						cfg_get(tls, tls_cfg, ct_wq_max))) {
		return -2;
	}
	ret = tls_ct_q_add(ct_q, data, size,
						cfg_get(tls, tls_cfg, ct_wq_blk_size));
	if (likely(ret >= 0))
		atomic_add(tls_total_ct_wq, size);
	return ret;
}
Esempio n. 29
0
void put_on_wait(  struct cell  *Trans  )
{

#ifdef EXTRA_DEBUG
	DBG("DEBUG: put on WAIT \n");
#endif


	/* we put the transaction on wait timer; we do it only once
	   in transaction's timelife because putting it multiple-times
	   might result in a second instance of a wait timer to be
	   set after the first one fired; on expiration of the second
	   instance, the transaction would be re-deleted

			PROCESS1		PROCESS2		TIMER PROCESS
		0. 200/INVITE rx;
		   put_on_wait
		1.					200/INVITE rx;
		2.									WAIT fires; transaction
											about to be deleted
		3.					avoid putting
							on WAIT again
		4.									WAIT timer executed,
											transaction deleted
	*/
	if (timer_add(&Trans->wait_timer, cfg_get(tm, tm_cfg, wait_timeout))==0){
		/* sucess */
		t_stats_wait();
	}else{
		DBG("tm: put_on_wait: transaction %p already on wait\n", Trans);
	}
}
Esempio n. 30
0
/* returns number of ticks before retrying the del, or 0 if the del.
 * was succesfull */
inline static ticks_t delete_cell(struct cell *p_cell, int unlock)
{
	/* there may still be FR/RETR timers, which have been reset
	   (i.e., time_out==TIMER_DELETED) but are stilled linked to
	   timer lists and must be removed from there before the
	   structures are released
	*/
	unlink_timers(p_cell);
	/* still in use ... don't delete */
	if(IS_REFFED_UNSAFE(p_cell)) {
		if(unlock)
			UNLOCK_HASH(p_cell->hash_index);
		LM_DBG("%p: can't delete -- still reffed (%d)\n", p_cell,
				p_cell->ref_count);
		/* delay the delete */
		/* TODO: change refcnts and delete on refcnt==0 */
		return cfg_get(tm, tm_cfg, delete_timeout);
	} else {
		if(unlock)
			UNLOCK_HASH(p_cell->hash_index);
#ifdef EXTRA_DEBUG
		LM_DBG("delete transaction %p\n", p_cell);
#endif
		free_cell(p_cell);
		return 0;
	}
}