Пример #1
0
/*! \brief Helper function which retrieves or allocates a T.38 state information datastore */
static struct t38_state *t38_state_get_or_alloc(struct ast_sip_session *session)
{
	RAII_VAR(struct ast_datastore *, datastore, ast_sip_session_get_datastore(session, "t38"), ao2_cleanup);
	struct t38_state *state;

	/* While the datastore refcount is decremented this is operating in the serializer so it will remain valid regardless */
	if (datastore) {
		return datastore->data;
	}

	if (!(datastore = ast_sip_session_alloc_datastore(&t38_datastore, "t38")) ||
		!(datastore->data = ast_calloc(1, sizeof(struct t38_state))) ||
		ast_sip_session_add_datastore(session, datastore)) {
		return NULL;
	}

	state = datastore->data;

	/* This will get bumped up before scheduling */
	state->timer.user_data = session;
	state->timer.cb = t38_automatic_reject_timer_cb;

	datastore->data = state;

	return state;
}
Пример #2
0
static void *playtones_alloc(struct ast_channel *chan, void *params)
{
	struct playtones_def *pd = params;
	struct playtones_state *ps = NULL;

	if (!(ps = ast_calloc(1, sizeof(*ps)))) {
		return NULL;
	}

	ps->origwfmt = ao2_bump(ast_channel_writeformat(chan));

	if (ast_set_write_format(chan, ast_format_slin)) {
		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
		playtones_release(NULL, ps);
		ps = NULL;
	} else {
		ps->vol = pd->vol;
		ps->reppos = pd->reppos;
		ps->nitems = pd->nitems;
		ps->items = pd->items;
		ps->oldnpos = -1;
	}

	/* Let interrupts interrupt :) */
	if (pd->interruptible) {
		ast_set_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
	} else {
		ast_clear_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
	}

	return ps;
}
Пример #3
0
void *_ast_register_timing_interface(struct ast_timing_interface *funcs,
				     struct ast_module *mod)
{
	struct timing_holder *h;

	if (!funcs->timer_open ||
	    !funcs->timer_close ||
	    !funcs->timer_set_rate ||
	    !funcs->timer_ack ||
	    !funcs->timer_get_event ||
	    !funcs->timer_get_max_rate ||
	    !funcs->timer_enable_continuous ||
	    !funcs->timer_disable_continuous) {
		return NULL;
	}

	if (!(h = ast_calloc(1, sizeof(*h)))) {
		return NULL;
	}

	h->iface = funcs;
	h->mod = mod;

	ast_heap_wrlock(timing_interfaces);
	ast_heap_push(timing_interfaces, h);
	ast_heap_unlock(timing_interfaces);

	return h;
}
Пример #4
0
int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, const char *exten, const char *context,
                            int timeout)
{
    struct stasis_app_control_dial_data *dial_data;

    if (!(dial_data = ast_calloc(1, sizeof(*dial_data)))) {
        return -1;
    }

    if (!ast_strlen_zero(endpoint)) {
        ast_copy_string(dial_data->endpoint, endpoint, sizeof(dial_data->endpoint));
    } else if (!ast_strlen_zero(exten) && !ast_strlen_zero(context)) {
        snprintf(dial_data->endpoint, sizeof(dial_data->endpoint), "Local/%s@%s", exten, context);
    } else {
        return -1;
    }

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

    stasis_app_send_command_async(control, app_control_dial, dial_data);

    return 0;
}
Пример #5
0
struct ast_timer *ast_timer_open(void)
{
	int fd = -1;
	struct timing_holder *h;
	struct ast_timer *t = NULL;

	ast_heap_rdlock(timing_interfaces);

	if ((h = ast_heap_peek(timing_interfaces, 1))) {
		fd = h->iface->timer_open();
		ast_module_ref(h->mod);
	}

	if (fd != -1) {
		if (!(t = ast_calloc(1, sizeof(*t)))) {
			h->iface->timer_close(fd);
		} else {
			t->fd = fd;
			t->holder = h;
		}
	}

	ast_heap_unlock(timing_interfaces);

	return t;
}
Пример #6
0
struct fixed_jb *fixed_jb_new(struct fixed_jb_conf *conf)
{
	struct fixed_jb *jb;

