示例#1
0
static void 
out_result(int ret)
{
    switch (ret) {
    case NE_OK:
	printf("succeeded.\n");
	break;
    case NE_AUTH:
    case NE_PROXYAUTH:
	printf("authentication failed.\n");
	break;
    case NE_CONNECT:
	printf("could not connect to server.\n");
	break;
    case NE_TIMEOUT:
	printf("connection timed out.\n");
	break;
    default:
        if (ret == NE_REDIRECT) {
            const ne_uri *dest = ne_redirect_location(session.sess);
            if (dest) {
                char *uri = ne_uri_unparse(dest);
                printf("redirect to %s\n", uri);
                ne_free(uri);
                break;
            }
        }
	printf("failed:  %s\n", ne_get_error(session.sess));
	break;
    }
}
static gboolean
gst_neonhttp_src_set_location (GstNeonhttpSrc * src, const gchar * uri,
                               GError ** err)
{
    ne_uri_free (&src->uri);
    if (src->location) {
        ne_free (src->location);
        src->location = NULL;
    }
    if (src->query_string) {
        ne_free (src->query_string);
        src->query_string = NULL;
    }

    if (ne_uri_parse (uri, &src->uri) != 0)
        goto parse_error;

    if (src->uri.scheme == NULL)
        src->uri.scheme = g_strdup ("http");

    if (src->uri.host == NULL)
        src->uri.host = g_strdup (DEFAULT_LOCATION);

    if (src->uri.port == 0) {
        if (!strcmp (src->uri.scheme, "https"))
            src->uri.port = HTTPS_DEFAULT_PORT;
        else
            src->uri.port = HTTP_DEFAULT_PORT;
    }

    if (!src->uri.path)
        src->uri.path = g_strdup ("");

    src->query_string = g_strjoin ("?", src->uri.path, src->uri.query, NULL);

    src->location = ne_uri_unparse (&src->uri);

    return TRUE;

    /* ERRORS */
parse_error:
    {
        if (src->location) {
            ne_free (src->location);
            src->location = NULL;
        }
        if (src->query_string) {
            ne_free (src->query_string);
            src->query_string = NULL;
        }
        ne_uri_free (&src->uri);
        return FALSE;
    }
}
示例#3
0
static void lk_pre_send(ne_request *r, void *userdata, ne_buffer *req)
{
    struct lh_req_cookie *lrc = ne_get_request_private(r, HOOK_ID);

    if (lrc->submit != NULL) {
	struct lock_list *item;

	/* Add in the If header */
	ne_buffer_czappend(req, "If:");
	for (item = lrc->submit; item != NULL; item = item->next) {
	    char *uri = ne_uri_unparse(&item->lock->uri);
	    ne_buffer_concat(req, " <", uri, "> (<",
			     item->lock->token, ">)", NULL);
	    ne_free(uri);
	}
	ne_buffer_czappend(req, "\r\n");
    }
}
示例#4
0
文件: util.c 项目: DJEX93/dsploit
const char *
svn_ra_neon__uri_unparse(const ne_uri *uri,
                         apr_pool_t *pool)
{
  char *unparsed_uri;
  const char *result;

  /* Unparse uri. */
  unparsed_uri = ne_uri_unparse(uri);

  /* Copy string to result pool, and make sure it conforms to
     Subversion rules */
  result = svn_uri_canonicalize(unparsed_uri, pool);

  /* Free neon's allocated copy. */
  ne_free(unparsed_uri);

  /* Return string allocated in result pool. */
  return result;
}
示例#5
0
static int check_redir(struct redir_args *args, const char *expect)
{
    ne_session *sess;
    const ne_uri *loc;
    char *unp;

    CALL(make_session(&sess, serve_redir, args));
    ne_redirect_register(sess);

    CALL(process_redir(sess, args->path, &loc));
    ONN("redirect location was NULL", loc == NULL);

    unp = ne_uri_unparse(loc);
    ONV(strcmp(unp, expect), ("redirected to `%s' not `%s'", unp, expect));
    ne_free(unp);

    ne_session_destroy(sess);
    CALL(await_server());

    return OK;
}
示例#6
0
void ne_session_system_proxy(ne_session *sess, unsigned int flags)
{
#ifdef HAVE_LIBPROXY
    pxProxyFactory *pxf = px_proxy_factory_new();
    struct host_info *hi, **lasthi;
    char *url, **proxies;
    ne_uri uri;
    unsigned n;

    free_proxies(sess);

    /* Create URI for session to pass off to libproxy */
    memset(&uri, 0, sizeof uri);
    ne_fill_server_uri(sess, &uri);

    uri.path = "/"; /* make valid URI structure. */
    url = ne_uri_unparse(&uri);
    uri.path = NULL;

    /* Get list of pseudo-URIs from libproxy: */
    proxies = px_proxy_factory_get_proxies(pxf, url);
    
    for (n = 0, lasthi = &sess->proxies; proxies[n]; n++) {
        enum proxy_type ptype;

        ne_uri_free(&uri);

        NE_DEBUG(NE_DBG_HTTP, "sess: libproxy #%u=%s\n", 
                 n, proxies[n]);

        if (ne_uri_parse(proxies[n], &uri))
            continue;
        
        if (!uri.scheme) continue;

        if (ne_strcasecmp(uri.scheme, "http") == 0)
            ptype = PROXY_HTTP;
        else if (ne_strcasecmp(uri.scheme, "socks") == 0)
            ptype = PROXY_SOCKS;
        else if (ne_strcasecmp(uri.scheme, "direct") == 0)
            ptype = PROXY_NONE;
        else
            continue;

        /* Hostname/port required for http/socks schemes. */
        if (ptype != PROXY_NONE && !(uri.host && uri.port))
            continue;
        
        /* Do nothing if libproxy returned only a single "direct://"
         * entry -- a single "direct" (noop) proxy is equivalent to
         * having none. */
        if (n == 0 && proxies[1] == NULL && ptype == PROXY_NONE)
            break;

        NE_DEBUG(NE_DBG_HTTP, "sess: Got proxy %s://%s:%d\n",
                 uri.scheme, uri.host ? uri.host : "(none)",
                 uri.port);
        
        hi = *lasthi = ne_calloc(sizeof *hi);
        
        if (ptype == PROXY_NONE) {
            /* A "direct" URI requires an attempt to connect directly to
             * the origin server, so dup the server details. */
            set_hostinfo(hi, ptype, sess->server.hostname,
                         sess->server.port);
        }
        else {
            /* SOCKS/HTTP proxy. */
            set_hostinfo(hi, ptype, uri.host, uri.port);

            if (ptype == PROXY_HTTP)
                sess->any_proxy_http = 1;
            else if (ptype == PROXY_SOCKS)
                sess->socks_ver = NE_SOCK_SOCKSV5;
        }

        lasthi = &hi->next;
    }

    /* Free up the proxies array: */
    for (n = 0; proxies[n]; n++)
        free(proxies[n]);
    free(proxies[n]);

    ne_free(url);
    ne_uri_free(&uri);
    px_proxy_factory_free(pxf);
#endif
}
示例#7
0
static int fetch_resource_list( const char *uri,
                                int depth,
                                struct listdir_context *fetchCtx )
{
  int ret = 0;
  ne_propfind_handler *hdl = NULL;
  ne_request *request = NULL;
  const char *content_type = NULL;
  char *curi = NULL;
  const ne_status *req_status = NULL;

