static char *acf_curl_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
	struct localuser *u;
	char *info, *post_data=NULL, *url;
	struct MemoryStruct chunk = { NULL, 0 };

	*buf = '\0';
	
	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "CURL requires an argument (URL)\n");
		return buf;
	}

	LOCAL_USER_ACF_ADD(u);

	info = ast_strdupa(data);
	if (!info) {
		ast_log(LOG_ERROR, "Out of memory\n");
		LOCAL_USER_REMOVE(u);
		return buf;
	}
	
	url = strsep(&info, "|");
	post_data = info;
	
	if (! curl_internal(&chunk, url, post_data)) {
		if (chunk.memory) {
			chunk.memory[chunk.size] = '\0';
			if (chunk.memory[chunk.size - 1] == 10)
				chunk.memory[chunk.size - 1] = '\0';

			ast_copy_string(buf, chunk.memory, len);
			free(chunk.memory);
		}
	} else {
		ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
	}

	LOCAL_USER_REMOVE(u);
	return buf;
}
Пример #2
0
static char *acf_sort_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
	struct localuser *u;

	LOCAL_USER_ACF_ADD(u);

	switch (sort_internal(chan, data, buf, len)) {
	case ERROR_NOARG:
		ast_log(LOG_ERROR, "SORT() requires an argument\n");
		break;
	case ERROR_NOMEM:
		ast_log(LOG_ERROR, "Out of memory\n");
		break;
	case 0:
		break;
	default:
		ast_log(LOG_ERROR, "Unknown internal error\n");
	}
	LOCAL_USER_REMOVE(u);
	return buf;
}
Пример #3
0
static char *acf_vmcount_exec(struct cw_channel *chan, int argc, char **argv, char *buf, size_t len)
{
    struct localuser *u;
    char *context;

    if (argc < 1 || argc > 2 || !argv[0][0]) {
        cw_log(LOG_ERROR, "Syntax: %s\n", vmcount_func_syntax);
        return NULL;
    }

    LOCAL_USER_ACF_ADD(u);

    buf[0] = '\0';

    if ((context = strchr(argv[0], '@')))
        *(context++) = '\0';
    else
        context = "default";

    snprintf(buf, len, "%d", hasvoicemail_internal(context, argv[0], (argc > 1 && argv[1][0] ? argv[1] : "INBOX")));

    LOCAL_USER_REMOVE(u);
    return buf;
}
char *acf_nconfcount_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) {
	struct localuser *u;
	char *info, *options=NULL, *confno;
	char tmpbuf[16];

	*buf = '\0';
	
	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "NCONFCOUNT requires an argument (confno)\n");
		return buf;
	}

	LOCAL_USER_ACF_ADD(u);

	info = ast_strdupa(data);
	if (!info) {
		ast_log(LOG_ERROR, "Out of memory\n");
		LOCAL_USER_REMOVE(u);
		return buf;
	}
	
	confno = strsep(&info, "|");
	options = info;

	struct ast_conference *conf = find_conf(confno);
	if (conf == NULL) {
		LOCAL_USER_REMOVE(u);
		return buf;
	}

	if (ast_strlen_zero(options)) {
		/* Count All Members */
		snprintf(tmpbuf, 15, "%d", conf->membercount);
		ast_copy_string(buf, tmpbuf, len);
	} else {
		/* Count Certain types of Members */
		int i;
		short counter = 0;
		struct ast_conf_member *member_list = conf->memberlist;
		while (member_list) {

			for ( i = 0 ; i < strlen(options) ; ++i ) {
				switch (options[i]) {
				case 'M':
					if (member_list->type == MEMBERTYPE_MASTER) {
						++counter;
					}
					break ;
				case 'S':
					if (member_list->type == MEMBERTYPE_SPEAKER) {
						++counter;
					}
					break ;
				case 'L':
					if (member_list->type == MEMBERTYPE_LISTENER) {
						++counter;
					}
					break ;
				case 'T':
					if (member_list->type == MEMBERTYPE_TALKER) {
						++counter;
					}
					break ;
				case 'C':
					if (member_list->type == MEMBERTYPE_CONSULTANT) {
						++counter;
					}
					break ;
				default:
					ast_log(LOG_WARNING, "Unknown option '%c'.\n", options[i]);
				}
			}

			member_list = member_list->next;
		}
		snprintf(tmpbuf, 15, "%d", counter);
		ast_copy_string(buf, tmpbuf, len);
	}

	LOCAL_USER_REMOVE(u);
	return buf;
}