	if (!(jb = ast_calloc(1, sizeof(*jb))))
		return NULL;

	/* First copy our config */
	memcpy(&jb->conf, conf, sizeof(struct fixed_jb_conf));

	/* we don't need the passed config anymore - continue working with the saved one */
	conf = &jb->conf;

	/* validate the configuration */
	if (conf->jbsize < 1)
		conf->jbsize = FIXED_JB_SIZE_DEFAULT;

	if (conf->resync_threshold < 1)
		conf->resync_threshold = FIXED_JB_RESYNCH_THRESHOLD_DEFAULT;

	/* Set the constant delay to the jitterbuf */
	jb->delay = conf->jbsize;

	return jb;
}
Пример #7
0
static struct srv_context *srv_datastore_setup(const char *service, struct ast_channel *chan)
{
	struct srv_result_datastore *srds;
	struct ast_datastore *datastore;
	const char *host;
	unsigned short port;

	if (!(srds = ast_calloc(1, sizeof(*srds) + strlen(service)))) {
		return NULL;
	}

	ast_autoservice_start(chan);
	if (ast_srv_lookup(&srds->context, service, &host, &port) < 0) {
		ast_autoservice_stop(chan);
		ast_log(LOG_NOTICE, "Error performing lookup of service '%s'\n", service);
		ast_free(srds);
		return NULL;
	}
	ast_autoservice_stop(chan);

	strcpy(srds->id, service);

	if (!(datastore = ast_datastore_alloc(&srv_result_datastore_info, srds->id))) {
		ast_srv_cleanup(&srds->context);
		ast_free(srds);
		return NULL;
	}

	datastore->data = srds;
	ast_channel_lock(chan);
	ast_channel_datastore_add(chan, datastore);
	ast_channel_unlock(chan);
	return srds->context;
}
Пример #8
0
/*! \brief Called when we want to place a call somewhere, but not actually call it... yet */
static struct ast_channel *bridge_request(const char *type, int format, void *data, int *cause)
{
	struct bridge_pvt *p = NULL;

	/* Try to allocate memory for our very minimal pvt structure */
	if (!(p = ast_calloc(1, sizeof(*p)))) {
		return NULL;
	}

	/* Try to grab two Asterisk channels to use as input and output channels */
	if (!(p->input = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-input", p))) {
		ast_free(p);
		return NULL;
	}
	if (!(p->output = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-output", p))) {
		ast_channel_free(p->input);
		ast_free(p);
		return NULL;
	}

	/* Setup the lock on the pvt structure, we will need that */
	ast_mutex_init(&p->lock);

	/* Setup parameters on both new channels */
	p->input->tech = p->output->tech = &bridge_tech;
	p->input->tech_pvt = p->output->tech_pvt = p;
	p->input->nativeformats = p->output->nativeformats = AST_FORMAT_SLINEAR;
	p->input->readformat = p->output->readformat = AST_FORMAT_SLINEAR;
	p->input->rawreadformat = p->output->rawreadformat = AST_FORMAT_SLINEAR;
	p->input->writeformat = p->output->writeformat = AST_FORMAT_SLINEAR;
	p->input->rawwriteformat = p->output->rawwriteformat = AST_FORMAT_SLINEAR;

	return p->input;
}
Пример #9
0
static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel *chan, char **datastore_id)
{
	struct ast_datastore *datastore = NULL;
	struct mixmonitor_ds *mixmonitor_ds;

	if (!(mixmonitor_ds = ast_calloc(1, sizeof(*mixmonitor_ds)))) {
		return -1;
	}

	if (ast_asprintf(datastore_id, "%p", mixmonitor_ds) == -1) {
		ast_log(LOG_ERROR, "Failed to allocate memory for MixMonitor ID.\n");
	}

	ast_mutex_init(&mixmonitor_ds->lock);
	ast_cond_init(&mixmonitor_ds->destruction_condition, NULL);

	if (!(datastore = ast_datastore_alloc(&mixmonitor_ds_info, *datastore_id))) {
		ast_mutex_destroy(&mixmonitor_ds->lock);
		ast_cond_destroy(&mixmonitor_ds->destruction_condition);
		ast_free(mixmonitor_ds);
		return -1;
	}


	mixmonitor_ds->samp_rate = 8000;
	mixmonitor_ds->audiohook = &mixmonitor->audiohook;
	datastore->data = mixmonitor_ds;

	ast_channel_lock(chan);
	ast_channel_datastore_add(chan, datastore);
	ast_channel_unlock(chan);

	mixmonitor->mixmonitor_ds = mixmonitor_ds;
	return 0;
}
Пример #10
0
struct ast_timer *ast_timer_open(void)
{
	void *data = NULL;
	struct timing_holder *h;
	struct ast_timer *t = NULL;

