Example #1
0
OOStkCmdStat ooHangCall(const char* callToken, OOCallClearReason reason, int q931cause)
{
   OOStackCommand cmd;

   OOH323CallData *call;

   if(!callToken)
   {
      return OO_STKCMD_INVALIDPARAM;
   }

   if(!(call = ooFindCallByToken(callToken))) {
      return OO_STKCMD_INVALIDPARAM;
   }

   if(call->CmdChan == 0)
   {
      if(ooCreateCallCmdConnection(call) != OO_OK)
         return OO_STKCMD_CONNECTIONERR;
   }

   memset(&cmd, 0, sizeof(OOStackCommand));
   cmd.type = OO_CMD_HANGCALL;
   cmd.param1 = ast_malloc(strlen(callToken)+1);
   cmd.param2 = ast_malloc(sizeof(OOCallClearReason));
   cmd.param3 = ast_malloc(sizeof(int));
   if(!cmd.param1 || !cmd.param2 || !cmd.param3)
   {
      if(cmd.param1)   ast_free(cmd.param1); /* Release memory */
      if(cmd.param2)   ast_free(cmd.param2);
      if(cmd.param3)   ast_free(cmd.param3);
      return OO_STKCMD_MEMERR;
   }
   strcpy((char*)cmd.param1, callToken);
   cmd.plen1 = strlen(callToken);
   *((OOCallClearReason*)cmd.param2) = reason;
   cmd.plen2 = sizeof(OOCallClearReason);
   *(int *)cmd.param3 = q931cause;
   cmd.plen3 = sizeof(int);

   if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
   {
      ast_free(cmd.param1);
      ast_free(cmd.param2);
      ast_free(cmd.param3);
      return OO_STKCMD_WRITEERR;
   }
   ast_free(cmd.param1);
   ast_free(cmd.param2);
   ast_free(cmd.param3);
   
   return OO_STKCMD_SUCCESS;
}
Example #2
0
static void cpg_deliver_cb(cpg_handle_t handle, const struct cpg_name *group_name,
		uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
{
	struct ast_event *event;

	if (msg_len < ast_event_minimum_length()) {
		ast_debug(1, "Ignoring event that's too small. %u < %u\n",
			(unsigned int) msg_len,
			(unsigned int) ast_event_minimum_length());
		return;
	}

	if (!ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(msg, AST_EVENT_IE_EID))) {
		/* Don't feed events back in that originated locally. */
		return;
	}

	ast_rwlock_rdlock(&event_types_lock);
	if (!event_types[ast_event_get_type(msg)].subscribe) {
		/* We are not configured to subscribe to these events. */
		ast_rwlock_unlock(&event_types_lock);
		return;
	}
	ast_rwlock_unlock(&event_types_lock);

	if (!(event = ast_malloc(msg_len))) {
		return;
	}

	memcpy(event, msg, msg_len);

	ast_event_queue_and_cache(event);
}
Example #3
0
/*! \brief Create an I/O context */
struct io_context *io_context_create(void)
{
	struct io_context *tmp = NULL;

	if (!(tmp = ast_malloc(sizeof(*tmp))))
		return NULL;
	
	tmp->needshrink = 0;
	tmp->fdcnt = 0;
	tmp->maxfdcnt = GROW_SHRINK_SIZE/2;
	tmp->current_ioc = -1;
	
	if (!(tmp->fds = ast_calloc(1, (GROW_SHRINK_SIZE / 2) * sizeof(*tmp->fds)))) {
		ast_free(tmp);
		tmp = NULL;
	} else {
		if (!(tmp->ior = ast_calloc(1, (GROW_SHRINK_SIZE / 2) * sizeof(*tmp->ior)))) {
			ast_free(tmp->fds);
			ast_free(tmp);
			tmp = NULL;
		}
	}

