예제 #1
0
파일: func_channel.c 프로젝트: OPSF/uClinux
static int func_channel_write(struct ast_channel *chan, char *function,
			      char *data, const char *value)
{
	int ret = 0;
	signed char gainset;

	if (!strcasecmp(data, "language"))
		locked_string_field_set(chan, language, value);
	else if (!strcasecmp(data, "musicclass"))
		locked_string_field_set(chan, musicclass, value);
	else if (!strcasecmp(data, "tonezone")) {
		struct tone_zone *new_zone;
		if (!(new_zone = ast_get_indication_zone(value))) {
			ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
			ret = -1;	
		} else 
			chan->zone = new_zone;
	} else if (!strcasecmp(data, "callgroup"))
		chan->callgroup = ast_get_group(value);
	else if (!strcasecmp(data, "txgain")) {
		sscanf(value, "%hhd", &gainset);
		ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
	} else if (!strcasecmp(data, "rxgain")) {
		sscanf(value, "%hhd", &gainset);
		ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
	} else if (!strcasecmp(data, "transfercapability")) {
		unsigned short i;
		for (i = 0; i < 0x20; i++) {
			if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
				chan->transfercapability = i;
				break;
			}
		}
	} else if (!chan->tech->func_channel_write
		 || chan->tech->func_channel_write(chan, function, data, value)) {
		ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
				data);
		ret = -1;
	}

	return ret;
}
예제 #2
0
static int func_channel_write_real(struct ast_channel *chan, const char *function,
			      char *data, const char *value)
{
	int ret = 0;
	signed char gainset;

	if (!strcasecmp(data, "language"))
		locked_string_field_set(chan, language, value);
	else if (!strcasecmp(data, "parkinglot"))
		locked_string_field_set(chan, parkinglot, value);
	else if (!strcasecmp(data, "musicclass"))
		locked_string_field_set(chan, musicclass, value);
	else if (!strcasecmp(data, "accountcode"))
		locked_string_field_set(chan, accountcode, value);
	else if (!strcasecmp(data, "userfield"))
		locked_string_field_set(chan, userfield, value);
	else if (!strcasecmp(data, "after_bridge_goto")) {
		if (ast_strlen_zero(value)) {
			ast_bridge_discard_after_goto(chan);
		} else {
			ast_bridge_set_after_go_on(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), value);
		}
	} else if (!strcasecmp(data, "amaflags")) {
		ast_channel_lock(chan);
		if (isdigit(*value)) {
			int amaflags;
			sscanf(value, "%30d", &amaflags);
			ast_channel_amaflags_set(chan, amaflags);
		} else if (!strcasecmp(value,"OMIT")){
			ast_channel_amaflags_set(chan, 1);
		} else if (!strcasecmp(value,"BILLING")){
			ast_channel_amaflags_set(chan, 2);
		} else if (!strcasecmp(value,"DOCUMENTATION")){
			ast_channel_amaflags_set(chan, 3);
		}
		ast_channel_unlock(chan);
	} else if (!strcasecmp(data, "peeraccount"))
		locked_string_field_set(chan, peeraccount, value);
	else if (!strcasecmp(data, "hangupsource"))
		/* XXX - should we be forcing this here? */
		ast_set_hangupsource(chan, value, 0);
#ifdef CHANNEL_TRACE
	else if (!strcasecmp(data, "trace")) {
		ast_channel_lock(chan);
		if (ast_true(value))
			ret = ast_channel_trace_enable(chan);
		else if (ast_false(value))
			ret = ast_channel_trace_disable(chan);
		else {
			ret = -1;
			ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).\n");
		}
		ast_channel_unlock(chan);
	}