	ast_heap_rdlock(timing_interfaces);

	if ((h = ast_heap_peek(timing_interfaces, 1))) {
		data = h->iface->timer_open();
		ast_module_ref(h->mod);
	}

	if (data) {
		if (!(t = ast_calloc(1, sizeof(*t)))) {
			h->iface->timer_close(data);
		} else {
			t->data = data;
			t->holder = h;
		}
	}

	ast_heap_unlock(timing_interfaces);

	return t;
}
Пример #11
0
struct ast_var_t *ast_var_assign(const char *name, const char *value)
#endif
{
	struct ast_var_t *var;
	int name_len = strlen(name) + 1;
	int value_len = strlen(value) + 1;

#ifdef MALLOC_DEBUG
	if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) {
#else
	if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
#endif
		return NULL;
	}

	ast_copy_string(var->name, name, name_len);
	var->value = var->name + name_len;
	ast_copy_string(var->value, value, value_len);

	return var;
}

void ast_var_delete(struct ast_var_t *var)
{
	ast_free(var);
}
Пример #12
0
static void * playtones_alloc(struct ast_channel *chan, void *params)
{
	struct playtones_def *pd = params;
	struct playtones_state *ps = NULL;

	if (!(ps = ast_calloc(1, sizeof(*ps))))
		return NULL;

	ps->origwfmt = chan->writeformat;

	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
		playtones_release(NULL, ps);
		ps = NULL;
	} else {
		ps->vol = pd->vol;
		ps->reppos = pd->reppos;
		ps->nitems = pd->nitems;
		ps->items = pd->items;
		ps->oldnpos = -1;
	}

	/* Let interrupts interrupt :) */
	if (pd->interruptible)
		ast_set_flag(chan, AST_FLAG_WRITE_INT);
	else
		ast_clear_flag(chan, AST_FLAG_WRITE_INT);

	return ps;
}
Пример #13
0
/*!
 * \brief test taskprocessor listener's alloc callback
 */
static void *test_listener_pvt_alloc(void)
{
	struct test_listener_pvt *pvt;

	pvt = ast_calloc(1, sizeof(*pvt));
	return pvt;
}
Пример #14
0
/*
 * ADD INDICATION command stuff
 */