  curi = _cleanPath( uri );

  if (!fetchCtx) {
    errno = ENOMEM;
    SAFE_FREE(curi);
    return -1;
  }
  fetchCtx->list = NULL;
  fetchCtx->target = curi;
  fetchCtx->currResource = NULL;

  /* do a propfind request and parse the results in the results function, set as callback */
  hdl = ne_propfind_create(dav_session.ctx, curi, depth);

  if(hdl) {
    ret = ne_propfind_named(hdl, ls_props, results, fetchCtx);
    request = ne_propfind_get_request( hdl );
    req_status = ne_get_status( request );
  }

  if( ret == NE_OK ) {
    fetchCtx->currResource = fetchCtx->list;
    /* Check the request status. */
    if( req_status && req_status->klass != 2 ) {
      set_errno_from_http_errcode(req_status->code);
      DEBUG_WEBDAV("ERROR: Request failed: status %d (%s)", req_status->code,
                   req_status->reason_phrase);
      ret = NE_CONNECT;
      set_error_message(req_status->reason_phrase);
    }
    DEBUG_WEBDAV("Simple propfind result code %d.", req_status ? req_status->code : -1);
  } else {
    if( ret == NE_ERROR && req_status->code == 404) {
      errno = ENOENT;
    } else {
      set_errno_from_neon_errcode(ret);
    }
  }

