Exemplo n.º 1
0
int cw_autoservice_start(struct cw_channel *chan)
{
	int res = -1;
	struct asent *as;
	int needstart;
	cw_mutex_lock(&autolock);
	needstart = (asthread == CW_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
	as = aslist;
	while(as) {
		if (as->chan == chan)
			break;
		as = as->next;
	}
	if (!as) {
		as = malloc(sizeof(struct asent));
		if (as) {
			memset(as, 0, sizeof(struct asent));
			as->chan = chan;
			as->next = aslist;
			aslist = as;
			res = 0;
			if (needstart) {
				if (cw_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
					cw_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
					free(aslist);
					aslist = NULL;
					res = -1;
				} else
					pthread_kill(asthread, SIGURG);
			}
		}
	}
	cw_mutex_unlock(&autolock);
	return res;
}
Exemplo n.º 2
0
static void launch_service(struct outgoing *o)
{
	pthread_t t;
	pthread_attr_t attr;
	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	if (cw_pthread_create(&t,&attr,attempt_thread, o) == -1) {
		cw_log(LOG_WARNING, "Unable to create thread :(\n");
		free_outgoing(o);
	}
}
Exemplo n.º 3
0
int load_module(void)
{
	if (!load_config())
		return -1;

	cw_verbose(VERBOSE_PREFIX_1 "Loading [Sub]Agent Module\n");

	res_snmp_dont_stop = 1;
	if (res_snmp_enabled)
		return cw_pthread_create(&thread, NULL, agent_thread, NULL);
	return 0;
}
Exemplo n.º 4
0
static int database_queue_thread_start(void) {
	pthread_attr_t  attr;

	cw_cond_init(&db_condition_save, NULL);
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	if (cw_pthread_create(&db_thread, &attr, database_queue_thread_main, NULL) < 0) {
		cw_log(LOG_ERROR, "Unable to start database queue thread. Using standard (non cached mode).\n");
		return -1;
	}

	return 0;
}
Exemplo n.º 5
0
int reload(void)
{
	cw_verbose(VERBOSE_PREFIX_1 "Reloading [Sub]Agent Module\n");

	res_snmp_dont_stop = 0;
	if (thread != CW_PTHREADT_NULL)
		pthread_join(thread, NULL);
	thread = CW_PTHREADT_NULL;
	load_config();

	res_snmp_dont_stop = 1;
	if (res_snmp_enabled)
		return cw_pthread_create(&thread, NULL, agent_thread, NULL);
	return 0;
}
Exemplo n.º 6
0
struct sched_context *sched_context_create(void)
{
	struct sched_context *tmp;

	tmp = context_create();

	if (tmp) {
		cw_cond_init(&tmp->service, NULL);
		if (cw_pthread_create(&tmp->tid, NULL, service_thread, tmp)) {
			cw_log(LOG_ERROR, "unable to start service thread: %s\n", strerror(errno));
			sched_context_destroy(tmp);
			tmp = NULL;
		}
	}

	return tmp;
}
Exemplo n.º 7
0
int load_module(void)
{
	pthread_t thread;
	pthread_attr_t attr;
	snprintf(qdir, sizeof(qdir), "%s/%s", cw_config_CW_SPOOL_DIR, "outgoing");
	if (mkdir(qdir, 0700) && (errno != EEXIST)) {
		cw_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool disabled\n", qdir);
		return 0;
	}
	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	if (cw_pthread_create(&thread,&attr,scan_thread, NULL) == -1) {
		cw_log(LOG_WARNING, "Unable to create thread :(\n");
		return -1;
	}
	return 0;
}
Exemplo n.º 8
0
static void cw_bridge_call_thread_launch(struct cw_channel *chan, struct cw_channel *peer) 
{
	pthread_t thread;
	pthread_attr_t attr;
	int result;
	struct cw_bridge_thread_obj *tobj;
	
	if((tobj = malloc(sizeof(struct cw_bridge_thread_obj)))) {
		memset(tobj,0,sizeof(struct cw_bridge_thread_obj));
		tobj->chan = chan;
		tobj->peer = peer;
		

		result = pthread_attr_init(&attr);
		pthread_attr_setschedpolicy(&attr, SCHED_RR);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
		result = cw_pthread_create(&thread, &attr,cw_bridge_call_thread, tobj);
		result = pthread_attr_destroy(&attr);
	}
}
Exemplo n.º 9
0
static int conf_do_originate(struct cw_conf_member *member, char *ext) {
    int res;

    pthread_t th;
    pthread_attr_t attr;
    struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper));

    char dst[80]="";
    char appdata[80]="";
    char *var;
    
    if (!fast) {
	res = -1;
    } else {
	memset(fast, 0, sizeof(struct fast_originate_helper));

	if (  (var = pbx_builtin_getvar_helper(member->chan, "NCONF_OUTBOUND_TIMEOUT")) ) {
	    fast->timeout = atoi(var) * 1000;
	} else
	    fast->timeout = 30000;

	strcat(dst,ext);
	strcat(dst,"@");
	if ( (var = pbx_builtin_getvar_helper(member->chan, "NCONF_OUTBOUND_CONTEXT")) )
	    strcat(dst,var);
	else
	    strcat(dst,member->chan->context);


	strcat(appdata,member->id);
	strcat(appdata,"/");
	if ( (var = pbx_builtin_getvar_helper(member->chan, "NCONF_OUTBOUND_PARAMS")) )
	    strcat(appdata,var);
	else {
	    strcat(appdata,"Sdq");
#if ENABLE_VAD
	    strcat(appdata,"V");
#endif
	}

	cw_copy_string( fast->tech, 	 "Local", sizeof(fast->tech) );
	cw_copy_string( fast->data, 	 dst, sizeof(fast->data) );
	cw_copy_string( fast->app, 	 APP_CONFERENCE_NAME, sizeof(fast->app) );
	cw_copy_string( fast->appdata, appdata, sizeof(fast->appdata) );

	if ( (var = pbx_builtin_getvar_helper(member->chan, "NCONF_OUTBOUND_CID_NAME")) )
	    cw_copy_string( fast->cid_name, var, sizeof(fast->cid_name) );
	else
	    cw_copy_string( fast->cid_name,"NavyConference",sizeof(fast->cid_name) );

	if ( (var = pbx_builtin_getvar_helper(member->chan, "NCONF_OUTBOUND_CID_NUM")) )
	    cw_copy_string( fast->cid_num, var,sizeof(fast->cid_num) );
	else
	    cw_copy_string( fast->cid_num, member->id,sizeof(fast->cid_num) );

	cw_copy_string( fast->context, "internal", sizeof(fast->context) );
	cw_copy_string( fast->exten, ext, sizeof(fast->exten) );
	fast->priority = 1;
	fast->vars=NULL;
/**/

	fast->frommember=member;

        pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	if (cw_pthread_create(&th, &attr, fast_originate, fast)) {
    	    free(fast);
	    res = -1;
	} else {
	    res = 0;
	}

    }

    cw_mutex_unlock(&member->chan->lock);
    cw_conf_member_genactivate( member ) ;

    return res;
}
Exemplo n.º 10
0
static struct cw_conference* create_conf( char* name, struct cw_conf_member* member )
{
    cw_log( CW_CONF_DEBUG, "entered create_conf, name => %s\n", name ) ;	


