Пример #1
0
char *xcap_uri_for_rls_resource(const str_t *xcap_root, const str_t *uri)
{
	dstring_t s;
	int l;
	str_t c_uri;
	char *dst = NULL;

	if (!xcap_root) return NULL;
	dstr_init(&s, 2 * xcap_root->len + 32);
	dstr_append_str(&s, xcap_root);
	if (xcap_root->s[xcap_root->len - 1] != '/') dstr_append(&s, "/", 1);
	dstr_append_zt(&s, "rls-services/global/index/~~/rls-services/service[@uri=%22");
	canonicalize_uri(uri, &c_uri);
	dstr_append_str(&s, &c_uri);
	if (c_uri.s) cds_free(c_uri.s);
	
	dstr_append_zt(&s, "%22]");
	l = dstr_get_data_length(&s);
	if (l > 0) {
		dst = (char *)cds_malloc(l + 1);
		if (dst) {
			dstr_get_data(&s, dst);
			dst[l] = 0;
		}
	}
	dstr_destroy(&s);
	return dst;
}
Пример #2
0
char *xcap_uri_for_rls_services(const str_t *xcap_root)
{
	dstring_t s;
	int l;
	char *dst = NULL;

	if (!xcap_root) return NULL;
	dstr_init(&s, 2 * xcap_root->len + 32);
	dstr_append_str(&s, xcap_root);
	if (xcap_root->s[xcap_root->len - 1] != '/') dstr_append(&s, "/", 1);
	dstr_append_zt(&s, "rls-services/global/index");
	
	l = dstr_get_data_length(&s);
	if (l > 0) {
		dst = (char *)cds_malloc(l + 1);
		if (dst) {
			dstr_get_data(&s, dst);
			dst[l] = 0;
		}
	}
	dstr_destroy(&s);
	return dst;
}
Пример #3
0
int xcap_query_impl(const char *uri, xcap_query_params_t *params, char **buf, int *bsize)
{
    CURLcode res = -1;
    static CURL *handle = NULL;
    dstring_t data;
    char *auth = NULL;
    int i;
    long auth_methods;

    if (!uri) {
        ERR("BUG: no uri given\n");
        return -1;
    }
    if (!buf) {
        ERR("BUG: no buf given\n");
        return -1;
    }

    i = 0;
    if (params) {
        i += params->auth_user.len;
        i += params->auth_pass.len;
    }
    if (i > 0) {
        /* do authentication */
        auth = (char *)cds_malloc_pkg(i + 2);
        if (!auth) return -1;
        sprintf(auth, "%.*s:%.*s", FMT_STR(params->auth_user),
                FMT_STR(params->auth_pass));
    }

    auth_methods = CURLAUTH_BASIC | CURLAUTH_DIGEST;

    dstr_init(&data, 512);

    if (!handle) handle = curl_easy_init();
    if (handle) {
        curl_easy_setopt(handle, CURLOPT_URL, uri);
        /* TRACE_LOG("uri: %s\n", uri ? uri : "<null>"); */

        /* do not store data into a file - store them in memory */
        curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data_func);
        curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data);

        /* be quiet */
#ifdef CURLOPT_MUTE
        curl_easy_setopt(handle, CURLOPT_MUTE, 1);
#endif /* CURLOPT_MUTE */

        /* non-2xx => error */
        curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1);

        /* auth */
        curl_easy_setopt(handle, CURLOPT_HTTPAUTH, auth_methods); /* TODO possibility of selection */
        curl_easy_setopt(handle, CURLOPT_NETRC, CURL_NETRC_IGNORED);
        curl_easy_setopt(handle, CURLOPT_USERPWD, auth);

        /* SSL */
        if (params) {
            if (params->enable_unverified_ssl_peer) {
                curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
                curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0);
            }
        }

        /* follow redirects (needed for apache mod_speling - case insesitive names) */
        curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);

        /*	curl_easy_setopt(handle, CURLOPT_TCP_NODELAY, 1);
        	curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 10);*/

        /* Accept headers */

        res = curl_easy_perform(handle);
        /* curl_easy_cleanup(handle); */ /* FIXME: experimental */
    }
    else ERROR_LOG("can't initialize curl handle\n");
    if (res == 0) {
        *bsize = dstr_get_data_length(&data);
        if (*bsize) {
            *buf = (char*)cds_malloc(*bsize);
            if (!*buf) {
                ERROR_LOG("can't allocate %d bytes\n", *bsize);
                res = -1;
                *bsize = 0;
            }
            else dstr_get_data(&data, *buf);
        }
    }
    else DBG("curl error: %d\n", res); /* see curl/curl.h for possible values*/
    dstr_destroy(&data);
    if (auth) cds_free_pkg(auth);
    return res;
}
Пример #4
0
int get_serialized_sstream_data(sstream_t *ss, char *dst)
{
	if (ss->type == sstream_out) return dstr_get_data(&ss->out, dst);
	else return -1; /* no output for input stream */
}