	return tmp;
}
Example #4
0
diva_status_interface_state_t diva_status_init_interface(int controller,
																												 diva_status_hardware_state_t* hwState,
																												 diva_status_changed_cb_proc_t fn,
																												 diva_hwstatus_changed_cb_proc_t hwfn)
{
	int idiController = diva_status_map_CAPI2XDI(controller);
	diva_status_ifc_t* controllerState = idiController > 0 ? (ast_malloc(sizeof(*controllerState))) : 0;
	diva_status_interface_state_t ret = DivaStatusInterfaceStateNotAvailable;

  if (controllerState != 0) {
		controllerState->capiController = controller;
		controllerState->idiController  = idiController;
		controllerState->status_changed_notify_proc    = fn;
		controllerState->hw_status_changed_notify_proc = hwfn;
		controllerState->ifstateWd = -1;
		controllerState->infoWd    = -1;
		diva_status_create_wd(&controllerState->ifstateWd, idiController, DIVA_STATUS_FILE, 0);
		diva_status_create_wd(&controllerState->infoWd, idiController, DIVA_INFO_FILE, 1);
		controllerState->currentState = 0;
		controllerState->changeTime = time(NULL);
		diva_status_get_controller_state(idiController, &controllerState->state[controllerState->currentState]);
		diva_q_add_tail(&controller_q, &controllerState->link);
		ret = diva_status_get_interface_state_from_idi_state(&controllerState->state[controllerState->currentState]);
		*hwState = diva_status_get_hw_state_from_idi_state(&controllerState->state[controllerState->currentState]);
	}

	return ret;
}
Example #5
0
/* returns 1 if frame was inserted into head of queue, 0 otherwise */
static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts) 
{
	jb_frame *frame;
	jb_frame *p;
	int head = 0;
	long resync_ts = ts - jb->info.resync_offset;

	if ((frame = jb->free)) {
		jb->free = frame->next;
	} else if (!(frame = ast_malloc(sizeof(*frame)))) {
		jb_err("cannot allocate frame\n");
		return 0;
	}

	jb->info.frames_cur++;

	frame->data = data;
	frame->ts = resync_ts;
	frame->ms = ms;
	frame->type = type;

	/* 
	 * frames are a circular list, jb-frames points to to the lowest ts, 
	 * jb->frames->prev points to the highest ts
	 */

	if (!jb->frames) {  /* queue is empty */
		jb->frames = frame;
		frame->next = frame;
		frame->prev = frame;
		head = 1;
	} else if (resync_ts < jb->frames->ts) {
		frame->next = jb->frames;
		frame->prev = jb->frames->prev;

		frame->next->prev = frame;
		frame->prev->next = frame;

		/* frame is out of order */
		jb->info.frames_ooo++;

		jb->frames = frame;
		head = 1;
	} else { 
		p = jb->frames;

		/* frame is out of order */
		if (resync_ts < p->prev->ts) jb->info.frames_ooo++;

		while (resync_ts < p->prev->ts && p->prev != jb->frames) 
			p = p->prev;

		frame->next = p;
		frame->prev = p->prev;

		frame->next->prev = frame;
		frame->prev->next = frame;
	}
	return head;
}
Example #6
0
void ast_pbx_hangup_handler_push(struct ast_channel *chan, const char *handler)
{
	struct ast_hangup_handler_list *handlers;
	struct ast_hangup_handler *h_handler;
	const char *expanded_handler;

	if (ast_strlen_zero(handler)) {
		return;
	}

	expanded_handler = ast_app_expand_sub_args(chan, handler);
	if (!expanded_handler) {
		return;
	}
	h_handler = ast_malloc(sizeof(*h_handler) + 1 + strlen(expanded_handler));
	if (!h_handler) {
		ast_free((char *) expanded_handler);
		return;
	}
	strcpy(h_handler->args, expanded_handler);/* Safe */
	ast_free((char *) expanded_handler);

	ast_channel_lock(chan);

	handlers = ast_channel_hangup_handlers(chan);
	AST_LIST_INSERT_HEAD(handlers, h_handler, node);
	publish_hangup_handler_message("push", chan, h_handler->args);
	ast_channel_unlock(chan);
}
Example #7
0
struct ast_ha *ast_append_ha(char *sense, const char *stuff, struct ast_ha *path)
{
	struct ast_ha *ha;
	char *nm = "255.255.255.255";
	char tmp[256];
	struct ast_ha *prev = NULL;
	struct ast_ha *ret;
	int x, z;
	unsigned int y;