static int handle_add_indication(int fd, int argc, char *argv[])
{
	struct tone_zone *tz;
	int created_country = 0;
	if (argc != 5) return RESULT_SHOWUSAGE;

	tz = ast_get_indication_zone(argv[2]);
	if (!tz) {
		/* country does not exist, create it */
		ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n",argv[2]);
		
		if (!(tz = ast_calloc(1, sizeof(*tz)))) {
			return -1;
		}
		ast_copy_string(tz->country,argv[2],sizeof(tz->country));
		if (ast_register_indication_country(tz)) {
			ast_log(LOG_WARNING, "Unable to register new country\n");
			free(tz);
			return -1;
		}
		created_country = 1;
	}
	if (ast_register_indication(tz,argv[3],argv[4])) {
		ast_log(LOG_WARNING, "Unable to register indication %s/%s\n",argv[2],argv[3]);
		if (created_country)
			ast_unregister_indication_country(argv[2]);
		return -1;
	}
	return 0;
}
Пример #15
0
int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
{
	struct chanvar *var;

	var = ast_calloc(1, sizeof(*var));
	if (!var) {
		return -1;
	}

	var->name = ast_strdup(variable);
	if (!var->name) {
		free_chanvar(var);
		return -1;
	}

	/* It's kosher for value to be NULL. It means the variable is being unset */
	if (value) {
		var->value = ast_strdup(value);
		if (!var->value) {
			free_chanvar(var);
			return -1;
		}
	}

	stasis_app_send_command_async(control, app_control_set_channel_var, var, free_chanvar);

	return 0;
}
Пример #16
0
static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel *chan)
{
	struct ast_datastore *datastore = NULL;
	struct mixmonitor_ds *mixmonitor_ds;

	if (!(mixmonitor_ds = ast_calloc(1, sizeof(*mixmonitor_ds)))) {
		return -1;
	}

	ast_mutex_init(&mixmonitor_ds->lock);
	ast_cond_init(&mixmonitor_ds->destruction_condition, NULL);

	if (!(datastore = ast_datastore_alloc(&mixmonitor_ds_info, NULL))) {
		ast_mutex_destroy(&mixmonitor_ds->lock);
		ast_cond_destroy(&mixmonitor_ds->destruction_condition);
		ast_free(mixmonitor_ds);
		return -1;
	}

	/* No need to lock mixmonitor_ds since this is still operating in the channel's thread */
	mixmonitor_ds->chan = chan;
	mixmonitor_ds->audiohook = &mixmonitor->audiohook;
	datastore->data = mixmonitor_ds;

	ast_channel_lock(chan);
	ast_channel_datastore_add(chan, datastore);
	ast_channel_unlock(chan);

	mixmonitor->mixmonitor_ds = mixmonitor_ds;
	return 0;
}
Пример #17
0
struct ast_include *include_alloc(const char *value, const char *registrar)
{
	struct ast_include *new_include;
	char *c;
	int valuebufsz = strlen(value) + 1;
	char *p;

	/* allocate new include structure ... */
	new_include = ast_calloc(1, sizeof(*new_include) + (valuebufsz * 2));
	if (!new_include) {
		return NULL;
	}

	/* Fill in this structure. Use 'p' for assignments, as the fields
	 * in the structure are 'const char *'
	 */
	p = new_include->stuff;
	new_include->name = p;
	strcpy(p, value);
	p += valuebufsz;
	new_include->rname = p;
	strcpy(p, value);
	/* Strip off timing info, and process if it is there */
	if ((c = strchr(p, ',')) ) {
		*c++ = '\0';
		new_include->hastime = ast_build_timing(&(new_include->timing), c);
	}
	new_include->registrar = registrar;

	return new_include;
}
Пример #18
0
/*!
 * \internal
 * \brief Set the features datastore if it doesn't exist.
 *
 * \param chan Channel to add features datastore
 * \param my_features The channel's feature flags
 * \param peer_features The channel's bridge peer feature flags
 *
 * \retval TRUE if features datastore already existed.
 */
static int add_features_datastore(struct ast_channel *chan, const struct ast_flags *my_features, const struct ast_flags *peer_features)
{
	struct ast_datastore *datastore;
	struct ast_dial_features *dialfeatures;

	ast_channel_lock(chan);
	datastore = ast_channel_datastore_find(chan, &dial_features_info, NULL);
	ast_channel_unlock(chan);
	if (datastore) {
		/* Already exists. */
		return 1;
	}

	/* Create a new datastore with specified feature flags. */
	datastore = ast_datastore_alloc(&dial_features_info, NULL);
	if (!datastore) {
		ast_log(LOG_WARNING, "Unable to create channel features datastore.\n");
		return 0;
	}
	dialfeatures = ast_calloc(1, sizeof(*dialfeatures));
	if (!dialfeatures) {
		ast_log(LOG_WARNING, "Unable to allocate memory for feature flags.\n");
		ast_datastore_free(datastore);
		return 0;
	}
	ast_copy_flags(&dialfeatures->my_features, my_features, AST_FLAGS_ALL);
	ast_copy_flags(&dialfeatures->peer_features, peer_features, AST_FLAGS_ALL);
	datastore->inheritance = DATASTORE_INHERIT_FOREVER;
	datastore->data = dialfeatures;
	ast_channel_lock(chan);
	ast_channel_datastore_add(chan, datastore);
	ast_channel_unlock(chan);
	return 0;
}
Пример #19
0
struct sip_srtp *sip_srtp_alloc(void)
{
	struct sip_srtp *srtp;

