static int verbose_exec(struct ast_channel *chan, void *data)
{
	char *vtext;
	int vsize;
	struct localuser *u;

	LOCAL_USER_ADD(u);

	if (data) {
		vtext = ast_strdupa((char *)data);
		if (vtext) {
			char *tmp = strsep(&vtext, "|,");
			if (vtext) {
				if (sscanf(tmp, "%d", &vsize) != 1) {
					vsize = 0;
					ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
				}
			} else {
				vtext = tmp;
				vsize = 0;
			}
			if (option_verbose >= vsize) {
				switch (vsize) {
				case 0:
					ast_verbose("%s\n", vtext);
					break;
				case 1:
					ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
					break;
				case 2:
					ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
					break;
				case 3:
					ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
					break;
				default:
					ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
				}
			}
		} else {
			ast_log(LOG_ERROR, "Out of memory\n");
		}
	}

	LOCAL_USER_REMOVE(u);

	return 0;
}
Ejemplo n.º 2
0
static int flash_exec(struct ast_channel *chan, void *data)
{
	int res = -1;
	int x;
	struct localuser *u;
	struct zt_params ztp;
	LOCAL_USER_ADD(u);
	if (!strcasecmp(chan->type, "Zap")) {
		memset(&ztp, 0, sizeof(ztp));
		res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
		if (!res) {
			if (ztp.sigtype & __ZT_SIG_FXS) {
				x = ZT_FLASH;
				res = ioctl(chan->fds[0], ZT_HOOK, &x);
				if (!res || (errno == EINPROGRESS)) {
					if (res) {
						/* Wait for the event to finish */
						zt_wait_event(chan->fds[0]);
					}
					res = ast_safe_sleep(chan, 1000);
					if (option_verbose > 2)
						ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
				} else
					ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
			} else
				ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
		} else
			ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
	} else
		ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
	LOCAL_USER_REMOVE(u);
	return res;
}
Ejemplo n.º 3
0
static int waitforsilence_exec(struct ast_channel *chan, void *data)
{
	int res = 1;
	int silencereqd = 1000;
	int timeout = 0;
	int iterations = 1, i;
	time_t waitstart;

	res = ast_answer(chan); /* Answer the channel */

	if (!data || ( (sscanf(data, "%d|%d|%d", &silencereqd, &iterations, &timeout) != 3) &&
		(sscanf(data, "%d|%d", &silencereqd, &iterations) != 2) &&
		(sscanf(data, "%d", &silencereqd) != 1) ) ) {
		ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration, no timeout\n");
	}

	if (option_verbose > 2)
		ast_verbose(VERBOSE_PREFIX_3 "Waiting %d time(s) for %d ms silence with %d timeout\n", iterations, silencereqd, timeout);

	time(&waitstart);
	res = 1;
	for (i=0; (i<iterations) && (res == 1); i++) {
		res = do_waiting(chan, silencereqd, waitstart, timeout);
	}
	if (res > 0)
		res = 0;
	return res;
}
Ejemplo n.º 4
0
int
sccp_session_send(sccp_session_t * s, sccp_moo_t * r)
{
  int res = 1;

  if (!s || s->fd <= 0) {
    ast_log(LOG_ERROR, "Tried to send packet over DOWN device.\n");
    free(r);
    return -1;
  }

  ast_mutex_lock(&s->lock);

  if (sccp_debug)
    ast_verbose(VERBOSE_PREFIX_2 "Sending Packet Type %s (%d bytes)\n", sccpmsg2str(r->messageId), r->length);

  res = write(s->fd, r, r->length + 8);

  if (res != r->length+8) {
    ast_log(LOG_WARNING, "Only managed to send %d bytes (out of %d): %s\n", res, r->length+8, strerror(errno));
    res = 0;
  }

  ast_mutex_unlock(&s->lock);
  free(r);
  return res;
}
Ejemplo n.º 5
0
static int oss_digit_end(struct ast_channel *c, char digit, unsigned int duration)
{
	/* no better use for received digits than print them */
	ast_verbose(" << Console Received digit %c of duration %u ms >> \n", 
		digit, duration);
	return 0;
}
static int waitforsilence_exec(struct ast_channel *chan, void *data)
{
	int res = 1;
	struct localuser *u;
	int maxsilence = 1000;
	int iterations = 1, i;

	LOCAL_USER_ADD(u);
	
	res = ast_answer(chan); /* Answer the channel */

	if (!data || ((sscanf(data, "%d|%d", &maxsilence, &iterations) != 2) &&
		(sscanf(data, "%d", &maxsilence) != 1))) {
		ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration\n");
	}

	if (option_verbose > 2)
		ast_verbose(VERBOSE_PREFIX_3 "Waiting %d time(s) for %d ms silence\n", iterations, maxsilence);
	
	res = 1;
	for (i=0; (i<iterations) && (res == 1); i++) {
		res = do_waiting(chan, maxsilence);
	}
	LOCAL_USER_REMOVE(u);
	if (res > 0)
		res = 0;
	return res;
}
Ejemplo n.º 7
0
static int reload(void)
{
	/* Aquire control before doing anything to the module itself. */
	ast_mutex_lock(&pgsql_lock);

	if (pgsqlConn) {
		PQfinish(pgsqlConn);
		pgsqlConn = NULL;
	};
	parse_config();

	if (!pgsql_reconnect(NULL)) {
		ast_log(LOG_WARNING,
				"Postgresql RealTime: Couldn't establish connection. Check debug.\n");
		ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
				PQerrorMessage(pgsqlConn));
	}

	ast_verbose(VERBOSE_PREFIX_2 "Postgresql RealTime reloaded.\n");

	/* Done reloading. Release lock so others can now use driver. */
	ast_mutex_unlock(&pgsql_lock);

	return 0;
}
int PAsteriskLog::Buffer::sync()
{
	char *str = strdup(string);
	char *s, *s1;
	char c;

	/* Pass each line with different ast_verbose() call */
	for (s = str; s && *s; s = s1) {
		s1 = strchr(s, '\n');
		if (!s1)
			s1 = s + strlen(s);
		else
			s1++;
		c = *s1;
		*s1 = '\0';
		ast_verbose("%s", s);
		*s1 = c;
	}
	free(str);

	string = PString();
	char *base = string.GetPointer(2000);
	setp(base, base + string.GetSize() - 1);
	return 0;
}
Ejemplo n.º 9
0
static int odbc_do_query(void)
{
	int ODBC_res;
	ODBC_res = SQLExecute(ODBC_stmt);
	
	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
		return -1;
	} else {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query Successful!\n");
		connected = 1;
	}
	return 0;
}
Ejemplo n.º 10
0
static int steal_channel(struct ast_channel *chan, void *pattern)
{
	int ret = 0;
	struct ast_module_user *u;
	struct ast_channel *cur;
	u = ast_module_user_add(chan);
	cur = find_matching_channel(chan, pattern, AST_STATE_UP);
	if (cur) {
		ast_verbose(VERBOSE_PREFIX_3 
			"Channel %s stole channel %s\n",
			chan->name, cur->name);
		pbx_builtin_setvar_helper(chan, "STEAL_CHANNEL", cur->name);
		if (chan->_state != AST_STATE_UP) {
			ast_answer(chan);
		}
		if (cur->_bridge) {
			if (!ast_mutex_lock(&cur->_bridge->lock)) {
				ast_moh_stop(cur->_bridge);
				ast_mutex_unlock(&cur->_bridge->lock);
			}
		}
			
		if (ast_channel_masquerade(cur, chan)) {
			ast_log(LOG_ERROR, "unable to masquerade\n");
			ret = -1;
		}
		ast_mutex_unlock(&cur->lock);
		ast_mutex_unlock(&chan->lock);
	} else {
		pbx_builtin_setvar_helper(chan, "STEAL_CHANNEL", "");
	}
	ast_module_user_remove(u);
	return(ret);
}
Ejemplo n.º 11
0
static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
{
	int i;
	int show_frame = 0;
	struct frame_trace_data *framedata = data;
	if (!frame) {
		return frame;
	}

	if ((event != AST_FRAMEHOOK_EVENT_WRITE) && (event != AST_FRAMEHOOK_EVENT_READ)) {
		return frame;
	}

	for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
		if (frame->frametype == frametype2str[i].type) {
			if ((framedata->list_type == 0) && (framedata->values[i])) { /* white list */
				show_frame = 1;
			} else if ((framedata->list_type == 1) && (!framedata->values[i])){ /* black list */
				show_frame = 1;
			}
			break;
		}
	}

	if (show_frame) {
		ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", ast_channel_name(chan));
		print_frame(frame);
	}
	return frame;
}
Ejemplo n.º 12
0
static int parse_srv(unsigned char *host, int hostlen, int *portno, unsigned char *answer, int len, unsigned char *msg)
{
	int res = 0;
	struct srv *srv = (struct srv *)answer;
	char repl[256] = "";

	if (len < sizeof(struct srv)) {
		printf("Length too short\n");
		return -1;
	}
	answer += sizeof(struct srv);
	len -= sizeof(struct srv);

	if ((res = dn_expand(msg,answer + len,answer, repl, sizeof(repl) - 1)) < 0) {
		ast_log(LOG_WARNING, "Failed to expand hostname\n");
		return -1;
	}
	if (res && strcmp(repl, ".")) {
		if (option_verbose > 3)
			ast_verbose( VERBOSE_PREFIX_3 "parse_srv: SRV mapped to host %s, port %d\n", repl, ntohs(srv->portnum));
		if (host) {
			strncpy(host, repl, hostlen - 1);
			host[hostlen-1] = '\0';
		}
		if (portno)
			*portno = ntohs(srv->portnum);
		return(0);
	}
	return(-1);
}
int ast_register_translator(struct ast_translator *t)
{
	char tmp[80];
	t->srcfmt = powerof(t->srcfmt);
	t->dstfmt = powerof(t->dstfmt);
	if (t->srcfmt >= MAX_FORMAT) {
		ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
		return -1;
	}
	if (t->dstfmt >= MAX_FORMAT) {
		ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
		return -1;
	}
	calc_cost(t,1);
	if (option_verbose > 1)
		ast_verbose(VERBOSE_PREFIX_2 "Registered translator '%s' from format %s to %s, cost %d\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
	ast_mutex_lock(&list_lock);
	if (!added_cli) {
		ast_cli_register(&show_trans);
		added_cli++;
	}
	t->next = list;
	list = t;
	rebuild_matrix(0);
	ast_mutex_unlock(&list_lock);
	return 0;
}
Ejemplo n.º 14
0
static int verbose_exec(struct ast_channel *chan, void *data)
{
	char *vtext;
	int vsize;
	struct ast_module_user *u;

	u = ast_module_user_add(chan);

	if (data) {
		char *tmp;
		vtext = ast_strdupa(data);
		tmp = strsep(&vtext, "|");
		if (vtext) {
			if (sscanf(tmp, "%30d", &vsize) != 1) {
				vsize = 0;
				ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext);
			}
		} else {
			vtext = tmp;
			vsize = 0;
		}
		if (option_verbose >= vsize) {
			switch (vsize) {
			case 0:
				ast_verbose("%s\n", vtext);
				break;
			case 1:
				ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext);
				break;
			case 2:
				ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext);
				break;
			case 3:
				ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext);
				break;
			default:
				ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext);
			}
		}
	}

	ast_module_user_remove(u);

	return 0;
}
static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
{
	int res = 0;
	time_t t;
	struct tm now;
	char *cl,*cn;
	char workstring[80];
	char timestamp[80];
	
	/* Extract the caller ID location */
	if (chan->cid.cid_num)
		ast_copy_string(workstring, chan->cid.cid_num, sizeof(workstring));
	workstring[sizeof(workstring) - 1] = '\0';
	
	ast_callerid_parse(workstring, &cn, &cl);
	if (cl) 
		ast_shrink_phone_number(cl);
                

	/* Get the current time */
		
	time(&t);
	ast_localtime(&t, &now, NULL);
	
	/* Format the time */
	
	strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); 

	
	res = fprintf(logfile, "\n\n[metadata]\n\n");
	
	if(res >= 0)
		res = fprintf(logfile, "PROTOCOL=%s\n", signalling_type);
		
	if(res >= 0)	
		res = fprintf(logfile, "CALLINGFROM=%s\n", (!cl) ? "<unknown>" : cl);
		
	if(res >- 0)
		res = fprintf(logfile, "CALLERNAME=%s\n", (!cn) ? "<unknown>" : cn);
		
	if(res >= 0)
		res = fprintf(logfile, "TIMESTAMP=%s\n\n", timestamp);
	
	if(res >= 0)
		res = fprintf(logfile, "[events]\n\n");
	
	if(res < 0){
		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't write metadata\n");	
		
		ast_log(LOG_DEBUG,"AlarmReceiver: can't write metadata\n");
	}
	else
		res = 0;

	return res;
}
static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn)
{
	int res = 0;
	int i = 0;
	int x = 0;
	struct ast_frame *f, wf;
	
	struct {
		unsigned char offset[AST_FRIENDLY_OFFSET];
		unsigned char buf[640];
	} tone_block;

	for(;;)
	{
	
		if (ast_waitfor(chan, -1) < 0){
			res = -1;
			break;
		}
		
		f = ast_read(chan);
		if (!f){
			res = -1;
			break;
		}
		
		if (f->frametype == AST_FRAME_VOICE) {
			wf.frametype = AST_FRAME_VOICE;
			wf.subclass = AST_FORMAT_ULAW;
			wf.offset = AST_FRIENDLY_OFFSET;
			wf.mallocd = 0;
			wf.data = tone_block.buf;
			wf.datalen = f->datalen;
			wf.samples = wf.datalen;
			
			make_tone_burst(tone_block.buf, freq, (float) tldn, wf.datalen, &x);

			i += wf.datalen / 8;
			if (i > duration) {
				ast_frfree(f);
				break;
			}
			if (ast_write(chan, &wf)){
				if(option_verbose >= 4)
					ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Failed to write frame on %s\n", chan->name);
				ast_log(LOG_WARNING, "AlarmReceiver Failed to write frame on %s\n",chan->name);
				res = -1;
				ast_frfree(f);
				break;
			}
		}
		
		ast_frfree(f);
	}
	return res;
}
Ejemplo n.º 17
0
int ast_image_register(struct ast_imager *img)
{
	if (option_verbose > 1)
		ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
	ast_mutex_lock(&listlock);
	img->next = list;
	list = img;
	ast_mutex_unlock(&listlock);
	return 0;
}
Ejemplo n.º 18
0
static int sqliteput_exec(struct ast_channel *chan, void *data)
{
	int arglen;
	char *argv, *value, *family, *key;

	arglen = strlen (data);
	argv = alloca (arglen + 1);
	if (!argv)			/* Why would this fail? */
	{
		ast_log (LOG_DEBUG, "Memory allocation failed\n");
		return 0;
	}

	memcpy (argv, data, arglen + 1);

	if (strchr (argv, '/') && strchr (argv, '='))
	{
		family = strsep (&argv, "/");
		key = strsep (&argv, "=");
		value = strsep (&argv, "\0");
		if (!value || !family || !key)
		{
			ast_log (LOG_DEBUG, "Ignoring; Syntax error in argument\n");
			return 0;
		}

		if (option_verbose > 2)
			ast_verbose (VERBOSE_PREFIX_3 "sqliteput: family=%s, key=%s, value=%s\n", family, key, value);

		if (ast_db_sqliteput (family, key, value))
		{
			if (option_verbose > 2)
				ast_verbose (VERBOSE_PREFIX_3 "sqliteput: Error writing value to database.\n");
		}

	}
	else
	{
		ast_log (LOG_DEBUG, "Ignoring, no parameters\n");
	}

	return 0;
}
Ejemplo n.º 19
0
static int phone_hangup(struct ast_channel *ast)
{
	struct phone_pvt *p;
	p = ast->pvt->pvt;
	if (option_debug)
		ast_log(LOG_DEBUG, "phone_hangup(%s)\n", ast->name);
	if (!ast->pvt->pvt) {
		ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
		return 0;
	}
	/* XXX Is there anything we can do to really hang up except stop recording? */
	ast_setstate(ast, AST_STATE_DOWN);
	if (ioctl(p->fd, PHONE_REC_STOP))
		ast_log(LOG_WARNING, "Failed to stop recording\n");
	if (ioctl(p->fd, PHONE_PLAY_STOP))
		ast_log(LOG_WARNING, "Failed to stop playing\n");
	if (ioctl(p->fd, PHONE_RING_STOP))
		ast_log(LOG_WARNING, "Failed to stop ringing\n");
	if (ioctl(p->fd, PHONE_CPT_STOP))
		ast_log(LOG_WARNING, "Failed to stop sounds\n");

	/* If it's an FXO, hang them up */
	if (p->mode == MODE_FXO) {
		if (ioctl(p->fd, PHONE_PSTN_SET_STATE, PSTN_ON_HOOK)) 
			ast_log(LOG_DEBUG, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n",ast->name, strerror(errno));
	}

	/* If they're off hook, give a busy signal */
	if (ioctl(p->fd, PHONE_HOOKSTATE)) {
		if (option_debug)
			ast_log(LOG_DEBUG, "Got hunghup, giving busy signal\n");
		ioctl(p->fd, PHONE_BUSY);
		p->cpt = 1;
	}
	p->lastformat = -1;
	p->lastinput = -1;
	p->ministate = 0;
	p->obuflen = 0;
	p->dialtone = 0;
	memset(p->ext, 0, sizeof(p->ext));
	((struct phone_pvt *)(ast->pvt->pvt))->owner = NULL;
	ast_mutex_lock(&usecnt_lock);
	usecnt--;
	if (usecnt < 0) 
		ast_log(LOG_WARNING, "Usecnt < 0???\n");
	ast_mutex_unlock(&usecnt_lock);
	ast_update_use_count();
	if (option_verbose > 2) 
		ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
	ast->pvt->pvt = NULL;
	ast_setstate(ast, AST_STATE_DOWN);
	restart_monitor();
	return 0;
}
Ejemplo n.º 20
0
void
sccp_dev_set_microphone(sccp_device_t * d, StationMicrophoneMode opt)
{
  sccp_moo_t * r;
  if (!d->session)
    return;
  REQ(r, SetMicroModeMessage)
  r->msg.SetMicroModeMessage.micMode = opt;
  ast_verbose(VERBOSE_PREFIX_2 "{SetMicroModeMessage} micMode=%d\n", opt);
  sccp_dev_send(d, r);
}
Ejemplo n.º 21
0
void
sccp_dev_set_speaker(sccp_device_t * d, StationSpeakerMode mode)
{
  sccp_moo_t * r;
  if (!d->session)
    return;
  REQ(r, SetSpeakerModeMessage)
  r->msg.SetSpeakerModeMessage.speakerMode = mode;
  ast_verbose(VERBOSE_PREFIX_2 "{SetSpeakerModeMessage} speakerMode=%d\n", mode);
  sccp_dev_send(d, r);
}
Ejemplo n.º 22
0
static void exit_now(GtkWidget *widget, gpointer data)
{
	ast_loader_unregister(mod_update);
	gtk_main_quit();
	inuse--;
	ast_update_use_count();
	ast_unregister_verbose(verboser);
	ast_unload_resource("pbx_gtkconsole", 0);
	if (option_verbose > 1)
		ast_verbose(VERBOSE_PREFIX_2 "GTK Console Monitor Exiting\n");
	/* XXX Trying to quit after calling this makes asterisk segfault XXX */
}
Ejemplo n.º 23
0
static int deltree_exec(struct ast_channel *chan, void *data)
{
	char *argv, *family, *keytree;
	struct ast_module_user *u;

	u = ast_module_user_add(chan);

	argv = ast_strdupa(data);

	if (strchr(argv, '/')) {
		family = strsep(&argv, "/");
		keytree = strsep(&argv, "\0");
			if (!family || !keytree) {
				ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
				ast_module_user_remove(u);
				return 0;
			}
		if (ast_strlen_zero(keytree))
			keytree = 0;
	} else {
		family = argv;
		keytree = 0;
	}

	if (option_verbose > 2)	{
		if (keytree)
			ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: family=%s, keytree=%s\n", family, keytree);
		else
			ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: family=%s\n", family);
	}

	if (ast_db_deltree(family, keytree)) {
		if (option_verbose > 2)
			ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: Error deleting key from database.\n");
	}

	ast_module_user_remove(u);

	return 0;
}
static int log_events(struct ast_channel *chan,  char *signalling_type, event_node_t *event)
{

	int res = 0;
	char workstring[sizeof(event_spool_dir)+sizeof(event_file)] = "";
	int fd;
	FILE *logfile;
	event_node_t *elp = event;
	
	if (!ast_strlen_zero(event_spool_dir)) {
		
		/* Make a template */
		
		ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
		strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
		
		/* Make the temporary file */
		
		fd = mkstemp(workstring);
		
		if(fd == -1){
			ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't make temporary file\n");	
			ast_log(LOG_DEBUG,"AlarmReceiver: can't make temporary file\n");
			res = -1;
		}
		
		if(!res){
			logfile = fdopen(fd, "w");
			if(logfile){
				/* Write the file */
				res = write_metadata(logfile, signalling_type, chan);
				if(!res)
					while((!res) && (elp != NULL)){
						res = write_event(logfile, elp);
						elp = elp->next;
					}
				if(!res){
					if(fflush(logfile) == EOF)
						res = -1;
					if(!res){
						if(fclose(logfile) == EOF)
							res = -1;
					}				
				}
			}
			else
				res = -1;
		}
	}

	return res;	
}
Ejemplo n.º 25
0
static int odbc_unload_module(void)
{
	ast_mutex_lock(&odbc_lock);
	if (connected) {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Disconnecting from %s\n", dsn);
		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
		SQLDisconnect(ODBC_con);
		SQLFreeHandle(SQL_HANDLE_DBC, ODBC_con);
		SQLFreeHandle(SQL_HANDLE_ENV, ODBC_env);
		connected = 0;
	}
	if (dsn && dsn_alloc) {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free dsn\n");
		free(dsn);
		dsn = NULL;
		dsn_alloc = 0;
	}
	if (username && username_alloc) {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free username\n");
		free(username);
		username = NULL;
		username_alloc = 0;
	}
	if (password && password_alloc) {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: free password\n");
		free(password);
		password = NULL;
		password_alloc = 0;
	}
	loguniqueid = 0;

	ast_cdr_unregister(name);
	ast_mutex_unlock(&odbc_lock);
	return 0;
}
Ejemplo n.º 26
0
static int odbc_log(struct ast_cdr *cdr)
{
	int res = 0;
	char timestr[150];

	ast_mutex_lock(&odbc_lock);
	build_query(cdr, timestr, sizeof(timestr));

	if (connected) {
		res = odbc_do_query();
		if (res < 0) {
			if (option_verbose > 10)
				ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
			odbc_disconnect();
			res = odbc_init();
			if (res < 0) {
				if (option_verbose > 10)
					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: %s has gone away!\n", dsn);
				odbc_disconnect();
			} else {
				if (option_verbose > 10)
					ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
				SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
				build_query(cdr, timestr, sizeof(timestr)); /* what a waste. If we have to reconnect, we have to build a new query */
				res = odbc_do_query();
				if (res < 0) {
					if (option_verbose > 10)
						ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
				}
			}
		}
	} else {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
	}
	SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
	ast_mutex_unlock(&odbc_lock);
	return 0;
}
Ejemplo n.º 27
0
sccp_line_t *
sccp_line_find_byname(char * line)
{
  sccp_line_t * l;
  ast_mutex_lock(&linelock);
  l = lines;
  while(l && strcasecmp(l->name, line) != 0) {
    if (sccp_debug)
      ast_verbose(VERBOSE_PREFIX_3 " --*> %s\n", l->name);
    l = l->lnext;
  }
  ast_mutex_unlock(&linelock);
  return l;
}
Ejemplo n.º 28
0
static int odbc_do_query(void)
{
	long int ODBC_err;
	int ODBC_res;
	short int ODBC_mlen;
	char ODBC_msg[200], ODBC_stat[10];
	
	ODBC_res = SQLExecute(ODBC_stmt);
	
	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
		SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_con, 1, ODBC_stat, &ODBC_err, ODBC_msg, 100, &ODBC_mlen);
		SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
		connected = 0;
		return -1;
	} else {
		if (option_verbose > 10)
			ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query Successful!\n");
		connected = 1;
	}
	return 0;
}
Ejemplo n.º 29
0
int load_module(void)
{
	if (pipe(clipipe)) {
		ast_log(LOG_WARNING, "Unable to create CLI pipe\n");
		return -1;
	}
	g_thread_init(NULL);
	if (gtk_init_check(NULL, NULL))  {
		if (!show_console()) {
			inuse++;
			ast_update_use_count();
			if (option_verbose > 1)
				ast_verbose( VERBOSE_PREFIX_2 "Launched GTK Console monitor\n");		
		} else
			ast_log(LOG_WARNING, "Unable to start GTK console\n");
	} else {
		if (option_debug)
			ast_log(LOG_DEBUG, "Unable to start GTK console monitor -- ignoring\n");
		else if (option_verbose > 1)
			ast_verbose( VERBOSE_PREFIX_2 "GTK is not available -- skipping monitor\n");
	}
	return 0;
}
int unload_module(void)
{
	int res = 0;
	do_reload = 1;

	ast_config_engine_deregister(&sqlite_engine);
	if (has_cdr) {
		ast_cdr_unregister(cdr_name);
		ast_verbose(VERBOSE_PREFIX_2 "SQLite CDR Disabled\n");
	}

	if (has_cli) {
		ast_verbose(VERBOSE_PREFIX_2 "SQLite CLI Disabled\n");
		ast_cli_unregister(&cli_sqlite1);  
		ast_cli_unregister(&cli_sqlite2);
		ast_cli_unregister(&cli_sqlite3);  
		ast_cli_unregister(&cli_sqlite4);  
		ast_cli_unregister(&cli_sqlite5);  
		ast_cli_unregister(&cli_sqlite6);  
		ast_cli_unregister(&cli_sqlite7);  
		ast_cli_unregister(&cli_sqlite8);  
		ast_cli_unregister(&cli_sqlite9);  
	}
		
	ast_unregister_application(app);




	if (has_switch) {
		ast_verbose(VERBOSE_PREFIX_2 "SQLite Switch Disabled\n");
		ast_unregister_switch(&sqlite_switch);
		sqlite3HashClear(&extens);
	}
	
	return res;
}