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;
}
Example #2
0
/*
* Write the metadata to the log file
*/
static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
{
	int res = 0;
	struct timeval t;
	struct ast_tm now;
	char *cl;
	char *cn;
	char workstring[80];
	char timestamp[80];
	
	/* Extract the caller ID location */
	ast_copy_string(workstring,
		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
		sizeof(workstring));
	ast_shrink_phone_number(workstring);
	if (ast_strlen_zero(workstring)) {
		cl = "<unknown>";
	} else {
		cl = workstring;
	}
	cn = S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, "<unknown>");

	/* Get the current time */
	t = ast_tvnow();
	ast_localtime(&t, &now, NULL);

	/* Format the time */
	ast_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);
	}
	if (res >= 0) {
		res = fprintf(logfile, "CALLERNAME=%s\n", 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_verb(3, "AlarmReceiver: can't write metadata\n");
		ast_debug(1,"AlarmReceiver: can't write metadata\n");
	} else {
		res = 0;
	}

	return res;
}
Example #3
0
static int phone_call(struct ast_channel *ast, char *dest, int timeout)
{
	struct phone_pvt *p;

	PHONE_CID cid;
	time_t UtcTime;
	struct tm tm;

	time(&UtcTime);
	localtime_r(&UtcTime,&tm);

	memset(&cid, 0, sizeof(PHONE_CID));
	if(&tm != NULL) {
		snprintf(cid.month, sizeof(cid.month), "%02d",(tm.tm_mon + 1));
		snprintf(cid.day, sizeof(cid.day),     "%02d", tm.tm_mday);
		snprintf(cid.hour, sizeof(cid.hour),   "%02d", tm.tm_hour);
		snprintf(cid.min, sizeof(cid.min),     "%02d", tm.tm_min);
	}
	/* the standard format of ast->callerid is:  "name" <number>, but not always complete */
	if (!ast->callerid || ast_strlen_zero(ast->callerid)){
		strncpy(cid.name, DEFAULT_CALLER_ID, sizeof(cid.name) - 1);
		cid.number[0]='\0';
	} else {
		char *n, *l;
		char callerid[256] = "";
		strncpy(callerid, ast->callerid, sizeof(callerid) - 1);
		ast_callerid_parse(callerid, &n, &l);
		if (l) {
			ast_shrink_phone_number(l);
			if (!ast_isphonenumber(l))
				l = NULL;
		}
		if (l)
			strncpy(cid.number, l, sizeof(cid.number) - 1);
		if (n)
			strncpy(cid.name, n, sizeof(cid.name) - 1);
	}

	p = ast->pvt->pvt;

	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
		ast_log(LOG_WARNING, "phone_call called on %s, neither down nor reserved\n", ast->name);
		return -1;
	}
	if (option_debug)
		ast_log(LOG_DEBUG, "Ringing %s on %s (%d)\n", dest, ast->name, ast->fds[0]);

	IXJ_PHONE_RING_START(cid);
	ast_setstate(ast, AST_STATE_RINGING);
	ast_queue_control(ast, AST_CONTROL_RINGING);
	return 0;
}
Example #4
0
/*!
 * \brief Write metadata to log file
 *
 * \param logfile Log File Pointer
 * \param signalling_type Signaling Type
 * \param chan Asterisk Channel
 * \param no_checksum Expecting messages without checksum
 *
 * \retval 0 success
 * \retval -1 failure
 */