	srtp = ast_calloc(1, sizeof(*srtp));

	return srtp;
}
Пример #20
0
struct callerid_state *callerid_new(int cid_signalling)
{
	struct callerid_state *cid;

	if ((cid = ast_calloc(1, sizeof(*cid)))) {
#ifdef INTEGER_CALLERID
		cid->fskd.ispb = 7;          	/* 1200 baud */	
		/* Set up for 1200 / 8000 freq *32 to allow ints */
		cid->fskd.pllispb  = (int)(8000 * 32  / 1200);
		cid->fskd.pllids   = cid->fskd.pllispb/32;
		cid->fskd.pllispb2 = cid->fskd.pllispb/2;
		
		cid->fskd.icont = 0;           /* PLL REset */
		/* cid->fskd.hdlc = 0; */     	/* Async */
		cid->fskd.nbit = 8;           	/* 8 bits */
		cid->fskd.instop = 1;        	/* 1 stop bit */
		/* cid->fskd.paridad = 0; */  	/* No parity */
		cid->fskd.bw = 1;             	/* Filter 800 Hz */
		if (cid_signalling == 2) {    	/* v23 signalling */
			cid->fskd.f_mark_idx  = 4;	/* 1300 Hz */
			cid->fskd.f_space_idx = 5;	/* 2100 Hz */
		} else {                      	/* Bell 202 signalling as default */
			cid->fskd.f_mark_idx  = 2;	/* 1200 Hz */
			cid->fskd.f_space_idx = 3;	/* 2200 Hz */
		}
		/* cid->fskd.pcola = 0; */    	/* No clue */
		/* cid->fskd.cont = 0.0; */   	/* Digital PLL reset */
		/* cid->fskd.x0 = 0.0; */
		/* cid->fskd.state = 0; */
		cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
		/* cid->pos = 0; */

		fskmodem_init(&cid->fskd);
#else
		cid->fskd.spb = 7.0;          	/* 1200 baud */
		/* cid->fskd.hdlc = 0; */     	/* Async */
		cid->fskd.nbit = 8;           	/* 8 bits */
		cid->fskd.nstop = 1.0;        	/* 1 stop bit */
		/* cid->fskd.paridad = 0; */  	/* No parity */
		cid->fskd.bw = 1;             	/* Filter 800 Hz */
		if (cid_signalling == 2) {    	/* v23 signalling */
			cid->fskd.f_mark_idx =  4;	/* 1300 Hz */
			cid->fskd.f_space_idx = 5;	/* 2100 Hz */
		} else {                      	/* Bell 202 signalling as default */
			cid->fskd.f_mark_idx =  2;	/* 1200 Hz */
			cid->fskd.f_space_idx = 3;	/* 2200 Hz */
		}
		/* cid->fskd.pcola = 0; */    	/* No clue */
		/* cid->fskd.cont = 0.0; */   	/* Digital PLL reset */
		/* cid->fskd.x0 = 0.0; */
		/* cid->fskd.state = 0; */
		cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
		/* cid->pos = 0; */
#endif
	}

