All pastes #35094 Raw Edit

Unnamed

public text v1 · immutable
#35094 ·published 2005-12-28 21:42 UTC
rendered paste body

static JSBool
chan_originatesync(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	struct fast_originate_helper *in;
	struct ast_channel *chan = NULL;
	char *channel = NULL, *exten = NULL, *context = NULL, *callerid = NULL, *tech = NULL,*data = NULL;
	int res = 0;
	int reason = 0;   
	
	ast_log(LOG_VERBOSE, "Calling originate_helper synchronously...\n");
	  
	*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
	  
	if ( argc == 4 ) {
			channel = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
			context = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
			exten = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
			callerid = JS_GetStringBytes(JS_ValueToString(cx, argv[3]));
	} else {
			ast_log(LOG_ERROR, "Error Origiante Sync called without enough arguments\n");
			return JS_TRUE; // There was not enough arguments
	}
	
	if((data = strchr(tech,'/'))) {
		*data = '\0';
		data++;
	}
	
	if(!(tech && data)) {
		ast_log(LOG_ERROR,"No channel technology or data\n");
		return -1;
	}
	
	// OK allocate everything
	in = malloc(sizeof(struct fast_originate_helper));
	
	if(!in) {
		ast_log(LOG_ERROR,"Origiante Sync: No Memory!\n");
		return -1;
	}
	
	memset(in,0,sizeof(struct fast_originate_helper));
	
	strncpy(in->tech,tech,sizeof(in->tech));
	strncpy(in->data,data,sizeof(in->data));
	in->timeout=30000; //timeout;
	
	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));
	
	ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, NULL, NULL, NULL, &chan);
	
	 /* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
	 if (chan) {
		ast_mutex_unlock(&chan->lock);
		*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
	}
	free(in);		
	return JS_TRUE;

}