static gboolean gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, const char *uri) { ne_uri_free (&src->proxy); if (ne_uri_parse (uri, &src->proxy) != 0) goto error; if (src->proxy.scheme) GST_WARNING ("The proxy schema shouldn't be defined (schema is '%s')", src->proxy.scheme); if (src->proxy.host && !src->proxy.port) goto error; if (!src->proxy.path || src->proxy.userinfo) goto error; return TRUE; /* ERRORS */ error: { ne_uri_free (&src->proxy); return FALSE; } }
/* Assign URL to RSRC. Use POOL for any allocations. */ static svn_error_t * assign_rsrc_url(svn_ra_neon__resource_t *rsrc, const char *url, apr_pool_t *pool) { char *url_path; apr_size_t len; ne_uri parsed_url; /* Parse the PATH element out of the URL. NOTE: mod_dav does not (currently) use an absolute URL, but simply a server-relative path (i.e. this uri_parse is effectively a no-op). */ if (ne_uri_parse(url, &parsed_url) != 0) { ne_uri_free(&parsed_url); return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Unable to parse URL '%s'"), url); } url_path = apr_pstrdup(pool, parsed_url.path); ne_uri_free(&parsed_url); /* Clean up trailing slashes from the URL. */ len = strlen(url_path); if (len > 1 && url_path[len - 1] == '/') url_path[len - 1] = '\0'; rsrc->url = url_path; return SVN_NO_ERROR; }
void get(const StringSlice& url, WriteTarget out) { static int inited = ne_sock_init(); if (inited != 0) { throw Exception("ne_sock_init()"); } CString cstr(url); ne_uri uri = {}; if (ne_uri_parse(cstr.data(), &uri)) { throw Exception("ne_uri_parse()"); } if (uri.port == 0) { uri.port = ne_uri_defaultport(uri.scheme); } unique_ptr<ne_uri, decltype(&ne_uri_free)> uri_free(&uri, ne_uri_free); unique_ptr<ne_session, decltype(&ne_session_destroy)> sess( ne_session_create(uri.scheme, uri.host, uri.port), ne_session_destroy); unique_ptr<ne_request, decltype(&ne_request_destroy)> req( ne_request_create(sess.get(), "GET", uri.path), ne_request_destroy); ne_userdata userdata = {out}; ne_add_response_body_reader(req.get(), accept, reader, &userdata); auto err = ne_request_dispatch(req.get()); if (err != NE_OK) { throw Exception("ne_request_dispatch()"); } auto* st = ne_get_status(req.get()); if (st->code != 200) { throw Exception(st->code); } }
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; } }
static void *ld_create(void *userdata, const char *href) { struct discover_ctx *ctx = userdata; struct ne_lock *lk = ne_lock_create(); if (ne_uri_parse(href, &lk->uri) != 0) { ne_lock_destroy(lk); return NULL; } if (!lk->uri.host) ne_fill_server_uri(ctx->session, &lk->uri); return lk; }
int session_set_uri(const char *s, const char *u, const char *p) { int l; assert(!b_uri); assert(!username); assert(!password); if (ne_uri_parse(s, &uri)) { fprintf(stderr, "Invalid URI <%s>\n", s); goto finish; } b_uri = 1; if (!uri.host) { fprintf(stderr, "Missing host part in URI <%s>\n", s); goto finish; } base_directory = strdup(uri.path); l = strlen(base_directory); if (base_directory[l-1] == '/') ((char*) base_directory)[l-1] = 0; if (u) username = strdup(u); if (p) password = strdup(p); return 0; finish: if (b_uri) { ne_uri_free(&uri); b_uri = 0; } return -1; }
svn_error_t * svn_ra_neon__get_url_path(const char **urlpath, const char *url, apr_pool_t *pool) { ne_uri parsed_url; svn_error_t *err = SVN_NO_ERROR; ne_uri_parse(url, &parsed_url); if (parsed_url.path) { *urlpath = apr_pstrdup(pool, parsed_url.path); } else { err = svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("Neon was unable to parse URL '%s'"), url); } ne_uri_free(&parsed_url); return err; }
int init(void) { ne_uri u = {0}, proxy = {0}; int optc, n; char *proxy_url = NULL; char str[64], *src; int i; if ((times1=malloc(sizeof(float)*pget_option.requests)) == NULL){ perror("malloc(times1) :"); exit(-1); } if ((times2=malloc(sizeof(float)*pget_option.requests)) == NULL){ perror("malloc(times2) :"); exit(-1); } while ((optc = getopt_long(test_argc, test_argv, "d:hp", longopts, NULL)) != -1) { switch (optc) { case 'd': htdocs_root = optarg; break; case 'p': proxy_url = optarg; break; default: exit(1); } } n = test_argc - optind; if (n == 0 || n > 3 || n == 2) { exit(1); } if (htdocs_root == NULL) htdocs_root = "htdocs"; if (ne_uri_parse(test_argv[optind], &u)) { t_context("couldn't parse server URL `%s'", test_argv[optind]); return FAILHARD; } if (proxy_url) { if (ne_uri_parse(proxy_url, &proxy)) { t_context("couldn't parse proxy URL `%s'", proxy_url); return FAILHARD; } if (proxy.scheme && strcmp(proxy.scheme, "http") != 0) { t_context("cannot use scheme `%s' for proxy", proxy.scheme); return FAILHARD; } if (proxy.port > 0) { proxy_port = proxy.port; } else { proxy_port = 8080; } proxy_hostname = proxy.host; } if (u.scheme && strcmp(u.scheme, "https") == 0) use_secure = 1; i_hostname = u.host; if (u.port > 0) { i_port = u.port; } else { if (use_secure) { i_port = 443; } else { i_port = 80; } } if (ne_path_has_trailing_slash(u.path)) { i_path = u.path; } else { i_path = ne_concat(u.path, "/", NULL); } i_path = ne_path_escape(i_path); if (n > 2) { i_username = test_argv[optind+1]; i_password = test_argv[optind+2]; if (strlen(i_username) >= NE_ABUFSIZ) { t_context("username must be <%d chars", NE_ABUFSIZ); return FAILHARD; } if (strlen(i_password) >= NE_ABUFSIZ) { t_context("password must be <%d chars", NE_ABUFSIZ); return FAILHARD; } } if (proxy_hostname) CALL(test_resolve(proxy_hostname, "proxy server")); else CALL(test_resolve(i_hostname, "server")); CALL(open_foo()); CALL(test_connect()); printf("Done\n"); return OK; }
static int open_handle (struct neon_handle * handle, uint64_t startbyte) { int ret; char * proxy_host = NULL; int proxy_port = 0; bool_t use_proxy = aud_get_bool (NULL, "use_proxy"); bool_t use_proxy_auth = aud_get_bool (NULL, "use_proxy_auth"); if (use_proxy) { proxy_host = aud_get_str (NULL, "proxy_host"); proxy_port = aud_get_int (NULL, "proxy_port"); } handle->redircount = 0; _DEBUG ("<%p> Parsing URL", handle); if (ne_uri_parse (handle->url, handle->purl) != 0) { _ERROR ("<%p> Could not parse URL '%s'", (void *) handle, handle->url); return -1; } while (handle->redircount < 10) { if (! handle->purl->port) handle->purl->port = ne_uri_defaultport (handle->purl->scheme); _DEBUG ("<%p> Creating session to %s://%s:%d", handle, handle->purl->scheme, handle->purl->host, handle->purl->port); handle->session = ne_session_create (handle->purl->scheme, handle->purl->host, handle->purl->port); ne_redirect_register (handle->session); ne_add_server_auth (handle->session, NE_AUTH_BASIC, server_auth_callback, (void *) handle); ne_set_session_flag (handle->session, NE_SESSFLAG_ICYPROTO, 1); ne_set_session_flag (handle->session, NE_SESSFLAG_PERSIST, 0); #ifdef HAVE_NE_SET_CONNECT_TIMEOUT ne_set_connect_timeout (handle->session, 10); #endif ne_set_read_timeout (handle->session, 10); ne_set_useragent (handle->session, "Audacious/" PACKAGE_VERSION); if (use_proxy) { _DEBUG ("<%p> Using proxy: %s:%d", handle, proxy_host, proxy_port); ne_session_proxy (handle->session, proxy_host, proxy_port); if (use_proxy_auth) { _DEBUG ("<%p> Using proxy authentication", handle); ne_add_proxy_auth (handle->session, NE_AUTH_BASIC, neon_proxy_auth_cb, (void *) handle); } } if (! strcmp ("https", handle->purl->scheme)) { ne_ssl_trust_default_ca (handle->session); ne_ssl_set_verify (handle->session, neon_vfs_verify_environment_ssl_certs, handle->session); } _DEBUG ("<%p> Creating request", handle); ret = open_request (handle, startbyte); if (! ret) { str_unref (proxy_host); return 0; } if (ret == -1) { ne_session_destroy (handle->session); handle->session = NULL; str_unref (proxy_host); return -1; } _DEBUG ("<%p> Following redirect...", handle); ne_session_destroy (handle->session); handle->session = NULL; } /* If we get here, our redirect count exceeded */ _ERROR ("<%p> Redirect count exceeded for URL %s", (void *) handle, handle->url); str_unref (proxy_host); return 1; }
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 }
/* Check certificate identity. Returns zero if identity matches; 1 if * identity does not match, or <0 if the certificate had no identity. * If 'identity' is non-NULL, store the malloc-allocated identity in * *identity. Logic specified by RFC 2818 and RFC 3280. */ static int check_identity(const ne_uri *server, X509 *cert, char **identity) { STACK_OF(GENERAL_NAME) *names; int match = 0, found = 0; const char *hostname; hostname = server ? server->host : ""; names = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL); if (names) { int n; /* subjectAltName contains a sequence of GeneralNames */ for (n = 0; n < sk_GENERAL_NAME_num(names) && !match; n++) { GENERAL_NAME *nm = sk_GENERAL_NAME_value(names, n); /* handle dNSName and iPAddress name extensions only. */ if (nm->type == GEN_DNS) { char *name = dup_ia5string(nm->d.ia5); if (identity && !found) *identity = ne_strdup(name); match = ne__ssl_match_hostname(name, strlen(name), hostname); free(name); found = 1; } else if (nm->type == GEN_IPADD) { /* compare IP address with server IP address. */ ne_inet_addr *ia; if (nm->d.ip->length == 4) ia = ne_iaddr_make(ne_iaddr_ipv4, nm->d.ip->data); else if (nm->d.ip->length == 16) ia = ne_iaddr_make(ne_iaddr_ipv6, nm->d.ip->data); else ia = NULL; /* ne_iaddr_make returns NULL if address type is unsupported */ if (ia != NULL) { /* address type was supported. */ char buf[128]; match = strcmp(hostname, ne_iaddr_print(ia, buf, sizeof buf)) == 0; found = 1; ne_iaddr_free(ia); } else { NE_DEBUG(NE_DBG_SSL, "iPAddress name with unsupported " "address type (length %d), skipped.\n", nm->d.ip->length); } } else if (nm->type == GEN_URI) { char *name = dup_ia5string(nm->d.ia5); ne_uri uri; if (ne_uri_parse(name, &uri) == 0 && uri.host && uri.scheme) { ne_uri tmp; if (identity && !found) *identity = ne_strdup(name); found = 1; if (server) { /* For comparison purposes, all that matters is * host, scheme and port; ignore the rest. */ memset(&tmp, 0, sizeof tmp); tmp.host = uri.host; tmp.scheme = uri.scheme; tmp.port = uri.port; match = ne_uri_cmp(server, &tmp) == 0; } } ne_uri_free(&uri); free(name); } } /* free the whole stack. */ sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); } /* Check against the commonName if no DNS alt. names were found, * as per RFC3280. */ if (!found) { X509_NAME *subj = X509_get_subject_name(cert); X509_NAME_ENTRY *entry; ne_buffer *cname = ne_buffer_ncreate(30); int idx = -1, lastidx; /* find the most specific commonName attribute. */ do { lastidx = idx; idx = X509_NAME_get_index_by_NID(subj, NID_commonName, lastidx); } while (idx >= 0); if (lastidx < 0) { /* no commonName attributes at all. */ ne_buffer_destroy(cname); return -1; } /* extract the string from the entry */ entry = X509_NAME_get_entry(subj, lastidx); if (append_dirstring(cname, X509_NAME_ENTRY_get_data(entry))) { ne_buffer_destroy(cname); return -1; } if (identity) *identity = ne_strdup(cname->data); match = ne__ssl_match_hostname(cname->data, cname->used - 1, hostname); ne_buffer_destroy(cname); } NE_DEBUG(NE_DBG_SSL, "Identity match for '%s': %s\n", hostname, match ? "good" : "bad"); return match ? 0 : 1; }
void upsdrv_initups(void) { int ret; char *val; FILE *fp; #if HAVE_NE_SET_CONNECT_TIMEOUT && HAVE_NE_SOCK_CONNECT_TIMEOUT /* we don't need to use alarm() */ #else struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = netxml_alarm_handler; sigaction(SIGALRM, &sa, NULL); #endif /* allow override of default network timeout value */ val = getval("timeout"); if (val) { timeout = atoi(val); if (timeout < 1) { fatalx(EXIT_FAILURE, "timeout must be greater than 0"); } } val = getval("shutdown_duration"); if (val) { shutdown_duration = atoi(val); if (shutdown_duration < 0) { fatalx(EXIT_FAILURE, "shutdown duration must be greater than or equal to 0"); } } val = getval("shutdown_timer"); if (val) { shutdown_timer = atoi(val); if (shutdown_timer < 0) { fatalx(EXIT_FAILURE, "shutdown timer must be greater than or equal to 0"); } } if (nut_debug_level > 5) { ne_debug_init(stderr, NE_DBG_HTTP | NE_DBG_HTTPBODY); } if (ne_sock_init()) { fatalx(EXIT_FAILURE, "%s: failed to initialize socket libraries", progname); } if (ne_uri_parse(device_path, &uri) || uri.host == NULL) { fatalx(EXIT_FAILURE, "%s: invalid hostname '%s'", progname, device_path); } /* if (uri.scheme == NULL) { uri.scheme = strdup("http"); } if (uri.host == NULL) { uri.host = strdup(device_path); } */ if (uri.port == 0) { uri.port = ne_uri_defaultport(uri.scheme); } upsdebugx(1, "using %s://%s port %d", uri.scheme, uri.host, uri.port); session = ne_session_create(uri.scheme, uri.host, uri.port); /* timeout if we can't (re)connect to the UPS */ #ifdef HAVE_NE_SET_CONNECT_TIMEOUT ne_set_connect_timeout(session, timeout); #endif /* just wait for a couple of seconds */ ne_set_read_timeout(session, timeout); ne_set_useragent(session, subdriver->version); if (strcasecmp(uri.scheme, "https") == 0) { ne_ssl_trust_default_ca(session); } ne_set_server_auth(session, netxml_authenticate, NULL); /* if debug level is set, direct output to stderr */ if (!nut_debug_level) { fp = fopen("/dev/null", "w"); } else { fp = stderr; } if (!fp) { fatal_with_errno(EXIT_FAILURE, "Connectivity test failed"); } /* see if we have a connection */ ret = ne_get(session, subdriver->initups, fileno(fp)); if (!nut_debug_level) { fclose(fp); } else { fprintf(fp, "\n"); } if (ret != NE_OK) { fatalx(EXIT_FAILURE, "Connectivity test: %s", ne_get_error(session)); } upslogx(LOG_INFO, "Connectivity test: %s", ne_get_error(session)); }
/* Check certificate identity. Returns zero if identity matches; 1 if * identity does not match, or <0 if the certificate had no identity. * If 'identity' is non-NULL, store the malloc-allocated identity in * *identity. If 'server' is non-NULL, it must be the network address * of the server in use, and identity must be NULL. */ static int check_identity(const ne_uri *server, gnutls_x509_crt cert, char **identity) { char name[255]; unsigned int critical; int ret, seq = 0; int match = 0, found = 0; size_t len; const char *hostname; hostname = server ? server->host : ""; do { len = sizeof name - 1; ret = gnutls_x509_crt_get_subject_alt_name(cert, seq, name, &len, &critical); switch (ret) { case GNUTLS_SAN_DNSNAME: name[len] = '\0'; if (identity && !found) *identity = ne_strdup(name); match = ne__ssl_match_hostname(name, len, hostname); found = 1; break; case GNUTLS_SAN_IPADDRESS: { ne_inet_addr *ia; if (len == 4) ia = ne_iaddr_make(ne_iaddr_ipv4, (unsigned char *)name); else if (len == 16) ia = ne_iaddr_make(ne_iaddr_ipv6, (unsigned char *)name); else ia = NULL; if (ia) { char buf[128]; match = strcmp(hostname, ne_iaddr_print(ia, buf, sizeof buf)) == 0; if (identity) *identity = ne_strdup(buf); found = 1; ne_iaddr_free(ia); } else { NE_DEBUG(NE_DBG_SSL, "iPAddress name with unsupported " "address type (length %" NE_FMT_SIZE_T "), skipped.\n", len); } } break; case GNUTLS_SAN_URI: { ne_uri uri; name[len] = '\0'; if (ne_uri_parse(name, &uri) == 0 && uri.host && uri.scheme) { ne_uri tmp; if (identity && !found) *identity = ne_strdup(name); found = 1; if (server) { /* For comparison purposes, all that matters is * host, scheme and port; ignore the rest. */ memset(&tmp, 0, sizeof tmp); tmp.host = uri.host; tmp.scheme = uri.scheme; tmp.port = uri.port; match = ne_uri_cmp(server, &tmp) == 0; } } ne_uri_free(&uri); } break; default: break; } seq++; } while (!match && ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE); /* Check against the commonName if no DNS alt. names were found, * as per RFC3280. */ if (!found) { seq = oid_find_highest_index(cert, 1, GNUTLS_OID_X520_COMMON_NAME); if (seq >= 0) { len = sizeof name; name[0] = '\0'; ret = gnutls_x509_crt_get_dn_by_oid(cert, GNUTLS_OID_X520_COMMON_NAME, seq, 0, name, &len); if (ret == 0) { if (identity) *identity = ne_strdup(name); match = ne__ssl_match_hostname(name, len, hostname); } } else { return -1; } } if (*hostname) NE_DEBUG(NE_DBG_SSL, "ssl: Identity match for '%s': %s\n", hostname, match ? "good" : "bad"); return match ? 0 : 1; }
/* FIXME: Leaky as a bucket */ void open_connection(const char *url) { char *proxy_host = get_option(opt_proxy), *pnt; ne_server_capabilities caps; int ret, use_ssl = 0; ne_session *sess; if (session.connected) { close_connection(); } else { ne_uri_free(&session.uri); if (session.lastwp) { ne_free(session.lastwp); session.lastwp = NULL; } } /* Single argument: see whether we have a path or scheme */ if (strchr(url, '/') == NULL) { /* No path, no scheme -> just a hostname */ pnt = strchr(url, ':'); if (pnt != NULL) { *pnt++ = '\0'; session.uri.port = atoi(pnt); } else { session.uri.port = 80; } session.uri.host = ne_strdup(url); session.uri.scheme = ne_strdup("http"); } else { /* Parse the URL */ if (ne_uri_parse(url, &session.uri) || session.uri.host == NULL) { printf(_("Could not parse URL `%s'\n"), url); return; } if (session.uri.scheme == NULL) session.uri.scheme = ne_strdup("http"); if (!session.uri.port) session.uri.port = ne_uri_defaultport(session.uri.scheme); if (strcasecmp(session.uri.scheme, "https") == 0) { if (!ne_has_support(NE_FEATURE_SSL)) { printf(_("SSL is not enabled.\n")); return; } use_ssl = 1; } } session.sess = ne_session_create(session.uri.scheme, session.uri.host, session.uri.port); sess = session.sess; if (use_ssl && setup_ssl()) { return; } ne_lockstore_register(session.locks, sess); ne_redirect_register(sess); ne_set_notifier(sess, notifier, NULL); if (session.uri.path == NULL) { session.uri.path = ne_strdup("/"); } else { if (!ne_path_has_trailing_slash(session.uri.path)) { pnt = ne_concat(session.uri.path, "/", NULL); free(session.uri.path); session.uri.path = pnt; } } /* Get the proxy details */ if (proxy_host != NULL) { if (get_option(opt_proxy_port) != NULL) { proxy_port = atoi(get_option(opt_proxy_port)); } else { proxy_port = 8080; } proxy_hostname = proxy_host; } #ifdef ENABLE_NETRC { netrc_entry *found; found = search_netrc(netrc_list, session.uri.host); if (found != NULL) { if (found->account && found->password) { server_username = found->account; server_password = found->password; } } } #endif /* ENABLE_NETRC */ #ifdef NE_SESSFLAG_EXPECT100 ne_set_session_flag(session.sess, NE_SESSFLAG_EXPECT100, get_bool_option(opt_expect100)); #endif /* NE_SESSFLAG_EXPECT100 */ session.connected = 0; ne_set_useragent(session.sess, "cadaver/" PACKAGE_VERSION); ne_set_server_auth(session.sess, supply_creds_server, NULL); ne_set_proxy_auth(session.sess, supply_creds_proxy, NULL); if (proxy_host) { ne_session_proxy(session.sess, proxy_hostname, proxy_port); } ret = ne_options(session.sess, session.uri.path, &caps); switch (ret) { case NE_OK: session.connected = true; if (set_path(session.uri.path)) { close_connection(); } break; case NE_CONNECT: if (proxy_host) { printf(_("Could not connect to `%s' on port %d:\n%s\n"), proxy_hostname, proxy_port, ne_get_error(session.sess)); } else { printf(_("Could not connect to `%s' on port %d:\n%s\n"), session.uri.host, session.uri.port, ne_get_error(session.sess)); } break; case NE_LOOKUP: puts(ne_get_error(session.sess)); break; default: printf(_("Could not open collection:\n%s\n"), ne_get_error(session.sess)); break; } }
svn_error_t * svn_ra_neon__search_for_starting_props(svn_ra_neon__resource_t **rsrc, const char **missing_path, svn_ra_neon__session_t *sess, const char *url, apr_pool_t *pool) { svn_error_t *err = SVN_NO_ERROR; apr_size_t len; svn_stringbuf_t *path_s; ne_uri parsed_url; svn_stringbuf_t *lopped_path = svn_stringbuf_create(url, pool); /* initialize to make sure it'll fit without reallocating */ apr_pool_t *iterpool = svn_pool_create(pool); /* Split the url into its component pieces (scheme, host, path, etc). We want the path part. */ ne_uri_parse(url, &parsed_url); if (parsed_url.path == NULL) { ne_uri_free(&parsed_url); return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("Neon was unable to parse URL '%s'"), url); } svn_stringbuf_setempty(lopped_path); path_s = svn_stringbuf_create(parsed_url.path, pool); ne_uri_free(&parsed_url); /* Try to get the starting_props from the public url. If the resource no longer exists in HEAD, we'll get a failure. That's fine: just keep removing components and trying to get the starting_props from parent directories. */ while (! svn_path_is_empty(path_s->data)) { svn_pool_clear(iterpool); err = svn_ra_neon__get_starting_props(rsrc, sess, path_s->data, NULL, iterpool); if (! err) break; /* found an existing parent! */ if (err->apr_err != SVN_ERR_FS_NOT_FOUND) return err; /* found a _real_ error */ /* else... lop off the basename and try again. */ svn_stringbuf_set(lopped_path, svn_path_join(svn_path_basename(path_s->data, iterpool), lopped_path->data, iterpool)); len = path_s->len; svn_path_remove_component(path_s); /* if we detect an infinite loop, get out. */ if (path_s->len == len) return svn_error_quick_wrap (err, _("The path was not part of a repository")); svn_error_clear(err); } /* error out if entire URL was bogus (not a single part of it exists in the repository!) */ if (svn_path_is_empty(path_s->data)) return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("No part of path '%s' was found in " "repository HEAD"), parsed_url.path); /* Duplicate rsrc out of iterpool into pool */ { apr_hash_index_t *hi; svn_ra_neon__resource_t *tmp = apr_pcalloc(pool, sizeof(*tmp)); tmp->url = apr_pstrdup(pool, (*rsrc)->url); tmp->is_collection = (*rsrc)->is_collection; tmp->pool = pool; tmp->propset = apr_hash_make(pool); for (hi = apr_hash_first(iterpool, (*rsrc)->propset); hi; hi = apr_hash_next(hi)) { const void *key; void *val; apr_hash_this(hi, &key, NULL, &val); apr_hash_set(tmp->propset, apr_pstrdup(pool, key), APR_HASH_KEY_STRING, svn_string_dup(val, pool)); } *rsrc = tmp; } *missing_path = lopped_path->data; svn_pool_destroy(iterpool); return SVN_NO_ERROR; }