Пример #1
0
int mi_xmlrpc_http_answer_to_connection (void *cls, void *connection,
		const char *url, const char *method,
		const char *version, const char *upload_data,
		size_t *upload_data_size, void **con_cls,
		str *buffer, str *page)
{
	str arg = {NULL, 0};
	struct mi_root *tree = NULL;
	struct mi_handler *async_hdl;
	int ret_code = MI_XMLRPC_OK;

	LM_DBG("START *** cls=%p, connection=%p, url=%s, method=%s, "
		"versio=%s, upload_data[%d]=%p, *con_cls=%p\n",
			cls, connection, url, method, version,
			(int)*upload_data_size, upload_data, *con_cls);
	if (strncmp(method, "POST", 4)==0) {
		httpd_api.lookup_arg(connection, "1", *con_cls, &arg);
		if (arg.s) {
			tree = mi_xmlrpc_http_run_mi_cmd(&arg,
						page, buffer, &async_hdl);
			if (tree == NULL) {
				LM_ERR("no reply\n");
				*page = MI_XMLRPC_U_ERROR;
				ret_code = MI_XMLRPC_INTERNAL_ERROR;
			} else if (tree == MI_ROOT_ASYNC_RPL) {
				LM_DBG("got an async reply\n");
				tree = NULL;
			} else {
				LM_DBG("building on page [%p:%d]\n",
					page->s, page->len);
				if(0!=mi_xmlrpc_http_build_page(page, buffer->len, tree)){
					LM_ERR("unable to build response\n");
					*page = MI_XMLRPC_U_ERROR;
					ret_code = MI_XMLRPC_INTERNAL_ERROR;
				} else {
					ret_code = tree->code;
				}
			}
		} else {
			page->s = buffer->s;
			LM_ERR("unable to build response for empty request\n");
			*page = MI_XMLRPC_U_ERROR;
			ret_code = MI_XMLRPC_INTERNAL_ERROR;
		}
		if (tree) {
			free_mi_tree(tree);
			tree = NULL;
		}
	} else {
		LM_ERR("unexpected method [%s]\n", method);
		*page = MI_XMLRPC_U_METHOD;
		return MI_XMLRPC_NOT_ACCEPTABLE;
	}

	return ret_code;
}
Пример #2
0
static int mod_init(void)
{
	http_root.len = strlen(http_root.s);

	/* Load httpd api */
	if(load_httpd_api(&httpd_api)<0) {
		LM_ERR("Failed to load httpd api\n");
		return -1;
	}
	/* Load httpd hooks */
	httpd_api.register_httpdcb(exports.name, &http_root,
				&mi_xmlrpc_http_answer_to_connection,
				&mi_xmlrpc_http_flush_data,
				&proc_init);

	return 0;
}
Пример #3
0
static int mod_init(void)
{
	http_root.len = strlen(http_root.s);

	if (http_method<0 || http_method>1) {
		LM_ERR("mi_http_method can be between [0,1]\n");
		return -1;
	}
	/* Load httpd api */
	if(load_httpd_api(&httpd_api)<0) {
		LM_ERR("Failed to load httpd api\n");
		return -1;
	}
	/* Load httpd hooks */
	httpd_api.register_httpdcb(exports.name, &http_root,
				&mi_http_answer_to_connection,
				&mi_http_flush_data,
				&proc_init);

	return 0;
}
Пример #4
0
void mi_http_answer_to_connection (void *cls, void *connection,
		const char *url, const char *method,
		const char *version, const char *upload_data,
		size_t *upload_data_size, void **con_cls,
		str *buffer, str *page)
{
	int mod = -1;
	int cmd = -1;
	str arg = {NULL, 0};
	struct mi_root *tree = NULL;
	struct mi_handler *async_hdl;

	LM_DBG("START *** cls=%p, connection=%p, url=%s, method=%s, "
		"versio=%s, upload_data[%d]=%p, *con_cls=%p\n",
			cls, connection, url, method, version,
			(int)*upload_data_size, upload_data, *con_cls);
	if (strncmp(method, "GET", 3)==0 || strncmp(method, "POST", 4)==0) {
		if(0 == mi_http_parse_url(url, &mod, &cmd)) {
			httpd_api.lookup_arg(connection, "arg", *con_cls, &arg);
			if (mod>=0 && cmd>=0 && arg.s) {
				LM_DBG("arg [%p]->[%.*s]\n", arg.s, arg.len, arg.s);
				tree = mi_http_run_mi_cmd(mod, cmd, &arg,
							page, buffer, &async_hdl);
				if (tree == NULL) {
					LM_ERR("no reply\n");
					*page = MI_HTTP_U_ERROR;
				} else if (tree == MI_ROOT_ASYNC_RPL) {
					LM_DBG("got an async reply\n");
					tree = NULL;
				} else {
					LM_DBG("building on page [%p:%d]\n",
						page->s, page->len);
					if(0!=mi_http_build_page(page, buffer->len,
								mod, cmd, tree)){
						LM_ERR("unable to build response "
							"for cmd [%d] w/ args [%.*s]\n",
							cmd,
							arg.len, arg.s);
						*page = MI_HTTP_U_ERROR;
					}
				}
			} else {
				page->s = buffer->s;
				if(0 != mi_http_build_page(page, buffer->len,
							mod, cmd, tree)) {
					LM_ERR("unable to build response\n");
					*page = MI_HTTP_U_ERROR;
				}
			}
			if (tree) {
				free_mi_tree(tree);
				tree = NULL;
			}
		} else {
			LM_ERR("unable to parse URL [%s]\n", url);
			*page = MI_HTTP_U_URL;
		}
	} else {
		LM_ERR("unexpected method [%s]\n", method);
		*page = MI_HTTP_U_METHOD;
	}

	return;
}
Пример #5
0
void mi_json_answer_to_connection (void *cls, void *connection,
    const char *url, const char *method,
    const char *version, const char *upload_data,
    size_t *upload_data_size, void **con_cls,
    str *buffer, str *page)
{
	str command = {NULL, 0};
	str params = {NULL, 0};
	struct mi_cmd *f = NULL;
	struct mi_root *tree = NULL;
	struct mi_handler *async_hdl;

	LM_DBG("START *** cls=%p, connection=%p, url=%s, method=%s, "
			"versio=%s, upload_data[%d]=%p, *con_cls=%p\n",
			cls, connection, url, method, version,
			(int)*upload_data_size, upload_data, *con_cls);
	if (strncmp(method, "GET", 3)==0) {
		if(url && url[0] == '/' && url[1] != '\0') {
			command.s = (char*)url+1;
			command.len = strlen(command.s);
		}
		httpd_api.lookup_arg(connection, "params", *con_cls, &params);
		if (command.s) {

			f = lookup_mi_cmd(command.s, command.len);
			if (f == NULL) {
				LM_ERR("unable to find mi command [%.*s]\n", command.len, command.s);
				*page = MI_HTTP_U_NOT_FOUND;
			} else {

				tree = mi_json_run_mi_cmd(f, &command,&params,
						page, buffer, &async_hdl);
				if (tree == NULL) {
					LM_ERR("no reply\n");
					*page = MI_HTTP_U_ERROR;
				} else if (tree == MI_ROOT_ASYNC_RPL) {
					LM_DBG("got an async reply\n");
					tree = NULL;
				} else {
					LM_DBG("building on page [%p:%d]\n",
							page->s, page->len);
					if(0!=mi_json_build_page(page, buffer->len, tree)){
						LM_ERR("unable to build response\n");
						*page = MI_HTTP_U_ERROR;
					}
				}
			}
		} else {
			page->s = buffer->s;
			LM_ERR("unable to build response for empty request\n");
			*page = MI_HTTP_U_ERROR;
		}
		if (tree) {
			free_mi_tree(tree);
			tree = NULL;
		}
	} else {
		LM_ERR("unexpected method [%s]\n", method);
		*page = MI_HTTP_U_METHOD;
	}

	return;
}