Exemplo n.º 1
0
static void
connect_server()
{
    ne_session *sess;
    ne_server_capabilities caps;
    int ret;

    /* set up the connection */

    ne_sock_init();

    memset(&session, 0, sizeof session);
    session.uri.scheme = ne_strdup("http");
    session.uri.host = hc_host;
    session.uri.port = port; 
    session.uri.path = ne_strdup("/webdav/"); /* always '/'-terminate */

    session.sess = sess = ne_session_create(session.uri.scheme, 
                                     session.uri.host, 
                                     session.uri.port);

    /* make the connection */

    ne_set_useragent(sess, "hctest/");  /* needed? */
/*
not needed to connect
    ne_lockstore_register(session.locks, sess);
    ne_redirect_register(sess);
*/
    /* convenient status */
    ne_set_status(sess, connection_status, NULL);
    ne_set_progress(sess, transfer_progress, NULL);

    /* execute connect */
    ret = ne_options(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:
        printf("got NE_CONNECT\n");
        quit(1);
	break;
    case NE_LOOKUP:
	puts(ne_get_error(sess));
        quit(1);
	break;
    default:
	printf("Could not open collection (default connect err):\n%s\n",
	       ne_get_error(sess));
        quit(1);
	break;
    }
}
Exemplo n.º 2
0
/* Returns true if resource at URI is lockable. */
static int is_lockable(const char *uri)
{
    ne_server_capabilities caps = {0};

    /* TODO: for the mo, just check we're on a Class 2 server.
     * Should check supportedlock property really. */

    if (ne_options(session.sess, uri, &caps) != NE_OK) {
	return 0;
    }

    return caps.dav_class2;
}
Exemplo n.º 3
0
/* 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;
    }

}