#endif
	else if (!strcasecmp(data, "tonezone")) {
		struct ast_tone_zone *new_zone;
		if (!(new_zone = ast_get_indication_zone(value))) {
			ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
			ret = -1;
		} else {
			ast_channel_lock(chan);
			if (ast_channel_zone(chan)) {
				ast_channel_zone_set(chan, ast_tone_zone_unref(ast_channel_zone(chan)));
			}
			ast_channel_zone_set(chan, ast_tone_zone_ref(new_zone));
			ast_channel_unlock(chan);
			new_zone = ast_tone_zone_unref(new_zone);
		}
	} else if (!strcasecmp(data, "dtmf_features")) {
		ret = ast_bridge_features_ds_set_string(chan, value);
	} else if (!strcasecmp(data, "callgroup")) {
		ast_channel_lock(chan);
		ast_channel_callgroup_set(chan, ast_get_group(value));
		ast_channel_unlock(chan);
	} else if (!strcasecmp(data, "pickupgroup")) {
		ast_channel_lock(chan);
		ast_channel_pickupgroup_set(chan, ast_get_group(value));
		ast_channel_unlock(chan);
	} else if (!strcasecmp(data, "namedcallgroup")) {
		struct ast_namedgroups *groups = ast_get_namedgroups(value);

		ast_channel_lock(chan);
		ast_channel_named_callgroups_set(chan, groups);
		ast_channel_unlock(chan);
		ast_unref_namedgroups(groups);
	} else if (!strcasecmp(data, "namedpickupgroup")) {
		struct ast_namedgroups *groups = ast_get_namedgroups(value);

		ast_channel_lock(chan);
		ast_channel_named_pickupgroups_set(chan, groups);
		ast_channel_unlock(chan);
		ast_unref_namedgroups(groups);
	} else if (!strcasecmp(data, "txgain")) {
		sscanf(value, "%4hhd", &gainset);
		ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
	} else if (!strcasecmp(data, "rxgain")) {
		sscanf(value, "%4hhd", &gainset);
		ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
	} else if (!strcasecmp(data, "transfercapability")) {
		unsigned short i;

		ast_channel_lock(chan);
		for (i = 0; i < 0x20; i++) {
			if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
				ast_channel_transfercapability_set(chan, i);
				break;
			}
		}
		ast_channel_unlock(chan);
	} else if (!strcasecmp(data, "hangup_handler_pop")) {
		/* Pop one hangup handler before pushing the new handler. */
		ast_pbx_hangup_handler_pop(chan);
		ast_pbx_hangup_handler_push(chan, value);
	} else if (!strcasecmp(data, "hangup_handler_push")) {
		ast_pbx_hangup_handler_push(chan, value);
	} else if (!strcasecmp(data, "hangup_handler_wipe")) {
		/* Pop all hangup handlers before pushing the new handler. */
		while (ast_pbx_hangup_handler_pop(chan)) {
		}
		ast_pbx_hangup_handler_push(chan, value);
	} else if (!strncasecmp(data, "secure_bridge_", 14)) {
		struct ast_datastore *ds;
		struct ast_secure_call_store *store;

		if (!chan || !value) {
			return -1;
		}

		ast_channel_lock(chan);
		if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
			if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
				ast_channel_unlock(chan);
				return -1;
			}
			if (!(store = ast_calloc(1, sizeof(*store)))) {
				ast_channel_unlock(chan);
				ast_free(ds);
				return -1;
			}
			ds->data = store;
			ast_channel_datastore_add(chan, ds);
		} else {
			store = ds->data;
		}

		if (!strcasecmp(data, "secure_bridge_signaling")) {
			store->signaling = ast_true(value) ? 1 : 0;
		} else if (!strcasecmp(data, "secure_bridge_media")) {
			store->media = ast_true(value) ? 1 : 0;
		}
		ast_channel_unlock(chan);
	} else if (!strcasecmp(data, "max_forwards")) {
		int max_forwards;
		if (sscanf(value, "%d", &max_forwards) != 1) {
			ast_log(LOG_WARNING, "Unable to set max forwards to '%s'\n", value);
			ret = -1;
		} else {
			ast_channel_lock(chan);
			ret = ast_max_forwards_set(chan, max_forwards);
			ast_channel_unlock(chan);
		}
	} else if (!ast_channel_tech(chan)->func_channel_write
		 || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
		ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
				data);
		ret = -1;
	}

	return ret;
}
예제 #3
0
파일: misdn_config.c 프로젝트: OPSF/uClinux
static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def)
{
	int re = 0;
	int len, tmp;
	char *valtmp;

	switch (type) {
	case MISDN_CTYPE_STR:
		if ((len = strlen(value))) {
			dest->str = (char *)malloc((len + 1) * sizeof(char));
			strncpy(dest->str, value, len);
			dest->str[len] = 0;
		} else {
			dest->str = (char *)malloc( sizeof(char));
			dest->str[0] = 0;
		}
		break;
	case MISDN_CTYPE_INT:
	{
		char *pat;
		if (strchr(value,'x')) 
			pat="%x";
		else
			pat="%d";
		if (sscanf(value, pat, &tmp)) {
			dest->num = (int *)malloc(sizeof(int));
			memcpy(dest->num, &tmp, sizeof(int));
		} else
			re = -1;
	}
		break;
	case MISDN_CTYPE_BOOL:
		dest->num = (int *)malloc(sizeof(int));
		*(dest->num) = (ast_true(value) ? 1 : 0);
		break;
	case MISDN_CTYPE_BOOLINT:
		dest->num = (int *)malloc(sizeof(int));
		if (sscanf(value, "%d", &tmp)) {
			memcpy(dest->num, &tmp, sizeof(int));
		} else {
			*(dest->num) = (ast_true(value) ? boolint_def : 0);
		}
		break;
	case MISDN_CTYPE_MSNLIST:
		for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) {
			if ((len = strlen(valtmp))) {
				struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list));
				ml->msn = (char *)calloc(len+1, sizeof(char));
				strncpy(ml->msn, valtmp, len);
				ml->next = dest->ml;
				dest->ml = ml;
			}
		}
		break;
	case MISDN_CTYPE_ASTGROUP:
		dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
		*(dest->grp) = ast_get_group(value);
		break;
	}

	return re;
}
예제 #4
0
static int func_channel_write_real(struct ast_channel *chan, const char *function,
                                   char *data, const char *value)
{
    int ret = 0;
    signed char gainset;

    if (!strcasecmp(data, "language"))
        locked_string_field_set(chan, language, value);
    else if (!strcasecmp(data, "parkinglot"))
        locked_string_field_set(chan, parkinglot, value);
    else if (!strcasecmp(data, "musicclass"))
        locked_string_field_set(chan, musicclass, value);
    else if (!strcasecmp(data, "accountcode"))
        locked_string_field_set(chan, accountcode, value);
    else if (!strcasecmp(data, "userfield"))
        locked_string_field_set(chan, userfield, value);
    else if (!strcasecmp(data, "amaflags")) {
        ast_channel_lock(chan);
        if(isdigit(*value)) {
            sscanf(value, "%30d", &chan->amaflags);
        } else if (!strcasecmp(value,"OMIT")) {
            chan->amaflags = 1;
        } else if (!strcasecmp(value,"BILLING")) {
            chan->amaflags = 2;
        } else if (!strcasecmp(value,"DOCUMENTATION")) {
            chan->amaflags = 3;
        }
        ast_channel_unlock(chan);
    } else if (!strcasecmp(data, "peeraccount"))
        locked_string_field_set(chan, peeraccount, value);
    else if (!strcasecmp(data, "hangupsource"))
        /* XXX - should we be forcing this here? */
        ast_set_hangupsource(chan, value, 0);
#ifdef CHANNEL_TRACE
    else if (!strcasecmp(data, "trace")) {
        ast_channel_lock(chan);
        if (ast_true(value))
            ret = ast_channel_trace_enable(chan);
        else if (ast_false(value))
            ret = ast_channel_trace_disable(chan);
        else {
            ret = -1;
            ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).");
        }
        ast_channel_unlock(chan);
    }