	ret = path;
	while (path) {
		prev = path;
		path = path->next;
	}
	if ((ha = ast_malloc(sizeof(*ha)))) {
		ast_copy_string(tmp, stuff, sizeof(tmp));
		nm = strchr(tmp, '/');
		if (!nm) {
			nm = "255.255.255.255";
		} else {
			*nm = '\0';
			nm++;
		}
		if (!strchr(nm, '.')) {
			if ((sscanf(nm, "%30d", &x) == 1) && (x >= 0) && (x <= 32)) {
				y = 0;
				for (z = 0; z < x; z++) {
					y >>= 1;
					y |= 0x80000000;
				}
				ha->netmask.s_addr = htonl(y);
			}
		} else if (!inet_aton(nm, &ha->netmask)) {
Example #8
0
const char *sip_route_add(struct sip_route *route, const char *uri, size_t len, int inserthead)
{
	struct sip_route_hop *hop;

	if (!uri || len < 1 || uri[0] == '\0') {
		return NULL;
	}

	/* Expand len to include null terminator */
	len++;

	/* ast_calloc is not needed because all fields are initialized in this block */
	hop = ast_malloc(sizeof(struct sip_route_hop) + len);
	if (!hop) {
		return NULL;
	}
	ast_copy_string(hop->uri, uri, len);

	if (inserthead) {
		AST_LIST_INSERT_HEAD(&route->list, hop, list);
		route->type = route_invalidated;
	} else {
		if (sip_route_empty(route)) {
			route->type = route_invalidated;
		}
		AST_LIST_INSERT_TAIL(&route->list, hop, list);
		hop->list.next = NULL;
	}

	return hop->uri;
}
Example #9
0
static char *assign_uuid(const pj_str_t *call_id, const pj_str_t *local_tag, const pj_str_t *remote_tag)
{
	RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
	pjsip_dialog *dlg;
	char *uuid = NULL;
	enum hep_uuid_type uuid_type = hepv3_get_uuid_type();

	if ((uuid_type == HEP_UUID_TYPE_CHANNEL)
		&& (dlg = pjsip_ua_find_dialog(call_id, local_tag, remote_tag, PJ_FALSE))
	    && (session = ast_sip_dialog_get_session(dlg))
	    && (session->channel)) {

		uuid = ast_strdup(ast_channel_name(session->channel));
	}

	/* If we couldn't get the channel or we never wanted it, default to the call-id */
	if (!uuid) {

		uuid = ast_malloc(pj_strlen(call_id) + 1);
		if (uuid) {
			ast_copy_pj_str(uuid, call_id, pj_strlen(call_id) + 1);
		}
	}

	return uuid;
}
Example #10
0
OOStkCmdStat ooRequestChangeMode(const char *callToken, int isT38Mode)
{
   OOStackCommand cmd;
   OOH323CallData *call;

   if(!callToken)
   {
      return OO_STKCMD_INVALIDPARAM;
   }

   if(!(call = ooFindCallByToken(callToken))) {
      return OO_STKCMD_INVALIDPARAM;
   }

   if(call->CmdChan == 0)
   {
      if(ooCreateCallCmdConnection(call) != OO_OK)
         return OO_STKCMD_CONNECTIONERR;
   }

   memset(&cmd, 0, sizeof(OOStackCommand));
   cmd.type = OO_CMD_REQMODE;

   cmd.param1 = ast_malloc(strlen(callToken)+1);
   cmd.param2 = ast_malloc(sizeof(int));
   if(!cmd.param1 || !cmd.param2)
   {
      ast_free(cmd.param1); /* Release memory */
      ast_free(cmd.param2);
      return OO_STKCMD_MEMERR;
   }
   strcpy((char*)cmd.param1, callToken);
   cmd.plen1 = strlen(callToken);
   *((int *) cmd.param2) = isT38Mode;
   cmd.plen2 = sizeof(int);
   
   if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
   {
      ast_free(cmd.param1);
      ast_free(cmd.param2);
      return OO_STKCMD_WRITEERR;
   }
   ast_free(cmd.param1);
   ast_free(cmd.param2);

   return OO_STKCMD_SUCCESS;
}
Example #11
0
OOStkCmdStat ooSetANI(const char *callToken, const char* ani)
{
   OOStackCommand cmd;
   OOH323CallData *call;

   if(!callToken)
   {
      return OO_STKCMD_INVALIDPARAM;
   }

   if(!(call = ooFindCallByToken(callToken))) {
      return OO_STKCMD_INVALIDPARAM;
   }

   if(call->CmdChan == 0)
   {
      if(ooCreateCallCmdConnection(call) != OO_OK)
         return OO_STKCMD_CONNECTIONERR;
   }

   memset(&cmd, 0, sizeof(OOStackCommand));
   cmd.type = OO_CMD_SETANI;

   cmd.param1 = ast_malloc(strlen(callToken)+1);
   cmd.param2 = ast_malloc(strlen(ani)+1);
   if(!cmd.param1 || !cmd.param2)
   {
      if(cmd.param1)   ast_free(cmd.param1); /* Release memory */
      if(cmd.param2)   ast_free(cmd.param2);
      return OO_STKCMD_MEMERR;
   }
   strcpy((char*)cmd.param1, callToken);
   cmd.plen1 = strlen(callToken);
   strcpy((char*)cmd.param2, ani);
   cmd.plen2 = strlen(ani);
   
   if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
   {
      ast_free(cmd.param1);
      ast_free(cmd.param2);
      return OO_STKCMD_WRITEERR;
   }
   ast_free(cmd.param1);
   ast_free(cmd.param2);

   return OO_STKCMD_SUCCESS;
}
Example #12
0
static void set_redirecting_value(char **dst, const pj_str_t *src)
{
	ast_free(*dst);
	*dst = ast_malloc(pj_strlen(src) + 1);
	if (*dst) {
		ast_copy_pj_str(*dst, src, pj_strlen(src) + 1);
	}
}
Example #13
0
static void *myrealloc(void *ptr, size_t size)
{
	/* There might be a realloc() out there that doesn't like reallocing
	   NULL pointers, so we take care of it here */
	if (ptr)
		return ast_realloc(ptr, size);
	else
		return ast_malloc(size);
}
Example #14
0
static void CB_INIT(char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size)
{
	if (!(*comment_buffer)) {
		*comment_buffer = ast_malloc(CB_INCR);
		if (!(*comment_buffer))
			return;
		(*comment_buffer)[0] = 0;
		*comment_buffer_size = CB_INCR;
		*lline_buffer = ast_malloc(CB_INCR);
		if (!(*lline_buffer))
			return;
		(*lline_buffer)[0] = 0;
		*lline_buffer_size = CB_INCR;
	} else {
		(*comment_buffer)[0] = 0;
		(*lline_buffer)[0] = 0;
	}
}
Example #15
0
void *ast_json_malloc(size_t size)
{
	struct json_mem *mem = ast_malloc(size + sizeof(*mem));
	if (!mem) {
		return NULL;
	}
	mem->magic = JSON_MAGIC;
	ast_mutex_init(&mem->mutex);
	return mem->data;
}
Example #16
0
struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree)
{
	char prefix[MAX_DB_FIELD];
	sqlite3_stmt *stmt = gettree_stmt;
	struct ast_db_entry *cur, *last = NULL, *ret = NULL;

	if (!ast_strlen_zero(family)) {
		if (!ast_strlen_zero(keytree)) {
			/* Family and key tree */
			snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
		} else {
			/* Family only */
			snprintf(prefix, sizeof(prefix), "/%s", family);
		}
	} else {
		prefix[0] = '\0';
		stmt = gettree_all_stmt;
	}

	ast_mutex_lock(&dblock);
	if (!ast_strlen_zero(prefix) && (sqlite3_bind_text(stmt, 1, prefix, -1, SQLITE_STATIC) != SQLITE_OK)) {
		ast_log(LOG_WARNING, "Could bind %s to stmt: %s\n", prefix, sqlite3_errmsg(astdb));
		sqlite3_reset(stmt);
		ast_mutex_unlock(&dblock);
		return NULL;
	}

	while (sqlite3_step(stmt) == SQLITE_ROW) {
		const char *key_s, *value_s;
		if (!(key_s = (const char *) sqlite3_column_text(stmt, 0))) {
			break;
		}
		if (!(value_s = (const char *) sqlite3_column_text(stmt, 1))) {
			break;
		}
		if (!(cur = ast_malloc(sizeof(*cur) + strlen(key_s) + strlen(value_s) + 2))) {
			break;
		}
		cur->next = NULL;
		cur->key = cur->data + strlen(value_s) + 1;
		strcpy(cur->data, value_s);
		strcpy(cur->key, key_s);
		if (last) {
			last->next = cur;
		} else {
			ret = cur;
		}
		last = cur;
	}
	sqlite3_reset(stmt);
	ast_mutex_unlock(&dblock);

	return ret;
}
Example #17
0
/* Create duplicate of ha structure */
static struct ast_ha *ast_duplicate_ha(struct ast_ha *original)
{
	struct ast_ha *new_ha;

	if ((new_ha = ast_malloc(sizeof(*new_ha)))) {
		/* Copy from original to new object */
		ast_copy_ha(original, new_ha);
	}

	return new_ha;
}
Example #18
0
int ast_ari_bridges_add_channel_parse_body(
	struct ast_json *body,
	struct ast_ari_bridges_add_channel_args *args)
{
	struct ast_json *field;
	/* Parse query parameters out of it */
	field = ast_json_object_get(body, "channel");
	if (field) {
		/* If they were silly enough to both pass in a query param and a
		 * JSON body, free up the query value.
		 */
		ast_free(args->channel);
		if (ast_json_typeof(field) == AST_JSON_ARRAY) {
			/* Multiple param passed as array */
			size_t i;
			args->channel_count = ast_json_array_size(field);
			args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);

			if (!args->channel) {
				return -1;
			}

			for (i = 0; i < args->channel_count; ++i) {
				args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
			}
		} else {
			/* Multiple param passed as single value */
			args->channel_count = 1;
			args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
			if (!args->channel) {
				return -1;
			}
			args->channel[0] = ast_json_string_get(field);
		}
	}
	field = ast_json_object_get(body, "role");
	if (field) {
		args->role = ast_json_string_get(field);
	}
	return 0;
}
Example #19
0
static void cpg_deliver_cb(cpg_handle_t handle, const struct cpg_name *group_name,
		uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
{
	struct ast_event *event;
	void (*publish_handler)(struct ast_event *) = NULL;
	enum ast_event_type event_type;

	if (msg_len < ast_event_minimum_length()) {
		ast_debug(1, "Ignoring event that's too small. %u < %u\n",
			(unsigned int) msg_len,
			(unsigned int) ast_event_minimum_length());
		return;
	}

	if (!ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(msg, AST_EVENT_IE_EID))) {
		/* Don't feed events back in that originated locally. */
		return;
	}

	event_type = ast_event_get_type(msg);
	if (event_type > AST_EVENT_TOTAL) {
		/* Egads, we don't support this */
		return;
	}

	ast_rwlock_rdlock(&event_types_lock);
	publish_handler = event_types[event_type].publish_to_stasis;
	if (!event_types[event_type].subscribe || !publish_handler) {
		/* We are not configured to subscribe to these events or
		   we have no way to publish it internally. */
		ast_rwlock_unlock(&event_types_lock);
		return;
	}
	ast_rwlock_unlock(&event_types_lock);

	if (!(event = ast_malloc(msg_len))) {
		return;
	}

	memcpy(event, msg, msg_len);

	if (event_type == AST_EVENT_PING) {
		const struct ast_eid *eid;
		char buf[128] = "";

		eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID);
		ast_eid_to_str(buf, sizeof(buf), (struct ast_eid *) eid);
		ast_log(LOG_NOTICE, "Got event PING from server with EID: '%s'\n", buf);
	}
	ast_debug(5, "Publishing event %s (%u) to stasis\n",
		ast_event_get_type_name(event), event_type);
	publish_handler(event);
}
Example #20
0
/*! /brief Create test element */
static char *ht_new(int i)
{
	const int buflen = 12;
	char *keybuf = ast_malloc(buflen);
	int needed;
	if (keybuf == NULL) {
		return NULL;
	}
	needed = snprintf(keybuf, buflen, "key%08x", (unsigned)i);
	ast_assert(needed + 1 <= buflen);
	return keybuf;
}
static char *socket_receive_file_to_buff(int fd,int *size)
{
    /* Receive file (probably a waveform file) from socket using   */
    /* Festival key stuff technique, but long winded I know, sorry */
    /* but will receive any file without closeing the stream or    */
    /* using OOB data                                              */
    static char *file_stuff_key = "ft_StUfF_key"; /* must == Festival's key */
    char *buff;
    int bufflen;
    int n,k,i;
    char c;

    bufflen = 1024;
    if (!(buff = ast_malloc(bufflen)))
    {
        /* TODO: Handle memory allocation failure */
    }
    *size=0;

    for (k=0; file_stuff_key[k] != '\0';)
    {
        n = read(fd,&c,1);
        if (n==0) break;  /* hit stream eof before end of file */
        if ((*size)+k+1 >= bufflen)
        {   /* +1 so you can add a NULL if you want */
            bufflen += bufflen/4;
            if (!(buff = ast_realloc(buff, bufflen)))
            {
                /* TODO: Handle memory allocation failure */
            }
        }
        if (file_stuff_key[k] == c)
            k++;
        else if ((c == 'X') && (file_stuff_key[k+1] == '\0'))
        {   /* It looked like the key but wasn't */
            for (i=0; i < k; i++,(*size)++)
                buff[*size] = file_stuff_key[i];
            k=0;
            /* omit the stuffed 'X' */
        }
        else
        {
            for (i=0; i < k; i++,(*size)++)
                buff[*size] = file_stuff_key[i];
            k=0;
            buff[*size] = c;
            (*size)++;
        }

    }

    return buff;
}
Example #22
0
jitterbuf * jb_new() 
{
	jitterbuf *jb;

	if (!(jb = ast_malloc(sizeof(*jb)))) 
		return NULL;

	jb_reset(jb);

	jb_dbg2("jb_new() = %x\n", jb);
	return jb;
}
/*!
 * \brief Execute an DELETE query
 * \param url
 * \param unused
 * \param keyfield where clause field
 * \param lookup value of field for where clause
 * \param ap list containing one or more field/value set(s)
 *
 * Delete a row from a database table, prepare the sql statement using keyfield and lookup
 * control the number of records to change. Additional params to match rows are stored in ap list.
 * Sub-in the values to the prepared statement and execute it.
 *
 * \retval number of rows affected
 * \retval -1 on failure
*/
static int destroy_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, va_list ap)
{
	struct ast_str *query;
	char buf1[200], buf2[200];
	const char *newparam, *newval;
	char *stringp;
	int i, rowcount = -1;
	const int EncodeSpecialChars = 1, bufsize = 100;
	char *buffer;

	if (!ast_custom_function_find("CURL")) {
		ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
		return -1;
	}

	if (!(query = ast_str_create(1000)))
		return -1;

	if (!(buffer = ast_malloc(bufsize))) {
		ast_free(query);
		return -1;
	}

	ast_uri_encode(keyfield, buf1, sizeof(buf1), EncodeSpecialChars);
	ast_uri_encode(lookup, buf2, sizeof(buf2), EncodeSpecialChars);
	ast_str_set(&query, 0, "${CURL(%s/destroy,%s=%s&", url, buf1, buf2);

	for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
		newval = va_arg(ap, const char *);
		ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
		ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
		ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
	}
	va_end(ap);

	ast_str_append(&query, 0, ")}");
	pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);

	/* Line oriented output */
	stringp = buffer;
	while (*stringp <= ' ')
		stringp++;
	sscanf(stringp, "%d", &rowcount);

	ast_free(buffer);
	ast_free(query);

	if (rowcount >= 0)
		return (int)rowcount;

	return -1;
}
Example #24
0
static struct qualify_data *qualify_data_alloc(struct ast_sip_endpoint *endpoint, int cli_fd)
{
	struct qualify_data *qual_data;