    // allocate memory for conference
    struct cw_conference *conf = calloc(1, sizeof( struct cw_conference ) ) ;
	
    if ( conf == NULL ) 
    {
    	cw_log( LOG_ERROR, "unable to malloc cw_conference\n" ) ;
    	return NULL ;
    }

    //
    // initialize conference
    //
	
    conf->next = NULL ;
    conf->memberlist = NULL ;
    conf->membercount = 0 ;
    conf->conference_thread = CW_PTHREADT_NULL ;
    conf->is_locked = 0;
    conf->command_queue = NULL ;

    // copy name to conference
    strncpy( (char*)&(conf->name), name, sizeof(conf->name) - 1 ) ;
    // initialize mutexes
    cw_mutex_init( &conf->lock ) ;
	
    // add the initial member
    add_member( conf, member) ;
	
    //
    // prepend new conference to conflist
    //

    // acquire mutex
    cw_mutex_lock( &conflist_lock ) ;

    conf->next = conflist ;
    conflist = conf ;
    cw_log( CW_CONF_DEBUG, "added new conference to conflist, name => %s\n", name ) ;

    //
    // spawn thread for new conference, using conference_exec( conf )
    //
    // acquire conference mutexes
    cw_mutex_lock( &conf->lock ) ;
	
    if ( cw_pthread_create( &conf->conference_thread, NULL, (void*)conference_exec, conf ) == 0 ) 
    {
	// detach the thread so it doesn't leak
	pthread_detach( conf->conference_thread ) ;
	// release conference mutexes
	cw_mutex_unlock( &conf->lock ) ;
	cw_log( CW_CONF_DEBUG, "started conference thread for conference, name => %s\n", conf->name ) ;
	manager_event(
	    EVENT_FLAG_CALL, 
	    APP_CONFERENCE_MANID"ConfCreate", 
	    "Channel: %s\r\n"
	    "ConfNo: %s\r\n",
	    member->channel_name,
	    name
	) ;
    }
    else
    {
    	cw_log( LOG_ERROR, "unable to start conference thread for conference %s\n", conf->name ) ;
	conf->conference_thread = CW_PTHREADT_NULL ;

	// release conference mutexes
	cw_mutex_unlock( &conf->lock ) ;

	// clean up conference
	free( conf ) ;
	conf = NULL ;
    }