static int write_metadata(FILE *logfile, char *signalling_type, struct ast_channel *chan, int no_checksum)
{
	struct timeval t;
	struct ast_tm now;
	char *cl;
	char *cn;
	char workstring[80];
	char timestamp[80];

	/* Extract the caller ID location */
	ast_copy_string(workstring,
		S_COR(ast_channel_caller(chan)->id.number.valid,
		ast_channel_caller(chan)->id.number.str, ""), sizeof(workstring));
	ast_shrink_phone_number(workstring);
	if (ast_strlen_zero(workstring)) {
		cl = "<unknown>";
	} else {
		cl = workstring;
	}
	cn = S_COR(ast_channel_caller(chan)->id.name.valid,
		ast_channel_caller(chan)->id.name.str, "<unknown>");

	/* Get the current time */
	t = ast_tvnow();
	ast_localtime(&t, &now, NULL);

	/* Format the time */
	ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);

	if (no_group_meta && fprintf(logfile, "PROTOCOL=%s\n"
			"CHECKSUM=%s\n"
			"CALLINGFROM=%s\n"
			"CALLERNAME=%s\n"
			"TIMESTAMP=%s\n\n",
			signalling_type, (!no_checksum) ? "yes" : "no", cl, cn, timestamp) > -1) {
		return 0;
	} else if (fprintf(logfile, "\n\n[metadata]\n\n"
			"PROTOCOL=%s\n"
			"CHECKSUM=%s\n"
			"CALLINGFROM=%s\n"
			"CALLERNAME=%s\n"
			"TIMESTAMP=%s\n\n"
			"[events]\n\n",
			signalling_type, (!no_checksum) ? "yes" : "no", cl, cn, timestamp) > -1) {
		return 0;
	}

	ast_verb(3, "AlarmReceiver: can't write metadata\n");
	ast_debug(1, "AlarmReceiver: can't write metadata\n");
	return -1;
}
Example #5
0
int ast_callerid_parse(char *instr, char **name, char **location)
{
	char *ns, *ne, *ls, *le;

	/* Try "name" <location> format or name <location> format */
	if ((ls = strrchr(instr, '<')) && (le = strrchr(ls, '>'))) {
		*ls = *le = '\0';	/* location found, trim off the brackets */
		*location = ls + 1;	/* and this is the result */
		if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
			*ns = *ne = '\0';	/* trim off the quotes */
			*name = ns + 1;		/* and this is the name */
		} else if (ns) {
			/* An opening quote was found but no closing quote was. The closing
			 * quote may actually be after the end of the bracketed number
			 */
			if (strchr(le + 1, '\"')) {
				*ns = '\0';
				*name = ns + 1;
				ast_trim_blanks(*name);
			} else {
				*name = NULL;
			}
		} else { /* no quotes, trim off leading and trailing spaces */
			*name = ast_skip_blanks(instr);
			ast_trim_blanks(*name);
		}
	} else {	/* no valid brackets */
		char tmp[256];

		ast_copy_string(tmp, instr, sizeof(tmp));
		ast_shrink_phone_number(tmp);
		if (ast_isphonenumber(tmp)) {	/* Assume it's just a location */
			*name = NULL;
			strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
			*location = instr;
		} else { /* Assume it's just a name. */
			*location = NULL;
			if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
				*ns = *ne = '\0';	/* trim off the quotes */
				*name = ns + 1;		/* and this is the name */
			} else { /* no quotes, trim off leading and trailing spaces */
				*name = ast_skip_blanks(instr);
				ast_trim_blanks(*name);
			}
		}
	}
	return 0;
}
Example #6
0
int ast_callerid_parse(char *input_str, char **name, char **location)
{
	char *ls;
	char *le;
	char *name_start;
	char *instr;
	int quotes_stripped = 0;

	/* Handle surrounding quotes */
	input_str = ast_strip(input_str);
	instr = ast_strip_quoted(input_str, "\"", "\"");
	if (instr != input_str) {
		quotes_stripped = 1;
	}

	/* Try "name" <location> format or name <location> format or with a missing > */
	if ((ls = strrchr(instr, '<'))) {
		if ((le = strrchr(ls, '>'))) {
			*le = '\0';	/* location found, trim off the brackets */
		}
		*ls = '\0';
		*location = ls + 1;	/* and this is the result */

		name_start = ast_strip_quoted(instr, "\"", "\"");
	} else {	/* no valid brackets */
		char tmp[256];

		ast_copy_string(tmp, instr, sizeof(tmp));
		ast_shrink_phone_number(tmp);
		if (!quotes_stripped && ast_isphonenumber(tmp)) {	/* Assume it's just a location */
			name_start = NULL;
			strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
			*location = instr;
		} else { /* Assume it's just a name. */
			*location = NULL;
			name_start = ast_strip_quoted(instr, "\"", "\"");
		}
	}

	if (name_start) {
		ast_unescape_quoted(name_start);
	}
	*name = name_start;
	return 0;
}
Example #7
0
int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen)
{
	char *tmp;
	char *l = NULL, *n = NULL;

	tmp = ast_strdupa(buf);
	ast_callerid_parse(tmp, &n, &l);
	if (n)
		ast_copy_string(name, n, namelen);
	else
		name[0] = '\0';
	if (l) {
		ast_shrink_phone_number(l);
		ast_copy_string(num, l, numlen);
	} else
		num[0] = '\0';
	return 0;
}
Example #8
0
void ast_ari_channels_originate(struct ast_variable *headers,
                                struct ast_ari_channels_originate_args *args,
                                struct ast_ari_response *response)
{
    char *dialtech;
    char dialdevice[AST_CHANNEL_NAME];
    char *caller_id = NULL;
    char *cid_num = NULL;
    char *cid_name = NULL;
    int timeout = 30000;

