static apr_status_t send_get_locations_report(ap_filter_t *output, apr_bucket_brigade *bb, const dav_resource *resource, apr_hash_t *fs_locations) { apr_hash_index_t *hi; apr_pool_t *pool; apr_status_t apr_err; pool = resource->pool; apr_err = ap_fprintf(output, bb, DAV_XML_HEADER DEBUG_CR "<S:get-locations-report xmlns:S=\"" SVN_XML_NAMESPACE "\" xmlns:D=\"DAV:\">" DEBUG_CR); if (apr_err) return apr_err; for (hi = apr_hash_first(pool, fs_locations); hi; hi = apr_hash_next(hi)) { const void *key; void *value; const char *path_quoted; apr_hash_this(hi, &key, NULL, &value); path_quoted = apr_xml_quote_string(pool, value, 1); apr_err = ap_fprintf(output, bb, "<S:location " "rev=\"%ld\" path=\"%s\"/>" DEBUG_CR, *(const svn_revnum_t *)key, path_quoted); if (apr_err) return apr_err; } return ap_fprintf(output, bb, "</S:get-locations-report>" DEBUG_CR); }
/* Implements `svn_location_segment_receiver_t'; helper for dav_svn__get_location_segments_report(). */ static svn_error_t * location_segment_receiver(svn_location_segment_t *segment, void *baton, apr_pool_t *pool) { struct location_segment_baton *b = baton; apr_status_t apr_err; SVN_ERR(maybe_send_opener(b)); if (segment->path) { const char *path_quoted = apr_xml_quote_string(pool, segment->path, 1); apr_err = ap_fprintf(b->output, b->bb, "<S:location-segment path=\"%s\" " "range-start=\"%ld\" range-end=\"%ld\"/>" DEBUG_CR, path_quoted, segment->range_start, segment->range_end); } else { apr_err = ap_fprintf(b->output, b->bb, "<S:location-segment " "range-start=\"%ld\" range-end=\"%ld\"/>" DEBUG_CR, segment->range_start, segment->range_end); } if (apr_err) return svn_error_create(apr_err, 0, NULL); return SVN_NO_ERROR; }
static void pendElement(void *ctxt, const xmlChar * uname) { saxctxt *ctx = (saxctxt *) ctxt; const char *name = (const char *) uname; const htmlElemDesc *desc = htmlTagLookup(uname); #if 0 /* for now, err on the side of leaving stuff alone */ if ((ctx->cfg->doctype == fpi_html) || (ctx->cfg->doctype == fpi_xhtml)) { /* enforce html */ if (!desc || desc->depr) return; } else if ((ctx->cfg->doctype == fpi_html) || (ctx->cfg->doctype == fpi_xhtml)) { /* enforce html legacy */ if (!desc) return; } #endif if (ctx->offset > 0) { dump_content(ctx); ctx->offset = 0; /* having dumped it, we can re-use the memory */ } if (!desc || !desc->empty) { ap_fprintf(ctx->f->next, ctx->bb, "</%s>", name); } }
/* Respond to a S:dated-rev-report request. The request contains a * DAV:creationdate element giving the requested date; the response * contains a DAV:version-name element giving the most recent revision * as of that date. */ dav_error * dav_svn__dated_rev_report(const dav_resource *resource, const apr_xml_doc *doc, ap_filter_t *output) { apr_xml_elem *child; int ns; apr_time_t tm = (apr_time_t) -1; svn_revnum_t rev; apr_bucket_brigade *bb; svn_error_t *err; apr_status_t apr_err; dav_error *derr = NULL; /* Find the DAV:creationdate element and get the requested time from it. */ ns = dav_svn__find_ns(doc->namespaces, "DAV:"); if (ns != -1) { for (child = doc->root->first_child; child != NULL; child = child->next) { if (child->ns != ns || strcmp(child->name, SVN_DAV__CREATIONDATE) != 0) continue; /* If this fails, we'll notice below, so ignore any error for now. */ svn_error_clear (svn_time_from_cstring(&tm, dav_xml_get_cdata(child, resource->pool, 1), resource->pool)); } } if (tm == (apr_time_t) -1) { return dav_svn__new_error(resource->pool, HTTP_BAD_REQUEST, 0, "The request does not contain a valid " "'DAV:" SVN_DAV__CREATIONDATE "' element."); } /* Do the actual work of finding the revision by date. */ if ((err = svn_repos_dated_revision(&rev, resource->info->repos->repos, tm, resource->pool)) != SVN_NO_ERROR) { svn_error_clear(err); return dav_svn__new_error(resource->pool, HTTP_INTERNAL_SERVER_ERROR, 0, "Could not access revision times."); } bb = apr_brigade_create(resource->pool, output->c->bucket_alloc); apr_err = ap_fprintf(output, bb, DAV_XML_HEADER DEBUG_CR "<S:dated-rev-report xmlns:S=\"" SVN_XML_NAMESPACE "\" " "xmlns:D=\"DAV:\">" DEBUG_CR "<D:" SVN_DAV__VERSION_NAME ">%ld</D:" SVN_DAV__VERSION_NAME ">""</S:dated-rev-report>", rev); if (apr_err) derr = dav_svn__convert_err(svn_error_create(apr_err, 0, NULL), HTTP_INTERNAL_SERVER_ERROR, "Error writing REPORT response.", resource->pool); return dav_svn__final_flush_or_error(resource->info->r, bb, output, derr, resource->pool); }
/* Respond to a S:deleted-rev-report request. */ dav_error * dav_svn__get_deleted_rev_report(const dav_resource *resource, const apr_xml_doc *doc, ap_filter_t *output) { apr_xml_elem *child; int ns; const char *rel_path = NULL, *abs_path; svn_revnum_t peg_rev = SVN_INVALID_REVNUM, end_rev = SVN_INVALID_REVNUM, deleted_rev; apr_bucket_brigade *bb; svn_error_t *err; apr_status_t apr_err; dav_error *derr = NULL; /* Sanity check. */ ns = dav_svn__find_ns(doc->namespaces, SVN_XML_NAMESPACE); if (ns == -1) return dav_svn__new_error_tag(resource->pool, HTTP_BAD_REQUEST, 0, "The request does not contain the 'svn:' " "namespace, so it is not going to have " "certain required elements.", SVN_DAV_ERROR_NAMESPACE, SVN_DAV_ERROR_TAG); for (child = doc->root->first_child; child != NULL; child = child->next) { /* If this element isn't one of ours, then skip it. */ if (child->ns != ns ) continue; if (strcmp(child->name, "peg-revision") == 0) { peg_rev = SVN_STR_TO_REV(dav_xml_get_cdata(child, resource->pool, 1)); } else if (strcmp(child->name, "end-revision") == 0) { end_rev = SVN_STR_TO_REV(dav_xml_get_cdata(child, resource->pool, 1)); } else if (strcmp(child->name, "path") == 0) { rel_path = dav_xml_get_cdata(child, resource->pool, 0); if ((derr = dav_svn__test_canonical(rel_path, resource->pool))) return derr; } } /* Check that all parameters are present. */ if (! (rel_path && SVN_IS_VALID_REVNUM(peg_rev) && SVN_IS_VALID_REVNUM(end_rev))) { return dav_svn__new_error_tag(resource->pool, HTTP_BAD_REQUEST, 0, "Not all parameters passed.", SVN_DAV_ERROR_NAMESPACE, SVN_DAV_ERROR_TAG); } /* Append the relative path to the base FS path to get an absolute repository path. */ abs_path = svn_path_join(resource->info->repos_path, rel_path, resource->pool); /* Do what we actually came here for: Find the rev abs_path was deleted. */ err = svn_repos_deleted_rev(resource->info->repos->fs, abs_path, peg_rev, end_rev, &deleted_rev, resource->pool); if (err) { svn_error_clear(err); return dav_new_error(resource->pool, HTTP_INTERNAL_SERVER_ERROR, 0, "Could not find revision path was deleted."); } bb = apr_brigade_create(resource->pool, output->c->bucket_alloc); apr_err = ap_fprintf(output, bb, DAV_XML_HEADER DEBUG_CR "<S:get-deleted-rev-report xmlns:S=\"" SVN_XML_NAMESPACE "\" xmlns:D=\"DAV:\">" DEBUG_CR "<D:" SVN_DAV__VERSION_NAME ">%ld</D:" SVN_DAV__VERSION_NAME ">""</S:get-deleted-rev-report>", deleted_rev); if (apr_err) derr = dav_svn__convert_err(svn_error_create(apr_err, 0, NULL), HTTP_INTERNAL_SERVER_ERROR, "Error writing REPORT response.", resource->pool); return dav_svn__final_flush_or_error(resource->info->r, bb, output, derr, resource->pool); }
/* Transmit LOCKS (a hash of Subversion filesystem locks keyed by path) across OUTPUT using BB. Use POOL for necessary allocations. NOTE: As written, this function currently returns one of only two status values -- "success", and "we had trouble writing out to the output stream". If you need to return something more interesting, you'll probably want to generate dav_error's here instead of passing back only apr_status_t's. */ static apr_status_t send_get_lock_response(apr_hash_t *locks, ap_filter_t *output, apr_bucket_brigade *bb, apr_pool_t *pool) { apr_pool_t *subpool; apr_hash_index_t *hi; /* start sending report */ SVN_APR_ERR(ap_fprintf(output, bb, DAV_XML_HEADER DEBUG_CR "<S:get-locks-report xmlns:S=\"" SVN_XML_NAMESPACE "\" xmlns:D=\"DAV:\">" DEBUG_CR)); /* stream the locks */ subpool = svn_pool_create(pool); for (hi = apr_hash_first(pool, locks); hi; hi = apr_hash_next(hi)) { void *val; const svn_lock_t *lock; svn_pool_clear(subpool); apr_hash_this(hi, NULL, NULL, &val); lock = val; /* Begin the <S:lock> tag, transmitting the path, token, and creation date. */ SVN_APR_ERR(ap_fprintf(output, bb, "<S:lock>" DEBUG_CR "<S:path>%s</S:path>" DEBUG_CR "<S:token>%s</S:token>" DEBUG_CR "<S:creationdate>%s</S:creationdate>" DEBUG_CR, apr_xml_quote_string(subpool, lock->path, 1), apr_xml_quote_string(subpool, lock->token, 1), svn_time_to_cstring(lock->creation_date, subpool))); /* Got expiration date? Tell the client. */ if (lock->expiration_date) SVN_APR_ERR(ap_fprintf(output, bb, "<S:expirationdate>%s</S:expirationdate>" DEBUG_CR, svn_time_to_cstring(lock->expiration_date, subpool))); /* Transmit the lock ownership information. */ if (lock->owner) { const char *owner; svn_boolean_t owner_base64 = FALSE; if (svn_xml_is_xml_safe(lock->owner, strlen(lock->owner))) { owner = apr_xml_quote_string(subpool, lock->owner, 1); } else { svn_string_t owner_string; const svn_string_t *encoded_owner; owner_string.data = lock->owner; owner_string.len = strlen(lock->owner); encoded_owner = svn_base64_encode_string2(&owner_string, TRUE, subpool); owner = encoded_owner->data; owner_base64 = TRUE; } SVN_APR_ERR(ap_fprintf(output, bb, "<S:owner %s>%s</S:owner>" DEBUG_CR, owner_base64 ? "encoding=\"base64\"" : "", owner)); } /* If the lock carries a comment, transmit that, too. */ if (lock->comment) { const char *comment; svn_boolean_t comment_base64 = FALSE; if (svn_xml_is_xml_safe(lock->comment, strlen(lock->comment))) { comment = apr_xml_quote_string(subpool, lock->comment, 1); } else { svn_string_t comment_string; const svn_string_t *encoded_comment; comment_string.data = lock->comment; comment_string.len = strlen(lock->comment); encoded_comment = svn_base64_encode_string2(&comment_string, TRUE, subpool); comment = encoded_comment->data; comment_base64 = TRUE; } SVN_APR_ERR(ap_fprintf(output, bb, "<S:comment %s>%s</S:comment>" DEBUG_CR, comment_base64 ? "encoding=\"base64\"" : "", comment)); } /* Okay, finish up this lock by closing the <S:lock> tag. */ SVN_APR_ERR(ap_fprintf(output, bb, "</S:lock>" DEBUG_CR)); } svn_pool_destroy(subpool); /* Finish the report */ SVN_APR_ERR(ap_fprintf(output, bb, "</S:get-locks-report>" DEBUG_CR)); return APR_SUCCESS; }
/* CONNECT handler */ static int proxy_connect_handler(request_rec *r, proxy_worker *worker, proxy_server_conf *conf, char *url, const char *proxyname, apr_port_t proxyport) { connect_conf *c_conf = ap_get_module_config(r->server->module_config, &proxy_connect_module); apr_pool_t *p = r->pool; apr_socket_t *sock; conn_rec *c = r->connection; conn_rec *backconn; apr_bucket_brigade *bb = apr_brigade_create(p, c->bucket_alloc); apr_status_t rv; apr_size_t nbytes; char buffer[HUGE_STRING_LEN]; apr_socket_t *client_socket = ap_get_conn_socket(c); int failed, rc; int client_error = 0; apr_pollset_t *pollset; apr_pollfd_t pollfd; const apr_pollfd_t *signalled; apr_int32_t pollcnt, pi; apr_int16_t pollevent; apr_sockaddr_t *nexthop; apr_uri_t uri; const char *connectname; int connectport = 0; /* is this for us? */ if (r->method_number != M_CONNECT) { ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "declining URL %s", url); return DECLINED; } ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "serving URL %s", url); /* * Step One: Determine Who To Connect To * * Break up the URL to determine the host to connect to */ /* we break the URL into host, port, uri */ if (APR_SUCCESS != apr_uri_parse_hostinfo(p, url, &uri)) { return ap_proxyerror(r, HTTP_BAD_REQUEST, apr_pstrcat(p, "URI cannot be parsed: ", url, NULL)); } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01019) "connecting %s to %s:%d", url, uri.hostname, uri.port); /* Determine host/port of next hop; from request URI or of a proxy. */ connectname = proxyname ? proxyname : uri.hostname; connectport = proxyname ? proxyport : uri.port; /* Do a DNS lookup for the next hop */ rv = apr_sockaddr_info_get(&nexthop, connectname, APR_UNSPEC, connectport, 0, p); if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02327) "failed to resolve hostname '%s'", connectname); return ap_proxyerror(r, HTTP_BAD_GATEWAY, apr_pstrcat(p, "DNS lookup failure for: ", connectname, NULL)); } /* Check ProxyBlock directive on the hostname/address. */ if (ap_proxy_checkproxyblock2(r, conf, uri.hostname, proxyname ? NULL : nexthop) != OK) { return ap_proxyerror(r, HTTP_FORBIDDEN, "Connect to remote machine blocked"); } ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "connecting to remote proxy %s on port %d", connectname, connectport); /* Check if it is an allowed port */ if(!allowed_port(c_conf, uri.port)) { return ap_proxyerror(r, HTTP_FORBIDDEN, "Connect to remote machine blocked"); } /* * Step Two: Make the Connection * * We have determined who to connect to. Now make the connection. */ /* * At this point we have a list of one or more IP addresses of * the machine to connect to. If configured, reorder this * list so that the "best candidate" is first try. "best * candidate" could mean the least loaded server, the fastest * responding server, whatever. * * For now we do nothing, ie we get DNS round robin. * XXX FIXME */ failed = ap_proxy_connect_to_backend(&sock, "CONNECT", nexthop, connectname, conf, r); /* handle a permanent error from the above loop */ if (failed) { if (proxyname) { return DECLINED; } else { return HTTP_SERVICE_UNAVAILABLE; } } /* setup polling for connection */ ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "setting up poll()"); if ((rv = apr_pollset_create(&pollset, 2, r->pool, 0)) != APR_SUCCESS) { apr_socket_close(sock); ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01020) "error apr_pollset_create()"); return HTTP_INTERNAL_SERVER_ERROR; } /* Add client side to the poll */ pollfd.p = r->pool; pollfd.desc_type = APR_POLL_SOCKET; pollfd.reqevents = APR_POLLIN; pollfd.desc.s = client_socket; pollfd.client_data = NULL; apr_pollset_add(pollset, &pollfd); /* Add the server side to the poll */ pollfd.desc.s = sock; apr_pollset_add(pollset, &pollfd); /* * Step Three: Send the Request * * Send the HTTP/1.1 CONNECT request to the remote server */ backconn = ap_run_create_connection(c->pool, r->server, sock, c->id, c->sbh, c->bucket_alloc); if (!backconn) { /* peer reset */ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01021) "an error occurred creating a new connection " "to %pI (%s)", nexthop, connectname); apr_socket_close(sock); return HTTP_INTERNAL_SERVER_ERROR; } ap_proxy_ssl_disable(backconn); rc = ap_run_pre_connection(backconn, sock); if (rc != OK && rc != DONE) { backconn->aborted = 1; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01022) "pre_connection setup failed (%d)", rc); return HTTP_INTERNAL_SERVER_ERROR; } ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r, "connection complete to %pI (%s)", nexthop, connectname); apr_table_setn(r->notes, "proxy-source-port", apr_psprintf(r->pool, "%hu", backconn->local_addr->port)); /* If we are connecting through a remote proxy, we need to pass * the CONNECT request on to it. */ if (proxyport) { /* FIXME: Error checking ignored. */ ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "sending the CONNECT request to the remote proxy"); ap_fprintf(backconn->output_filters, bb, "CONNECT %s HTTP/1.0" CRLF, r->uri); ap_fprintf(backconn->output_filters, bb, "Proxy-agent: %s" CRLF CRLF, ap_get_server_banner()); ap_fflush(backconn->output_filters, bb); } else { ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Returning 200 OK"); nbytes = apr_snprintf(buffer, sizeof(buffer), "HTTP/1.0 200 Connection Established" CRLF); ap_xlate_proto_to_ascii(buffer, nbytes); ap_fwrite(c->output_filters, bb, buffer, nbytes); nbytes = apr_snprintf(buffer, sizeof(buffer), "Proxy-agent: %s" CRLF CRLF, ap_get_server_banner()); ap_xlate_proto_to_ascii(buffer, nbytes); ap_fwrite(c->output_filters, bb, buffer, nbytes); ap_fflush(c->output_filters, bb); #if 0 /* This is safer code, but it doesn't work yet. I'm leaving it * here so that I can fix it later. */ r->status = HTTP_OK; r->header_only = 1; apr_table_set(r->headers_out, "Proxy-agent: %s", ap_get_server_banner()); ap_rflush(r); #endif } ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "setting up poll()"); /* * Step Four: Handle Data Transfer * * Handle two way transfer of data over the socket (this is a tunnel). */ /* we are now acting as a tunnel - the input/output filter stacks should * not contain any non-connection filters. */ r->output_filters = c->output_filters; r->proto_output_filters = c->output_filters; r->input_filters = c->input_filters; r->proto_input_filters = c->input_filters; /* r->sent_bodyct = 1;*/ while (1) { /* Infinite loop until error (one side closes the connection) */ if ((rv = apr_pollset_poll(pollset, -1, &pollcnt, &signalled)) != APR_SUCCESS) { if (APR_STATUS_IS_EINTR(rv)) { continue; } apr_socket_close(sock); ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01023) "error apr_poll()"); return HTTP_INTERNAL_SERVER_ERROR; } #ifdef DEBUGGING ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01024) "woke from poll(), i=%d", pollcnt); #endif for (pi = 0; pi < pollcnt; pi++) { const apr_pollfd_t *cur = &signalled[pi]; if (cur->desc.s == sock) { pollevent = cur->rtnevents; if (pollevent & APR_POLLIN) { #ifdef DEBUGGING ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01025) "sock was readable"); #endif rv = proxy_connect_transfer(r, backconn, c, bb, "sock"); } else if ((pollevent & APR_POLLERR) || (pollevent & APR_POLLHUP)) { rv = APR_EPIPE; ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(01026) "err/hup on backconn"); } if (rv != APR_SUCCESS) client_error = 1; } else if (cur->desc.s == client_socket) { pollevent = cur->rtnevents; if (pollevent & APR_POLLIN) { #ifdef DEBUGGING ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01027) "client was readable"); #endif rv = proxy_connect_transfer(r, c, backconn, bb, "client"); } } else { rv = APR_EBADF; ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01028) "unknown socket in pollset"); } } if (rv != APR_SUCCESS) { break; } } ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "finished with poll() - cleaning up"); /* * Step Five: Clean Up * * Close the socket and clean up */ if (client_error) apr_socket_close(sock); else ap_lingering_close(backconn); c->aborted = 1; c->keepalive = AP_CONN_CLOSE; return OK; }