	qual_data = ast_malloc(sizeof(*qual_data));
	if (!qual_data) {
		return NULL;
	}

	qual_data->endpoint = ao2_bump(endpoint);
	qual_data->cli_fd = cli_fd;
	return qual_data;
}
Example #25
0
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str,
			 int flags, int family)
{
	struct addrinfo hints, *res, *ai;
	char *s, *host, *port;
	int	e, i, res_cnt;

	if (!str) {
		return 0;
	}

	s = ast_strdupa(str);
	if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
		return 0;
	}

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = family;
	hints.ai_socktype = SOCK_DGRAM;

	if ((e = getaddrinfo(host, port, &hints, &res))) {
		ast_log(LOG_ERROR, "getaddrinfo(\"%s\", \"%s\", ...): %s\n",
			host, S_OR(port, "(null)"), gai_strerror(e));
		return 0;
	}

	res_cnt = 0;
	for (ai = res; ai; ai = ai->ai_next) {
		res_cnt++;
	}

	if (res_cnt == 0) {
		goto cleanup;
	}

	if ((*addrs = ast_malloc(res_cnt * sizeof(struct ast_sockaddr))) == NULL) {
		res_cnt = 0;
		goto cleanup;
	}

	i = 0;
	for (ai = res; ai; ai = ai->ai_next) {
		(*addrs)[i].len = ai->ai_addrlen;
		memcpy(&(*addrs)[i].ss, ai->ai_addr, ai->ai_addrlen);
		++i;
	}