#endif
    else if (!strcasecmp(data, "tonezone")) {
        struct ast_tone_zone *new_zone;
        if (!(new_zone = ast_get_indication_zone(value))) {
            ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
            ret = -1;
        } else {
            ast_channel_lock(chan);
            if (chan->zone) {
                chan->zone = ast_tone_zone_unref(chan->zone);
            }
            chan->zone = ast_tone_zone_ref(new_zone);
            ast_channel_unlock(chan);
            new_zone = ast_tone_zone_unref(new_zone);
        }
    } else if (!strcasecmp(data, "callgroup")) {
        chan->callgroup = ast_get_group(value);
    } else if (!strcasecmp(data, "pickupgroup")) {
        chan->pickupgroup = ast_get_group(value);
    } else if (!strcasecmp(data, "txgain")) {
        sscanf(value, "%4hhd", &gainset);
        ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
    } else if (!strcasecmp(data, "rxgain")) {
        sscanf(value, "%4hhd", &gainset);
        ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
    } else if (!strcasecmp(data, "transfercapability")) {
        unsigned short i;
        for (i = 0; i < 0x20; i++) {
            if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
                chan->transfercapability = i;
                break;
            }
        }
    } else if (!strncasecmp(data, "secure_bridge_", 14)) {
        struct ast_datastore *ds;
        struct ast_secure_call_store *store;

        if (!chan || !value) {
            return -1;
        }

        ast_channel_lock(chan);
        if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
            if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
                ast_channel_unlock(chan);
                return -1;
            }
            if (!(store = ast_calloc(1, sizeof(*store)))) {
                ast_channel_unlock(chan);
                ast_free(ds);
                return -1;
            }
            ds->data = store;
            ast_channel_datastore_add(chan, ds);
        } else {
            store = ds->data;
        }
        ast_channel_unlock(chan);

        if (!strcasecmp(data, "secure_bridge_signaling")) {
            store->signaling = ast_true(value) ? 1 : 0;
        } else if (!strcasecmp(data, "secure_bridge_media")) {
            store->media = ast_true(value) ? 1 : 0;
        }
    } else if (!chan->tech->func_channel_write
               || chan->tech->func_channel_write(chan, function, data, value)) {
        ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
                data);
        ret = -1;
    }

    return ret;
}
예제 #5
0
static int _parse (union misdn_cfg_pt *dest, const char *value, enum misdn_cfg_type type, int boolint_def)
{
	int re = 0;
	int len, tmp;
	char *valtmp;
	char *tmp2 = ast_strdupa(value);

	switch (type) {
	case MISDN_CTYPE_STR:
		if (dest->str) {
			ast_free(dest->str);
		}
		if ((len = strlen(value))) {
			dest->str = ast_malloc((len + 1) * sizeof(char));
			strncpy(dest->str, value, len);
			dest->str[len] = 0;
		} else {
			dest->str = ast_malloc(sizeof(char));
			dest->str[0] = 0;
		}
		break;
	case MISDN_CTYPE_INT:
	{
		int res;

		if (strchr(value,'x')) {
			res = sscanf(value, "%30x", &tmp);
		} else {
			res = sscanf(value, "%30d", &tmp);
		}
		if (res) {
			if (!dest->num) {
				dest->num = ast_malloc(sizeof(int));
			}
			memcpy(dest->num, &tmp, sizeof(int));
		} else
			re = -1;
	}
		break;
	case MISDN_CTYPE_BOOL:
		if (!dest->num) {
			dest->num = ast_malloc(sizeof(int));
		}
		*(dest->num) = (ast_true(value) ? 1 : 0);
		break;
	case MISDN_CTYPE_BOOLINT:
		if (!dest->num) {
			dest->num = ast_malloc(sizeof(int));
		}
		if (sscanf(value, "%30d", &tmp)) {
			memcpy(dest->num, &tmp, sizeof(int));
		} else {
			*(dest->num) = (ast_true(value) ? boolint_def : 0);
		}
		break;
	case MISDN_CTYPE_MSNLIST:
		for (valtmp = strsep(&tmp2, ","); valtmp; valtmp = strsep(&tmp2, ",")) {
			if ((len = strlen(valtmp))) {
				struct msn_list *ml = ast_malloc(sizeof(*ml));
				ml->msn = ast_calloc(len+1, sizeof(char));
				strncpy(ml->msn, valtmp, len);
				ml->next = dest->ml;
				dest->ml = ml;
			}
		}
		break;
	case MISDN_CTYPE_ASTGROUP:
		if (!dest->grp) {
			dest->grp = ast_malloc(sizeof(ast_group_t));
		}
		*(dest->grp) = ast_get_group(value);
		break;
	case MISDN_CTYPE_ASTNAMEDGROUP:
		dest->namgrp = ast_get_namedgroups(value);
		break;
	}

	return re;
}