static void auth_register(ne_session *sess, int isproxy, const struct auth_class *ahc, const char *id, ne_auth_creds creds, void *userdata) { auth_session *ahs = ne_calloc(sizeof *ahs); ahs->creds = creds; ahs->userdata = userdata; ahs->sess = sess; ahs->spec = ahc; if (strcmp(ne_get_scheme(sess), "https") == 0) { ahs->context = isproxy ? AUTH_CONNECT : AUTH_NOTCONNECT; #ifdef HAVE_GSSAPI { get_gss_name(&ahs->gssname, (isproxy ? sess->proxy.hostname : sess->server.hostname)); ahs->gssctx = GSS_C_NO_CONTEXT; ahs->gssmech = GSS_C_NO_OID; } #endif } else { ahs->context = AUTH_ANY; } /* Register hooks */ ne_hook_create_request(sess, ah_create, ahs); ne_hook_pre_send(sess, ah_pre_send, ahs); ne_hook_post_send(sess, ah_post_send, ahs); ne_hook_destroy_request(sess, ah_destroy, ahs); ne_hook_destroy_session(sess, free_auth, ahs); ne_set_session_private(sess, id, ahs); }
void ne_lockstore_register(ne_lock_store *store, ne_session *sess) { /* Register the hooks */ ne_hook_create_request(sess, lk_create, store); ne_hook_pre_send(sess, lk_pre_send, store); ne_hook_destroy_request(sess, lk_destroy, store); }
/* A slightly ugly hack: the pre_send hook is scoped per-session, so * must check that the invoking request is this one, before doing * anything, and must be unregistered when the context is * destroyed. */ ne_decompress *ne_decompress_reader(ne_request *req, ne_accept_response acpt, ne_block_reader rdr, void *userdata) { ne_decompress *ctx = ne_calloc(sizeof *ctx); ne_add_request_header(req, "Accept-Encoding", "gzip"); ne_add_response_body_reader(req, gz_acceptor, gz_reader, ctx); ctx->reader = rdr; ctx->userdata = userdata; ctx->session = ne_get_session(req); ctx->request = req; ctx->acceptor = acpt; ne_hook_pre_send(ne_get_session(req), gz_pre_send, ctx); return ctx; }
int begin(void) { const char *scheme = use_secure?"https":"http"; char *space; static const char blanks[] = " "; static const char stars[] = "**********************************"; i_session = ne_session_create(scheme, i_hostname, i_port); CALL(init_session(i_session)); ne_hook_pre_send(i_session, i_pre_send, "X-Prestan"); space = ne_concat(i_path, "davtest/", NULL); ne_delete(i_session, space); if (ne_mkcol(i_session, space)) { t_context("Could not create new collection `%s' for tests: %s\n" "Server must allow `MKCOL %s' for tests to proceed", space, ne_get_error(i_session), space); return FAILHARD; } free(i_path); i_path = space; warmup(); printf("\nStart Testing %s:\n\n",pget_option.URL) ; printf("\n%s%s\n", blanks, stars); printf("\n%s* Number of Requests\t\t%d\n", blanks, pget_option.requests); printf("\n%s* Number of Dead Properties\t%d\n", blanks, pget_option.numprops); printf("\n%s* Depth of Collection\t\t%d\n", blanks, pget_option.depth); printf("\n%s* Width of Collection\t\t%d\n", blanks, pget_option.width); printf("\n%s* Type of Methods\t\t%s\n", blanks, pget_option.methods); printf("\n%s%s\n", blanks, stars); printf("\n\n"); return OK; }
/* Register cookie handling for given session using given cache. */ void ne_cookie_register(ne_session *sess, ne_cookie_cache *cache) { ne_hook_create_request(sess, create, cache); ne_hook_pre_send(sess, pre_send, cache); }
/* * Connect to a DAV server * This function sets the flag _connected if the connection is established * and returns if the flag is set, so calling it frequently is save. */ static int dav_connect(const char *base_url) { int useSSL = 0; int rc; char protocol[6] = {'\0'}; char uaBuf[256]; char *path = NULL; char *scheme = NULL; char *host = NULL; unsigned int port = 0; int proxystate = -1; if (_connected) { return 0; } rc = c_parse_uri( base_url, &scheme, &dav_session.user, &dav_session.pwd, &host, &port, &path ); if( rc < 0 ) { DEBUG_WEBDAV("Failed to parse uri %s", base_url ); goto out; } DEBUG_WEBDAV("* scheme %s", scheme ); DEBUG_WEBDAV("* host %s", host ); DEBUG_WEBDAV("* port %u", port ); DEBUG_WEBDAV("* path %s", path ); if( strcmp( scheme, "owncloud" ) == 0 ) { strcpy( protocol, "http"); } else if( strcmp( scheme, "ownclouds" ) == 0 ) { strcpy( protocol, "https"); useSSL = 1; } else { DEBUG_WEBDAV("Invalid scheme %s, go outa here!", scheme ); rc = -1; goto out; } DEBUG_WEBDAV("* user %s", dav_session.user ? dav_session.user : ""); if (port == 0) { port = ne_uri_defaultport(protocol); } #if 0 rc = ne_sock_init(); DEBUG_WEBDAV("ne_sock_init: %d", rc ); if (rc < 0) { rc = -1; goto out; } #endif dav_session.ctx = ne_session_create( protocol, host, port); if (dav_session.ctx == NULL) { DEBUG_WEBDAV("Session create with protocol %s failed", protocol ); rc = -1; goto out; } if (dav_session.read_timeout == 0) dav_session.read_timeout = 300; // set 300 seconds as default. ne_set_read_timeout(dav_session.ctx, dav_session.read_timeout); snprintf( uaBuf, sizeof(uaBuf), "Mozilla/5.0 (%s) csyncoC/%s", get_platform(), CSYNC_STRINGIFY( LIBCSYNC_VERSION )); ne_set_useragent( dav_session.ctx, uaBuf); ne_set_server_auth(dav_session.ctx, ne_auth, 0 ); if( useSSL ) { if (!ne_has_support(NE_FEATURE_SSL)) { DEBUG_WEBDAV("Error: SSL is not enabled."); rc = -1; goto out; } ne_ssl_trust_default_ca( dav_session.ctx ); ne_ssl_set_verify( dav_session.ctx, verify_sslcert, 0 ); } /* Hook called when a request is created. It sets the proxy connection header. */ ne_hook_create_request( dav_session.ctx, request_created_hook, NULL ); /* Hook called after response headers are read. It gets the Session ID. */ ne_hook_post_headers( dav_session.ctx, post_request_hook, NULL ); /* Hook called before a request is sent. It sets the cookies. */ ne_hook_pre_send( dav_session.ctx, pre_send_hook, NULL ); /* Hook called after request is dispatched. Used for handling possible redirections. */ ne_hook_post_send( dav_session.ctx, post_send_hook, NULL ); /* Proxy support */ proxystate = configureProxy( dav_session.ctx ); if( proxystate < 0 ) { DEBUG_WEBDAV("Error: Proxy-Configuration failed."); } else if( proxystate > 0 ) { ne_set_proxy_auth( dav_session.ctx, ne_proxy_auth, 0 ); } _connected = 1; rc = 0; out: SAFE_FREE(path); SAFE_FREE(host); SAFE_FREE(scheme); return rc; }