	return cid;
}
Пример #21
0
static void *http_root(void *data)
{
	int fd;
	struct sockaddr_in sin;
	socklen_t sinlen;
	struct ast_http_server_instance *ser;
	pthread_t launched;
	pthread_attr_t attr;
	
	for (;;) {
		int flags;

		ast_wait_for_input(httpfd, -1);
		sinlen = sizeof(sin);
		fd = accept(httpfd, (struct sockaddr *)&sin, &sinlen);

		if (fd < 0) {
			if ((errno != EAGAIN) && (errno != EINTR))
				ast_log(LOG_WARNING, "Accept failed: %s\n", strerror(errno));
			continue;
		}

		if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) {
			close(fd);
			continue;
		}

		ser = ast_calloc(1, sizeof(*ser));
		if (!ser) {
			ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno));
			close(fd);
			ast_atomic_fetchadd_int(&session_count, -1);
			continue;
		}
		flags = fcntl(fd, F_GETFL);
		fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
		ser->fd = fd;
		memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
		if ((ser->f = fdopen(ser->fd, "w+"))) {
			pthread_attr_init(&attr);
			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
			
			if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
				ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
				fclose(ser->f);
				free(ser);
				ast_atomic_fetchadd_int(&session_count, -1);
			}
			pthread_attr_destroy(&attr);
		} else {
			ast_log(LOG_WARNING, "fdopen failed!\n");
			close(ser->fd);
			free(ser);
			ast_atomic_fetchadd_int(&session_count, -1);
		}
	}
	return NULL;
}
Пример #22
0
static int __ast_http_post_load(int reload)
{
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

	cfg = ast_config_load2("http.conf", "http", config_flags);
	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
		return 0;
	}

	if (reload) {
		ast_http_uri_unlink_all_with_key(__FILE__);
	}

	if (cfg) {
		for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
			if (!strcasecmp(v->name, "prefix")) {
				ast_copy_string(prefix, v->value, sizeof(prefix));
				if (prefix[strlen(prefix)] == '/') {
					prefix[strlen(prefix)] = '\0';
				}
			}
		}

		for (v = ast_variable_browse(cfg, "post_mappings"); v; v = v->next) {
			struct ast_http_uri *urih;
			struct ast_str *ds;

			if (!(urih = ast_calloc(sizeof(*urih), 1))) {
				ast_config_destroy(cfg);
				return -1;
			}

			if (!(ds = ast_str_create(32))) {
				ast_free(urih);
				ast_config_destroy(cfg);
				return -1;
			}

			urih->description = ast_strdup("HTTP POST mapping");
			urih->uri = ast_strdup(v->name);
			ast_str_set(&ds, 0, "%s", v->value);
			urih->data = ds;
			urih->has_subtree = 0;
			urih->supports_get = 0;
			urih->supports_post = 1;
			urih->callback = http_post_callback;
			urih->key = __FILE__;
			urih->mallocd = urih->dmallocd = 1;

			ast_http_uri_link(urih);
		}

		ast_config_destroy(cfg);
	}
	return 0;
}
Пример #23
0
static void *calloc_wrapper(unsigned int num_structs, size_t struct_size,
	const char *file, int lineno, const char *func)
{
#if defined(__AST_DEBUG_MALLOC)
	return __ast_calloc(num_structs, struct_size, file, lineno, func);
#else
	return ast_calloc(num_structs, struct_size);
#endif
}
Пример #24
0
struct ast_sdp_srtp *ast_sdp_srtp_alloc(void)
{
	if (!ast_rtp_engine_srtp_is_registered()) {
	       ast_debug(1, "No SRTP module loaded, can't setup SRTP session.\n");
	       return NULL;
	}

	return ast_calloc(1, sizeof(struct ast_sdp_srtp));
}
Пример #25
0
/*! \brief Add enum tree to linked list */
static struct enum_search *enum_newtoplev(const char *s)
{
	struct enum_search *tmp;

	if ((tmp = ast_calloc(1, sizeof(*tmp)))) {		
		ast_copy_string(tmp->toplev, s, sizeof(tmp->toplev));
	}
	return tmp;
}
Пример #26
0
/*! \brief open the grabber.
 * We use the special name 'X11' to indicate this grabber.
 */
static void *grab_x11_open(const char *name, struct fbuf_t *geom, int fps)
{
	XImage *im;
	int screen_num;
	struct grab_x11_desc *v;
	struct fbuf_t *b;

	/* all names starting with X11 identify this grabber */
	if (strncasecmp(name, "X11", 3))
		return NULL;	/* not us */
	v = ast_calloc(1, sizeof(*v));
	if (v == NULL)
		return NULL;	/* no memory */

	/* init the connection with the X server */
	v->dpy = XOpenDisplay(NULL);
	if (v->dpy == NULL) {
		ast_log(LOG_WARNING, "error opening display\n");
		goto error;
	}

	v->b = *geom;	/* copy geometry */
	b = &v->b;	/* shorthand */
	/* find width and height of the screen */
	screen_num = DefaultScreen(v->dpy);
	v->screen_width = DisplayWidth(v->dpy, screen_num);
	v->screen_height = DisplayHeight(v->dpy, screen_num);

	v->image = im = XGetImage(v->dpy,
		RootWindow(v->dpy, DefaultScreen(v->dpy)),
		b->x, b->y, b->w, b->h, AllPlanes, ZPixmap);
	if (v->image == NULL) {
		ast_log(LOG_WARNING, "error creating Ximage\n");
		goto error;
	}
	switch (im->bits_per_pixel) {
	case 32:
		b->pix_fmt = PIX_FMT_RGBA32;
		break;
	case 16:
		b->pix_fmt = (im->green_mask == 0x7e0) ? PIX_FMT_RGB565 : PIX_FMT_RGB555;
		break;
	}

	ast_log(LOG_NOTICE, "image: data %p %d bpp fmt %d, mask 0x%lx 0x%lx 0x%lx\n",
		im->data,
		im->bits_per_pixel,
		b->pix_fmt,
		im->red_mask, im->green_mask, im->blue_mask);

	/* set the pointer but not the size as this is not malloc'ed */
	b->data = (uint8_t *)im->data;
	return v;

error:
	return grab_x11_close(v);
}
Пример #27
0
struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
		ssize_t index_offset)