  if( ret == NE_OK ) {
    /* Check the content type. If the server has a problem, ie. database is gone or such,
        * the content type is not xml but a html error message. Stop on processing if it's
        * not XML.
        * FIXME: Generate user error message from the reply content.
        */
    content_type =  ne_get_response_header( request, "Content-Type" );
    if( !(content_type && c_streq(content_type, "application/xml; charset=utf-8") ) ) {
      DEBUG_WEBDAV("ERROR: Content type of propfind request not XML: %s.",
                   content_type ?  content_type: "<empty>");
      errno = ERRNO_WRONG_CONTENT;
      set_error_message("Server error: PROPFIND reply is not XML formatted!");
      ret = NE_CONNECT;
    }
  }
#ifndef NDEBUG
  if( ret != NE_OK ) {
    const char *err = ne_get_error(dav_session.ctx);
    DEBUG_WEBDAV("WRN: propfind named failed with %d, request error: %s", ret, err ? err : "<nil>");
  }
#endif /* NDEBUG */

  if (hdl != NULL) {
    ne_propfind_destroy(hdl);
  }

#ifndef NDEBUG
  if (ret == NE_REDIRECT) {
    const ne_uri *redir_ne_uri = ne_redirect_location(dav_session.ctx);
    if (redir_ne_uri) {
      char *redir_uri = ne_uri_unparse(redir_ne_uri);
      DEBUG_WEBDAV("Permanently moved to %s", redir_uri);
    }
  }
#endif /* NDEBUG */

  if( ret != NE_OK ) {
    free_fetchCtx(fetchCtx);
    return -1;
  }

  return 0;
}
static void
gst_neonhttp_src_get_property (GObject * object, guint prop_id,
                               GValue * value, GParamSpec * pspec)
{
    GstNeonhttpSrc *neonhttpsrc = GST_NEONHTTP_SRC (object);

    switch (prop_id) {
    case PROP_PROXY:
    {
        gchar *str;

        if (neonhttpsrc->proxy.host) {
            str = ne_uri_unparse (&neonhttpsrc->proxy);
            if (!str)
                break;
            g_value_set_string (value, str);
            ne_free (str);
        } else {
            g_value_set_static_string (value, "");
        }
        break;
    }
    case PROP_LOCATION:
    {
        gchar *str;

        if (neonhttpsrc->uri.host) {
            str = ne_uri_unparse (&neonhttpsrc->uri);
            if (!str)
                break;
            g_value_set_string (value, str);
            ne_free (str);
        } else {
            g_value_set_static_string (value, "");
        }
        break;
    }
    case PROP_USER_AGENT:
        g_value_set_string (value, neonhttpsrc->user_agent);
        break;
    case PROP_COOKIES:
        g_value_set_boxed (value, neonhttpsrc->cookies);
        break;
    case PROP_AUTOMATIC_REDIRECT:
        g_value_set_boolean (value, neonhttpsrc->automatic_redirect);
        break;
    case PROP_ACCEPT_SELF_SIGNED:
        g_value_set_boolean (value, neonhttpsrc->accept_self_signed);
        break;
    case PROP_CONNECT_TIMEOUT:
        g_value_set_uint (value, neonhttpsrc->connect_timeout);
        break;
    case PROP_READ_TIMEOUT:
        g_value_set_uint (value, neonhttpsrc->read_timeout);
        break;
#ifndef GST_DISABLE_GST_DEBUG
    case PROP_NEON_HTTP_DEBUG:
        g_value_set_boolean (value, neonhttpsrc->neon_http_debug);
        break;
#endif
    case PROP_IRADIO_MODE:
        g_value_set_boolean (value, neonhttpsrc->iradio_mode);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}