    // count new conference 
    if ( conf != NULL )
    	++conference_count ;

    conf->auto_destroy = 1;

    // release mutex
    cw_mutex_unlock( &conflist_lock ) ;

    return conf ;
}
Exemplo n.º 11
0
static int originate_cli(int fd, int argc, char *argv[]) {
	char *chan_name_1,*context,*exten,*tech,*data,*callerid;
	int pri=0,to=60000;
	struct fast_originate_helper *in;
	pthread_t thread;
	pthread_attr_t attr;
	int result;
	char *num = NULL;

	if(argc < 3) {
		cw_cli(fd,USAGE);
		return -1;
	}
	chan_name_1 = argv[1];

	exten = cw_strdupa(argv[2]);
	if((context = strchr(exten,'@'))) {
		*context = 0;
		context++;
	}
	if(! (context && exten)) {
		cw_cli(fd,CGUSAGE);
        return -1;
	}


	pri = argv[3] ? atoi(argv[3]) : 1;
	if(!pri)
		pri = 1;

	tech = cw_strdupa(chan_name_1);
	if((data = strchr(tech,'/'))) {
		*data = '\0';
		data++;
	}
	if(!(tech && data)) {
		cw_cli(fd,USAGE);
        return -1;
	}
	in = malloc(sizeof(struct fast_originate_helper));
	if(!in) {
		cw_cli(fd,"No Memory!\n");
        return -1;
	}
	memset(in,0,sizeof(struct fast_originate_helper));
	
	callerid = (argc > 4)  ? argv[4] : NULL;
	to = (argc > 5) ? atoi(argv[5]) : 60000;

	strncpy(in->tech,tech,sizeof(in->tech));
	strncpy(in->data,data,sizeof(in->data));
	in->timeout=to;
	if(callerid) {
		if((num = strchr(callerid,':'))) {
			*num = '\0';
			num++;
			strncpy(in->cid_num,num,sizeof(in->cid_num));
		}
		strncpy(in->cid_name,callerid,sizeof(in->cid_name));
	}
	strncpy(in->context,context,sizeof(in->context));
	strncpy(in->exten,exten,sizeof(in->exten));
	in->priority = pri;

	cw_cli(fd,"Originating Call %s/%s %s %s %d\n",in->tech,in->data,in->context,in->exten,in->priority);


	result = pthread_attr_init(&attr);
	pthread_attr_setschedpolicy(&attr, SCHED_RR);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	result = cw_pthread_create(&thread, &attr,originate,in);
	result = pthread_attr_destroy(&attr);	
	return 0;
}
Exemplo n.º 12
0
/* this is for incoming calls callweaver sccp_request */
static int sccp_pbx_call(struct cw_channel *ast, char *dest, int timeout) {
	sccp_line_t	 * l;
	sccp_device_t  * d;
	sccp_session_t * s;
	sccp_channel_t * c;
	char * ringermode = NULL;
	pthread_attr_t attr;
	pthread_t t;

	c = CS_CW_CHANNEL_PVT(ast);

	if (!c) {
		cw_log(LOG_WARNING, "SCCP: CallWeaver request to call %s channel: %s, but we don't have this channel!\n", dest, ast->name);
		return -1;
	}

	l = c->line;
	d = l->device;
	s = d->session;

	if (!l || !d || !s) {
		cw_log(LOG_WARNING, "SCCP: weird error. The channel %d has no line or device or session\n", (c ? c->callid : 0) );
		return -1;
	}

	sccp_log(1)(VERBOSE_PREFIX_3 "%s: CallWeaver request to call %s\n", d->id, ast->name);

	cw_mutex_lock(&d->lock);

	if (d->dnd) {
		if (d->dndmode == SCCP_DNDMODE_REJECT) {
			cw_mutex_unlock(&d->lock);
			cw_setstate(ast, CW_STATE_BUSY);
			cw_queue_control(ast, CW_CONTROL_BUSY);
			sccp_log(1)(VERBOSE_PREFIX_3 "%s: DND is on. Call %s rejected\n", d->id, ast->name);
			return 0;
		} else if (d->dndmode == SCCP_DNDMODE_SILENT) {
			/* disable the ringer and autoanswer options */
			c->ringermode = SKINNY_STATION_SILENTRING;
			c->autoanswer_type = SCCP_AUTOANSWER_NONE;
			sccp_log(1)(VERBOSE_PREFIX_3 "%s: DND (silent) is on. Set the ringer = silent and autoanswer = off for %s\n", d->id, ast->name);
		}
	}

	/* if incoming call limit is reached send BUSY */
	cw_mutex_lock(&l->lock);
	if ( l->channelCount > l->incominglimit ) { /* >= just to be sure :-) */
		sccp_log(1)(VERBOSE_PREFIX_3 "Incoming calls limit (%d) reached on SCCP/%s... sending busy\n", l->incominglimit, l->name);
		cw_mutex_unlock(&l->lock);
		cw_mutex_unlock(&d->lock);
		cw_setstate(ast, CW_STATE_BUSY);
		cw_queue_control(ast, CW_CONTROL_BUSY);
		return 0;
	}
	cw_mutex_unlock(&l->lock);

	/* autoanswer check */
	if (c->autoanswer_type) {
		if (d->channelCount > 1) {
			sccp_log(1)(VERBOSE_PREFIX_3 "%s: Autoanswer requested, but the device is in use\n", d->id);
			c->autoanswer_type = SCCP_AUTOANSWER_NONE;
			if (c->autoanswer_cause) {
				switch (c->autoanswer_cause) {
					case CW_CAUSE_CONGESTION:
						cw_queue_control(ast, CW_CONTROL_CONGESTION);
						break;
					default:
						cw_queue_control(ast, CW_CONTROL_BUSY);
						break;
				}
				cw_mutex_unlock(&d->lock);
				return 0;
			}
		} else {
			sccp_log(1)(VERBOSE_PREFIX_3 "%s: Autoanswer requested and activated %s\n", d->id, (c->autoanswer_type == SCCP_AUTOANSWER_1W) ? "with MIC OFF" : "with MIC ON");
		}
	}
	cw_mutex_unlock(&d->lock);

  /* Set the channel callingParty Name and Number */
	sccp_channel_set_callingparty(c, ast->cid.cid_name, ast->cid.cid_num);

  /* Set the channel calledParty Name and Number 7910 compatibility*/
	sccp_channel_set_calledparty(c, l->cid_name, l->cid_num);

	if (!c->ringermode) {
		c->ringermode = SKINNY_STATION_OUTSIDERING;
		ringermode = pbx_builtin_getvar_helper(ast, "ALERT_INFO");
	}

	if ( ringermode && !cw_strlen_zero(ringermode) ) {
		sccp_log(1)(VERBOSE_PREFIX_3 "%s: Found ALERT_INFO=%s\n", d->id, ringermode);
		if (strcasecmp(ringermode, "inside") == 0)
			c->ringermode = SKINNY_STATION_INSIDERING;
		else if (strcasecmp(ringermode, "feature") == 0)
			c->ringermode = SKINNY_STATION_FEATURERING;
		else if (strcasecmp(ringermode, "silent") == 0)
			c->ringermode = SKINNY_STATION_SILENTRING;
		else if (strcasecmp(ringermode, "urgent") == 0)
			c->ringermode = SKINNY_STATION_URGENTRING;
	}

	/* release the callweaver lock */
	cw_mutex_unlock(&ast->lock);
	if ( sccp_channel_get_active(d) ) {
		sccp_indicate_lock(c, SCCP_CHANNELSTATE_CALLWAITING);
		cw_queue_control(ast, CW_CONTROL_RINGING);
	} else {
		sccp_indicate_lock(c, SCCP_CHANNELSTATE_RINGIN);
		cw_queue_control(ast, CW_CONTROL_RINGING);
		if (c->autoanswer_type) {
			sccp_log(1)(VERBOSE_PREFIX_3 "%s: Running the autoanswer thread on %s\n", d->id, ast->name);
			pthread_attr_init(&attr);
			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
			if (cw_pthread_create(&t, &attr, sccp_pbx_call_autoanswer_thread, &c->callid)) {
				cw_log(LOG_WARNING, "%s: Unable to create switch thread for channel (%s-%d) %s\n", d->id, l->name, c->callid, strerror(errno));
			}
		}
	}
	return 0;
}