#endif
{
	struct ast_heap *h;

	if (!cmp_fn) {
		ast_log(LOG_ERROR, "A comparison function must be provided\n");
		return NULL;
	}

	if (!init_height) {
		init_height = 8;
	}

	if (!(h =
#ifdef MALLOC_DEBUG
			__ast_calloc(1, sizeof(*h), file, lineno, func)
#else
			ast_calloc(1, sizeof(*h))
#endif
		)) {
		return NULL;
	}

	h->cmp_fn = cmp_fn;
	h->index_offset = index_offset;
	h->avail_len = (1 << init_height) - 1;

	if (!(h->heap =
#ifdef MALLOC_DEBUG
			__ast_calloc(1, h->avail_len * sizeof(void *), file, lineno, func)
#else
			ast_calloc(1, h->avail_len * sizeof(void *))
#endif
		)) {
		ast_free(h);
		return NULL;
	}

	ast_rwlock_init(&h->lock);

	return h;
}
Пример #28
0
int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
{
	int mylen = len;
	int olen;
	int b = 'X';
	int res;
	int c,x;
	short *buf = ast_calloc(1, 2 * len + tdd->oldlen);
	short *obuf = buf;
	if (!buf) {
		ast_log(LOG_WARNING, "Out of memory\n");
		return -1;
	}
	memcpy(buf, tdd->oldstuff, tdd->oldlen);
	mylen += tdd->oldlen / 2;
	for (x = 0; x < len; x++)
		buf[x + tdd->oldlen / 2] = AST_MULAW(ubuf[x]);
	c = res = 0;
	while (mylen >= 1320) { /* has to have enough to work on */
		olen = mylen;
		res = fsk_serial(&tdd->fskd, buf, &mylen, &b);
		if (mylen < 0) {
			ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
			ast_free(obuf);
			return -1;
		}
		buf += (olen - mylen);
		if (res < 0) {
			ast_log(LOG_NOTICE, "fsk_serial failed\n");
			ast_free(obuf);
			return -1;
		}
		if (res == 1) {
			/* Ignore invalid bytes */
			if (b > 0x7f)
				continue;
			c = tdd_decode_baudot(tdd, b);
			if ((c < 1) || (c > 126))
				continue; /* if not valid */
			break;
		}
	}
	if (mylen) {
		memcpy(tdd->oldstuff, buf, mylen * 2);
		tdd->oldlen = mylen * 2;
	} else
		tdd->oldlen = 0;
	ast_free(obuf);
	if (res) {
		tdd->mode = 2;
/* put it in mode where it
			reliably puts teleprinter in correct shift mode */
		return(c);
	}
	return 0;
}
Пример #29
0
struct varshead *ast_var_list_create(void)
{
	struct varshead *head;

	head = ast_calloc(1, sizeof(*head));
	if (!head) {
		return NULL;
	}
	AST_LIST_HEAD_INIT_NOLOCK(head);
	return head;
}
Пример #30
0
static struct playlist_entry *make_entry(const char *filename)
{
	struct playlist_entry *entry;
	
	if (!(entry = ast_calloc(1, sizeof(*entry) + strlen(filename) + 10))) /* XXX why 10 ? */
		return NULL;

	strcpy(entry->filename, filename);

	return entry;
}