cleanup:
	freeaddrinfo(res);
	return res_cnt;
}
static int mcd_write(
	struct ast_channel *chan, const char *cmd, char *parse, const char *value
) {

	memcached_return_t rc;
	memcached_st *mcd = memcached_pool_fetch(mcdpool, &to, &rc);
	if (rc) {
        ast_log(LOG_WARNING, "mcd_write: memcached pool error: %d\n", rc);
		return 0;
    }

	char *key = (char *)ast_malloc(MEMCACHED_MAX_KEY);
	unsigned int timeout = mcdttl; 

	mcd_set_operation_result(chan, MEMCACHED_SUCCESS);

	// the app argument is the key to set
	if (ast_strlen_zero(parse)) {
		ast_log(LOG_WARNING, "MCD() requires argument (key)\n");
		mcd_set_operation_result(chan, MEMCACHED_ARGUMENT_NEEDED);
		free(key);
		return 0;
	}
	strcpy(key, parse);
	ast_log(LOG_DEBUG, "setting value for key: %s=%s\n", key, value);

	const char *ttlval = pbx_builtin_getvar_helper(chan, "MCDTTL");
	if (ttlval) {
		timeout = atoi(ttlval);
		if ((timeout == 0) && (strcmp(ttlval, "0") != 0)) {
			ast_log(LOG_WARNING, "dialplan variable MCDTTL=%s (not numeric), will use time-to-live value in the config file\n", ttlval);
			timeout = mcdttl;
		}
	}
	ast_log(LOG_DEBUG, "timeout: %d\n", timeout);

	memcached_return_t mcdret = MEMCACHED_FAILURE;
	mcdret = memcached_set(mcd, 
		key, strlen(key), value, strlen(value), (time_t)timeout, (uint32_t)0
	);
	if (mcdret)
		ast_log(LOG_WARNING, 
			"memcached_%s() error %d: %s\n", cmd, mcdret, memcached_strerror(mcd, mcdret)
		);

	mcd_set_operation_result(chan, mcdret);
	free(key);
	memcached_pool_release(mcdpool, mcd);
	return 0;

}
Example #27
0
int ast_ari_applications_unsubscribe_parse_body(
	struct ast_json *body,
	struct ast_ari_applications_unsubscribe_args *args)
{
	struct ast_json *field;
	/* Parse query parameters out of it */
	field = ast_json_object_get(body, "eventSource");
	if (field) {
		/* If they were silly enough to both pass in a query param and a
		 * JSON body, free up the query value.
		 */
		ast_free(args->event_source);
		if (ast_json_typeof(field) == AST_JSON_ARRAY) {
			/* Multiple param passed as array */
			size_t i;
			args->event_source_count = ast_json_array_size(field);
			args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);

			if (!args->event_source) {
				return -1;
			}

			for (i = 0; i < args->event_source_count; ++i) {
				args->event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
			}
		} else {
			/* Multiple param passed as single value */
			args->event_source_count = 1;
			args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
			if (!args->event_source) {
				return -1;
			}
			args->event_source[0] = ast_json_string_get(field);
		}
	}
	return 0;
}
Example #28
0
int ast_ari_asterisk_get_info_parse_body(
	struct ast_json *body,
	struct ast_ari_asterisk_get_info_args *args)
{
	struct ast_json *field;
	/* Parse query parameters out of it */
	field = ast_json_object_get(body, "only");
	if (field) {
		/* If they were silly enough to both pass in a query param and a
		 * JSON body, free up the query value.
		 */
		ast_free(args->only);
		if (ast_json_typeof(field) == AST_JSON_ARRAY) {
			/* Multiple param passed as array */
			size_t i;
			args->only_count = ast_json_array_size(field);
			args->only = ast_malloc(sizeof(*args->only) * args->only_count);

			if (!args->only) {
				return -1;
			}

			for (i = 0; i < args->only_count; ++i) {
				args->only[i] = ast_json_string_get(ast_json_array_get(field, i));
			}
		} else {
			/* Multiple param passed as single value */
			args->only_count = 1;
			args->only = ast_malloc(sizeof(*args->only) * args->only_count);
			if (!args->only) {
				return -1;
			}
			args->only[0] = ast_json_string_get(field);
		}
	}
	return 0;
}
Example #29
0
static VALUE_PAIR *get_avp(const char *file)
{
	FILE *in;
	char tmp[256];
	VALUE_PAIR *avp = NULL;
	VALUE_PAIR *avp_head = NULL;
	VALUE_PAIR *avp_tmp = NULL;
	int len = 0;

	if((in=fopen(file,"r")) != NULL) {
		while(!feof(in)){
			memset(tmp,0,sizeof(tmp));
			if(!fgets(tmp,sizeof(tmp),in))
				break;
			avp = (VALUE_PAIR *)ast_malloc(sizeof(VALUE_PAIR));
			if(avp == NULL){
				return NULL;
			}
			if(avp_head == NULL){
				avp_head = avp;
			}
			ast_copy_string(avp->name,tmp,strlen(tmp));
			memset(tmp,0,sizeof(tmp));
			fgets(tmp,sizeof(tmp),in);
			avp->attribute = atoi(tmp);
			memset(tmp,0,sizeof(tmp));
			fgets(tmp,sizeof(tmp),in);
			avp->type = atoi(tmp);
			memset(tmp,0,sizeof(tmp));
			fgets(tmp,sizeof(tmp),in);
			if(avp->type == 0) {
				len = strlen(tmp)-1;
				tmp[len] = '\0';
				memcpy(avp->strvalue,tmp,strlen(tmp));
				avp->lvalue = strlen(tmp);
			}else{
				avp->lvalue = atoi(tmp);
			}
			avp->next = NULL;
			if(avp_tmp != NULL){
				avp_tmp->next = avp;
			}
			avp_tmp = avp;
		}
		fclose(in);
	}

	return avp_head;
}
static void *mwi_allocate_body(void *data)
{
	struct ast_str **mwi_str;

	mwi_str = ast_malloc(sizeof(*mwi_str));
	if (!mwi_str) {
		return NULL;
	}
	*mwi_str = ast_str_create(128);
	if (!*mwi_str) {
		ast_free(mwi_str);
		return NULL;
	}
	return mwi_str;
}