    char *stuff;
    struct ast_channel *chan;
    RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);

    if (ast_strlen_zero(args->endpoint)) {
        ast_ari_response_error(response, 400, "Bad Request",
                               "Endpoint must be specified");
        return;
    }

    dialtech = ast_strdupa(args->endpoint);
    if ((stuff = strchr(dialtech, '/'))) {
        *stuff++ = '\0';
        ast_copy_string(dialdevice, stuff, sizeof(dialdevice));
    }

    if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
        ast_ari_response_error(response, 400, "Bad Request",
                               "Invalid endpoint specified");
        return;
    }

    if (args->timeout > 0) {
        timeout = args->timeout * 1000;
    } else if (args->timeout == -1) {
        timeout = -1;
    }

    if (!ast_strlen_zero(args->caller_id)) {
        caller_id = ast_strdupa(args->caller_id);
        ast_callerid_parse(caller_id, &cid_name, &cid_num);

        if (ast_is_shrinkable_phonenumber(cid_num)) {
            ast_shrink_phone_number(cid_num);
        }
    }

    if (!ast_strlen_zero(args->app)) {
        const char *app = "Stasis";

        RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free);

        if (!appdata) {
            ast_ari_response_alloc_failed(response);
            return;
        }

        ast_str_set(&appdata, 0, "%s", args->app);
        if (!ast_strlen_zero(args->app_args)) {
            ast_str_append(&appdata, 0, ",%s", args->app_args);
        }

        /* originate a channel, putting it into an application */
        if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, &chan)) {
            ast_ari_response_alloc_failed(response);
            return;
        }
    } else if (!ast_strlen_zero(args->extension)) {
Example #9
0
static void ari_channels_handle_originate_with_id(const char *args_endpoint,
        const char *args_extension,
        const char *args_context,
        long args_priority,
        const char *args_app,
        const char *args_app_args,
        const char *args_caller_id,
        int args_timeout,
        struct ast_variable *variables,
        const char *args_channel_id,
        const char *args_other_channel_id,
        struct ast_ari_response *response)
{
    char *dialtech;
    char dialdevice[AST_CHANNEL_NAME];
    char *caller_id = NULL;
    char *cid_num = NULL;
    char *cid_name = NULL;
    int timeout = 30000;
    RAII_VAR(struct ast_format_cap *, cap,
             ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
    struct ast_format tmp_fmt;
    char *stuff;
    struct ast_channel *chan;
    RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
    struct ast_assigned_ids assignedids = {
        .uniqueid = args_channel_id,
        .uniqueid2 = args_other_channel_id,
    };

    if (!cap) {
        ast_ari_response_alloc_failed(response);
        return;
    }
    ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));

    if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
            || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
        ast_ari_response_error(response, 400, "Bad Request",
                               "Uniqueid length exceeds maximum of %d\n", AST_MAX_PUBLIC_UNIQUEID);
        return;
    }

    if (ast_strlen_zero(args_endpoint)) {
        ast_ari_response_error(response, 400, "Bad Request",
                               "Endpoint must be specified");
        return;
    }

    dialtech = ast_strdupa(args_endpoint);
    if ((stuff = strchr(dialtech, '/'))) {
        *stuff++ = '\0';
        ast_copy_string(dialdevice, stuff, sizeof(dialdevice));
    }

    if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
        ast_ari_response_error(response, 400, "Bad Request",
                               "Invalid endpoint specified");
        return;
    }

    if (args_timeout > 0) {
        timeout = args_timeout * 1000;
    } else if (args_timeout == -1) {
        timeout = -1;
    }

    if (!ast_strlen_zero(args_caller_id)) {
        caller_id = ast_strdupa(args_caller_id);
        ast_callerid_parse(caller_id, &cid_name, &cid_num);

        if (ast_is_shrinkable_phonenumber(cid_num)) {
            ast_shrink_phone_number(cid_num);
        }
    }

    if (!ast_strlen_zero(args_app)) {
        const char *app = "Stasis";

        RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free);

        if (!appdata) {
            ast_ari_response_alloc_failed(response);
            return;
        }

        ast_str_set(&appdata, 0, "%s", args_app);
        if (!ast_strlen_zero(args_app_args)) {
            ast_str_append(&appdata, 0, ",%s", args_app_args);
        }

        /* originate a channel, putting it into an application */
        if (ast_pbx_outgoing_app(dialtech, cap, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, variables, NULL, &chan, &assignedids)) {
            ast_ari_response_alloc_failed(response);
            return;
        }
    } else if (!ast_strlen_zero(args_extension)) {