1 --- rpm-4.5/rpmio/rpmdav.c~ 2008-07-09 12:38:31.000000000 +0300
2 +++ rpm-4.5/rpmio/rpmdav.c 2008-09-04 17:43:50.215697868 +0300
10 -#include "ne_basic.h"
11 -#include "ne_dates.h"
12 -#include "ne_locks.h"
14 -#include "neon/ne_alloc.h"
15 -#include "neon/ne_auth.h"
16 -#include "neon/ne_basic.h"
17 -#include "neon/ne_dates.h"
18 -#include "neon/ne_locks.h"
21 -#define NEONBLOWSCHUNKS
22 -#ifndef NEONBLOWSCHUNKS
23 -/* HACK: include ne_private.h to access sess->socket for now. */
24 -#include "../neon/src/ne_private.h"
27 -#if USE_INTERNAL_NEON
28 -#include "ne_props.h"
29 -#include "ne_request.h"
30 -#include "ne_socket.h"
31 -#include "ne_string.h"
32 -#include "ne_utils.h"
33 -#include "ne_md5.h" /* for version detection only */
35 -#include "neon/ne_props.h"
36 -#include "neon/ne_request.h"
37 -#include "neon/ne_socket.h"
38 -#include "neon/ne_string.h"
39 -#include "neon/ne_utils.h"
40 -#include "neon/ne_md5.h" /* for version detection only */
43 -/* poor-man's NEON version determination */
44 -#if defined(NE_MD5_H)
45 -#define WITH_NEON_MIN_VERSION 0x002700
46 -#elif defined(NE_FEATURE_I18N)
47 -#define WITH_NEON_MIN_VERSION 0x002600
49 -#define WITH_NEON_MIN_VERSION 0x002500
52 -/* XXX API changes for NEON 0.26 */
53 -#if WITH_NEON_MIN_VERSION >= 0x002600
54 -#define ne_set_persist(_sess, _flag)
55 -#define ne_propfind_set_private(_pfh, _create_item, NULL) \
56 - ne_propfind_set_private(_pfh, _create_item, NULL, NULL)
59 #include <rpmio_internal.h>
61 #define _RPMDAV_INTERNAL
66 -#if 0 /* HACK: reasonable value needed. */
67 -#define TIMEOUT_SECS 60
69 -#define TIMEOUT_SECS 5
72 -static int httpTimeoutSecs = TIMEOUT_SECS;
74 -/* =============================================================== */
75 -int davFree(urlinfo u)
76 - /*@globals internalState @*/
77 - /*@modifies u, internalState @*/
80 - if (u->sess != NULL) {
81 - ne_session_destroy(u->sess);
84 - switch (u->urltype) {
86 - /*@notreached@*/ break;
90 - u->capabilities = _free(u->capabilities);
91 - if (u->lockstore != NULL)
92 - ne_lockstore_destroy(u->lockstore);
93 - u->lockstore = NULL;
101 -static void davProgress(void * userdata, off_t current, off_t total)
104 - urlinfo u = userdata;
109 -assert(sess != NULL);
110 -assert(u == ne_get_session_private(sess, "urlinfo"));
112 - u->current = current;
116 -fprintf(stderr, "*** davProgress(%p,0x%x:0x%x) sess %p u %p\n", userdata, (unsigned int)current, (unsigned int)total, sess, u);
119 -#if WITH_NEON_MIN_VERSION >= 0x002700
120 -static void davNotify(void * userdata,
121 - ne_session_status connstatus, const ne_session_status_info *info)
123 -static void davNotify(void * userdata,
124 - ne_conn_status connstatus, const char * info)
128 - urlinfo u = userdata;
131 - static const char * connstates[] = {
141 -assert(sess != NULL);
142 -assert(u == ne_get_session_private(sess, "urlinfo"));
146 - ne_conn_namelookup, /* lookup up hostname (info = hostname) */
147 - ne_conn_connecting, /* connecting to host (info = hostname) */
148 - ne_conn_connected, /* connected to host (info = hostname) */
149 - ne_conn_secure /* connection now secure (info = crypto level) */
153 -#if WITH_NEON_MIN_VERSION < 0x002700
154 - u->connstatus = connstatus;
159 -fprintf(stderr, "*** davNotify(%p,%d,%p) sess %p u %p %s\n", userdata, connstatus, info, sess, u, connstates[ (connstatus < 4 ? connstatus : 4)]);
164 -static void davCreateRequest(ne_request * req, void * userdata,
165 - const char * method, const char * uri)
168 - urlinfo u = userdata;
170 - void * private = NULL;
171 - const char * id = "urlinfo";
174 -assert(u->sess != NULL);
175 -assert(req != NULL);
176 - sess = ne_get_session(req);
177 -assert(sess == u->sess);
178 -assert(u == ne_get_session_private(sess, "urlinfo"));
180 -assert(sess != NULL);
181 - private = ne_get_session_private(sess, id);
182 -assert(u == private);
185 -fprintf(stderr, "*** davCreateRequest(%p,%p,%s,%s) %s:%p\n", req, userdata, method, uri, id, private);
188 -static void davPreSend(ne_request * req, void * userdata, ne_buffer * buf)
190 - urlinfo u = userdata;
192 - const char * id = "fd";
196 -assert(u->sess != NULL);
197 -assert(req != NULL);
198 - sess = ne_get_session(req);
199 -assert(sess == u->sess);
200 -assert(u == ne_get_session_private(sess, "urlinfo"));
202 - fd = ne_get_request_private(req, id);
205 -fprintf(stderr, "*** davPreSend(%p,%p,%p) sess %p %s %p\n", req, userdata, buf, sess, id, fd);
207 -fprintf(stderr, "-> %s\n", buf->data);
211 -static int davPostSend(ne_request * req, void * userdata, const ne_status * status)
214 - urlinfo u = userdata;
216 - const char * id = "fd";
220 -assert(u->sess != NULL);
221 -assert(req != NULL);
222 - sess = ne_get_session(req);
223 -assert(sess == u->sess);
224 -assert(u == ne_get_session_private(sess, "urlinfo"));
226 - fd = ne_get_request_private(req, id);
230 -fprintf(stderr, "*** davPostSend(%p,%p,%p) sess %p %s %p %s\n", req, userdata, status, sess, id, fd, ne_get_error(sess));
235 -static void davDestroyRequest(ne_request * req, void * userdata)
238 - urlinfo u = userdata;
240 - const char * id = "fd";
244 -assert(u->sess != NULL);
245 -assert(req != NULL);
246 - sess = ne_get_session(req);
247 -assert(sess == u->sess);
248 -assert(u == ne_get_session_private(sess, "urlinfo"));
250 - fd = ne_get_request_private(req, id);
253 -fprintf(stderr, "*** davDestroyRequest(%p,%p) sess %p %s %p\n", req, userdata, sess, id, fd);
256 -static void davDestroySession(void * userdata)
259 - urlinfo u = userdata;
261 - void * private = NULL;
262 - const char * id = "urlinfo";
265 -assert(u->sess != NULL);
267 -assert(u == ne_get_session_private(sess, "urlinfo"));
269 -assert(sess != NULL);
270 - private = ne_get_session_private(sess, id);
271 -assert(u == private);
274 -fprintf(stderr, "*** davDestroySession(%p) sess %p %s %p\n", userdata, sess, id, private);
278 -davVerifyCert(void *userdata, int failures, const ne_ssl_certificate *cert)
281 - const char *hostname = userdata;
284 -fprintf(stderr, "*** davVerifyCert(%p,%d,%p) %s\n", userdata, failures, cert, hostname);
286 - return 0; /* HACK: trust all server certificates. */
289 -static int davConnect(urlinfo u)
290 - /*@globals internalState @*/
291 - /*@modifies u, internalState @*/
293 - const char * path = NULL;
296 - /* HACK: hkp:// has no steenkin' options */
297 - if (!(u->urltype == URL_IS_HTTP || u->urltype == URL_IS_HTTPS))
300 - /* HACK: where should server capabilities be read? */
301 - (void) urlPath(u->url, &path);
302 - /* HACK: perhaps capture Allow: tag, look for PUT permitted. */
303 - /* XXX [hdr] Allow: GET,HEAD,POST,OPTIONS,TRACE */
304 - rc = ne_options(u->sess, path, u->capabilities);
307 - { ne_server_capabilities *cap = u->capabilities;
308 - if (cap->dav_class1)
309 - u->allow |= RPMURL_SERVER_HASDAVCLASS1;
311 - u->allow &= ~RPMURL_SERVER_HASDAVCLASS1;
312 - if (cap->dav_class2)
313 - u->allow |= RPMURL_SERVER_HASDAVCLASS2;
315 - u->allow &= ~RPMURL_SERVER_HASDAVCLASS2;
316 - if (cap->dav_executable)
317 - u->allow |= RPMURL_SERVER_HASDAVEXEC;
319 - u->allow &= ~RPMURL_SERVER_HASDAVEXEC;
322 - /* HACK: "301 Moved Permanently" on empty subdir. */
323 - if (!strncmp("301 ", ne_get_error(u->sess), sizeof("301 ")-1))
325 - errno = EIO; /* HACK: more precise errno. */
328 - errno = ENOENT; /* HACK: errno same as non-existent path. */
330 - case NE_CONNECT: /* HACK: errno set already? */
334 -fprintf(stderr, "*** Connect to %s:%d failed(%d):\n\t%s\n",
335 - u->host, u->port, rc, ne_get_error(u->sess));
339 - /* HACK: sensitive to error returns? */
340 - u->httpVersion = (ne_version_pre_http11(u->sess) ? 0 : 1);
345 -static int davInit(const char * url, urlinfo * uret)
346 - /*@globals internalState @*/
347 - /*@modifies *uret, internalState @*/
352 -/*@-globs@*/ /* FIX: h_errno annoyance. */
353 - if (urlSplit(url, &u))
354 - return -1; /* XXX error returns needed. */
357 - if (u->url != NULL && u->sess == NULL)
358 - switch (u->urltype) {
360 - assert(u->urltype != u->urltype);
361 - /*@notreached@*/ break;
365 - { ne_server_capabilities * capabilities;
367 - /* HACK: oneshots should be done Somewhere Else Instead. */
369 - rc = ((_dav_debug < 0) ? NE_DBG_HTTP : 0);
370 - ne_debug_init(stderr, rc); /* XXX oneshot? */
372 - rc = ne_sock_init(); /* XXX oneshot? */
374 - u->lockstore = ne_lockstore_create(); /* XXX oneshot? */
376 - u->capabilities = capabilities = xcalloc(1, sizeof(*capabilities));
377 - u->sess = ne_session_create(u->scheme, u->host, u->port);
379 - ne_lockstore_register(u->lockstore, u->sess);
381 - if (u->proxyh != NULL)
382 - ne_session_proxy(u->sess, u->proxyh, u->proxyp);
385 - { const ne_inet_addr ** addrs;
387 - ne_set_addrlist(u->sess, addrs, n);
391 - ne_set_progress(u->sess, davProgress, u);
392 -#if WITH_NEON_MIN_VERSION >= 0x002700
393 - ne_set_notifier(u->sess, davNotify, u);
395 - ne_set_status(u->sess, davNotify, u);
398 - ne_set_persist(u->sess, 1);
399 - ne_set_read_timeout(u->sess, httpTimeoutSecs);
400 - ne_set_useragent(u->sess, PACKAGE "/" PACKAGE_VERSION);
402 - /* XXX check that neon is ssl enabled. */
403 - if (!strcasecmp(u->scheme, "https"))
404 - ne_ssl_set_verify(u->sess, davVerifyCert, (char *)u->host);
406 - ne_set_session_private(u->sess, "urlinfo", u);
408 - ne_hook_destroy_session(u->sess, davDestroySession, u);
410 - ne_hook_create_request(u->sess, davCreateRequest, u);
411 - ne_hook_pre_send(u->sess, davPreSend, u);
412 - ne_hook_post_send(u->sess, davPostSend, u);
413 - ne_hook_destroy_request(u->sess, davDestroyRequest, u);
415 - /* HACK: where should server capabilities be read? */
416 - rc = davConnect(u);
425 - *uret = urlLink(u, "davInit");
427 - u = urlFree(u, "urlSplit (davInit)");
432 -/* =============================================================== */
433 -enum fetch_rtype_e {
440 -struct fetch_resource_s {
442 - struct fetch_resource_s *next;
446 - enum fetch_rtype_e type;
450 - int is_vcr; /* Is version resource. 0: no vcr, 1 checkin 2 checkout */
451 - char *error_reason; /* error string returned for this resource */
452 - int error_status; /* error status returned for this resource */
456 -static void *fetch_destroy_item(/*@only@*/ struct fetch_resource_s *res)
457 - /*@modifies res @*/
460 - ne_free(res->error_reason);
467 -static void *fetch_destroy_list(/*@only@*/ struct fetch_resource_s *res)
468 - /*@modifies res @*/
470 - struct fetch_resource_s *next;
472 - for (; res != NULL; res = next) {
474 - res = fetch_destroy_item(res);
481 -#if WITH_NEON_MIN_VERSION >= 0x002600
482 -static void *fetch_create_item(/*@unused@*/ void *userdata, /*@unused@*/ const ne_uri *uri)
484 -static void *fetch_create_item(/*@unused@*/ void *userdata, /*@unused@*/ const char *uri)
488 - struct fetch_resource_s * res = ne_calloc(sizeof(*res));
492 -/* =============================================================== */
493 -struct fetch_context_s {
494 -/*@relnull@*/ /*@dependent@*/
495 - struct fetch_resource_s **resrock;
497 - unsigned int include_target; /* Include resource at href */
503 -/*@null@*/ /*@shared@*/
511 -static void *fetch_destroy_context(/*@only@*/ /*@null@*/ struct fetch_context_s *ctx)
512 - /*@globals internalState @*/
513 - /*@modifies ctx, internalState @*/
517 - if (ctx->av != NULL)
518 - ctx->av = argvFree(ctx->av);
519 - ctx->modes = _free(ctx->modes);
520 - ctx->sizes = _free(ctx->sizes);
521 - ctx->mtimes = _free(ctx->mtimes);
522 - ctx->u = urlFree(ctx->u, "fetch_destroy_context");
523 - ctx->uri = _free(ctx->uri);
525 - memset(ctx, 0, sizeof(*ctx));
532 -static void *fetch_create_context(const char *uri, /*@null@*/ struct stat *st)
533 - /*@globals internalState @*/
534 - /*@modifies internalState @*/
536 - struct fetch_context_s * ctx;
539 -/*@-globs@*/ /* FIX: h_errno annoyance. */
540 - if (urlSplit(uri, &u))
544 - ctx = ne_calloc(sizeof(*ctx));
545 - ctx->uri = xstrdup(uri);
546 - ctx->u = urlLink(u, "fetch_create_context");
547 - if ((ctx->st = st) != NULL)
548 - memset(ctx->st, 0, sizeof(*ctx->st));
552 -/*@unchecked@*/ /*@observer@*/
553 -static const ne_propname fetch_props[] = {
554 - { "DAV:", "getcontentlength" },
555 - { "DAV:", "getlastmodified" },
556 - { "http://apache.org/dav/props/", "executable" },
557 - { "DAV:", "resourcetype" },
558 - { "DAV:", "checked-in" },
559 - { "DAV:", "checked-out" },
563 -#define ELM_resourcetype (NE_PROPS_STATE_TOP + 1)
564 -#define ELM_collection (NE_PROPS_STATE_TOP + 2)
566 -/*@unchecked@*/ /*@observer@*/
567 -static const struct ne_xml_idmap fetch_idmap[] = {
568 - { "DAV:", "resourcetype", ELM_resourcetype },
569 - { "DAV:", "collection", ELM_collection }
572 -static int fetch_startelm(void *userdata, int parent,
573 - const char *nspace, const char *name,
574 - /*@unused@*/ const char **atts)
577 - ne_propfind_handler *pfh = userdata;
578 - struct fetch_resource_s *r = ne_propfind_current_private(pfh);
579 - int state = ne_xml_mapid(fetch_idmap, NE_XML_MAPLEN(fetch_idmap),
583 - !((parent == NE_207_STATE_PROP && state == ELM_resourcetype) ||
584 - (parent == ELM_resourcetype && state == ELM_collection)))
585 - return NE_XML_DECLINE;
587 - if (state == ELM_collection) {
588 - r->type = resr_collection;
594 -static int fetch_compare(const struct fetch_resource_s *r1,
595 - const struct fetch_resource_s *r2)
598 - /* Sort errors first, then collections, then alphabetically */
599 - if (r1->type == resr_error) {
601 - } else if (r2->type == resr_error) {
603 - } else if (r1->type == resr_collection) {
604 - if (r2->type != resr_collection) {
607 - return strcmp(r1->uri, r2->uri);
610 - if (r2->type != resr_collection) {
611 - return strcmp(r1->uri, r2->uri);
618 -#if WITH_NEON_MIN_VERSION >= 0x002600
619 -static void fetch_results(void *userdata, const ne_uri *uarg,
620 - const ne_prop_result_set *set)
622 -static void fetch_results(void *userdata, void *uarg,
623 - const ne_prop_result_set *set)
627 - struct fetch_context_s *ctx = userdata;
628 - struct fetch_resource_s *current, *previous, *newres;
629 - const char *clength, *modtime, *isexec;
630 - const char *checkin, *checkout;
631 - const ne_status *status = NULL;
632 - const char * path = NULL;
634 -#if WITH_NEON_MIN_VERSION >= 0x002600
635 - const ne_uri * uri = uarg;
636 - (void) urlPath(uri->path, &path);
638 - const char * uri = uarg;
639 - (void) urlPath(uri, &path);
644 - newres = ne_propset_private(set);
647 -fprintf(stderr, "==> %s in uri %s\n", path, ctx->uri);
649 - if (ne_path_compare(ctx->uri, path) == 0 && !ctx->include_target) {
650 - /* This is the target URI */
652 -fprintf(stderr, "==> %s skipping target resource.\n", path);
653 - /* Free the private structure. */
654 -/*@-dependenttrans -exposetrans@*/
656 -/*@=dependenttrans =exposetrans@*/
660 - newres->uri = ne_strdup(path);
663 - clength = ne_propset_value(set, &fetch_props[0]);
664 - modtime = ne_propset_value(set, &fetch_props[1]);
665 - isexec = ne_propset_value(set, &fetch_props[2]);
666 - checkin = ne_propset_value(set, &fetch_props[4]);
667 - checkout = ne_propset_value(set, &fetch_props[5]);
671 - if (clength == NULL)
672 - status = ne_propset_status(set, &fetch_props[0]);
673 - if (modtime == NULL)
674 - status = ne_propset_status(set, &fetch_props[1]);
677 - if (newres->type == resr_normal && status != NULL) {
678 - /* It's an error! */
679 - newres->error_status = status->code;
681 - /* Special hack for Apache 1.3/mod_dav */
682 - if (strcmp(status->reason_phrase, "status text goes here") == 0) {
684 - if (status->code == 401) {
685 - desc = _("Authorization Required");
686 - } else if (status->klass == 3) {
687 - desc = _("Redirect");
688 - } else if (status->klass == 5) {
689 - desc = _("Server Error");
691 - desc = _("Unknown Error");
693 - newres->error_reason = ne_strdup(desc);
695 - newres->error_reason = ne_strdup(status->reason_phrase);
697 - newres->type = resr_error;
700 - if (isexec && strcasecmp(isexec, "T") == 0) {
701 - newres->is_executable = 1;
703 - newres->is_executable = 0;
707 - newres->modtime = ne_httpdate_parse(modtime);
710 - newres->size = atoi(clength);
714 - newres->is_vcr = 1;
715 - } else if (checkout) {
716 - newres->is_vcr = 2;
718 - newres->is_vcr = 0;
721 - for (current = *ctx->resrock, previous = NULL; current != NULL;
722 - previous = current, current = current->next)
724 - if (fetch_compare(current, newres) >= 0) {
729 - previous->next = newres;
731 -/*@-boundswrite -dependenttrans @*/
732 - *ctx->resrock = newres;
733 -/*@=boundswrite =dependenttrans @*/
735 - newres->next = current;
738 -static int davFetch(const urlinfo u, struct fetch_context_s * ctx)
739 - /*@globals internalState @*/
740 - /*@modifies ctx, internalState @*/
742 - const char * path = NULL;
743 - int depth = 1; /* XXX passed arg? */
744 - unsigned int include_target = 0; /* XXX passed arg? */
745 - struct fetch_resource_s * resitem = NULL;
746 - struct fetch_resource_s ** resrock = &resitem; /* XXX passed arg? */
747 - ne_propfind_handler *pfh;
748 - struct fetch_resource_s *current, *next;
753 - (void) urlPath(u->url, &path);
754 - pfh = ne_propfind_create(u->sess, ctx->uri, depth);
756 - /* HACK: need to set RPMURL_SERVER_HASRANGE in u->allow here. */
758 - ctx->resrock = resrock;
759 - ctx->include_target = include_target;
761 - ne_xml_push_handler(ne_propfind_get_parser(pfh),
762 - fetch_startelm, NULL, NULL, pfh);
764 - ne_propfind_set_private(pfh, fetch_create_item, NULL);
766 - rc = ne_propfind_named(pfh, fetch_props, fetch_results, ctx);
768 - ne_propfind_destroy(pfh);
770 - for (current = resitem; current != NULL; current = next) {
771 - const char *s, *se;
774 - next = current->next;
776 - /* Collections have trailing '/' that needs trim. */
777 - /* The top level collection is returned as well. */
778 - se = current->uri + strlen(current->uri);
779 - if (se[-1] == '/') {
780 - if (strlen(current->uri) <= strlen(path)) {
781 - current = fetch_destroy_item(current);
787 - while (s > current->uri && s[-1] != '/')
790 - val = ne_strndup(s, (se - s));
793 - val = ne_path_unescape(val);
796 - xx = argvAdd(&ctx->av, val);
798 -fprintf(stderr, "*** argvAdd(%p,\"%s\")\n", &ctx->av, val);
801 - while (ctx->ac >= ctx->nalloced) {
802 - if (ctx->nalloced <= 0)
804 - ctx->nalloced *= 2;
805 - ctx->modes = xrealloc(ctx->modes,
806 - (sizeof(*ctx->modes) * ctx->nalloced));
807 - ctx->sizes = xrealloc(ctx->sizes,
808 - (sizeof(*ctx->sizes) * ctx->nalloced));
809 - ctx->mtimes = xrealloc(ctx->mtimes,
810 - (sizeof(*ctx->mtimes) * ctx->nalloced));
813 - switch (current->type) {
816 - /*@switchbreak@*/ break;
817 - case resr_collection:
819 - /*@switchbreak@*/ break;
820 - case resr_reference:
824 - /*@switchbreak@*/ break;
827 - ctx->modes[ctx->ac] = st_mode;
828 - ctx->sizes[ctx->ac] = current->size;
829 - ctx->mtimes[ctx->ac] = current->modtime;
833 - current = fetch_destroy_item(current);
835 - ctx->resrock = NULL; /* HACK: avoid leaving stack reference. */
836 - /* HACK realloc to truncate modes/sizes/mtimes */
841 -/* HACK this should be rewritten to use davReq/davResp w callbacks. */
842 -static int davHEAD(urlinfo u, struct stat *st)
843 - /*@modifies *st @*/
847 - const char *value = NULL;
850 - st->st_mode = S_IFREG;
851 - st->st_blksize = 4 * 1024; /* HACK correct for linux ext */
857 - req = ne_request_create(u->sess, "HEAD", u->url);
859 - rc = ne_request_dispatch(req);
865 - if (ne_get_status(req)->klass != 2) {
874 - value = ne_get_response_header(req, htag);
876 - /* inode-size-mtime */
880 - htag = "Content-Length";
881 -#if defined(HAVE_NEON_NE_GET_RESPONSE_HEADER)
882 - value = ne_get_response_header(req, htag);
885 - st->st_size = strtoll(value, NULL, 10);
886 - st->st_blocks = (st->st_size + 511)/512;
889 - htag = "Last-Modified";
890 -#if defined(HAVE_NEON_NE_GET_RESPONSE_HEADER)
891 - value = ne_get_response_header(req, htag);
894 - st->st_mtime = ne_httpdate_parse(value);
895 - st->st_atime = st->st_ctime = st->st_mtime; /* HACK */
899 - ne_request_destroy(req);
903 -static int davNLST(struct fetch_context_s * ctx)
904 - /*@globals internalState @*/
905 - /*@modifies ctx, internalState @*/
911 - rc = davInit(ctx->uri, &u);
912 - if (rc || u == NULL)
915 -/* HACK do PROPFIND through davFetch iff enabled, otherwise HEAD Content-length/ETag/Last-Modified */
916 - if (u->allow & RPMURL_SERVER_HASDAV)
917 - rc = davFetch(u, ctx); /* use PROPFIND to get contentLength */
919 - rc = davHEAD(u, ctx->st); /* use HEAD to get contentLength */
925 - /* HACK: "405 Method Not Allowed" for PROPFIND on non-DAV servers. */
926 - /* XXX #206066 OPTIONS is ok, but PROPFIND from Stat() fails. */
927 - /* rpm -qp --rpmiodebug --davdebug http://people.freedesktop.org/~sandmann/metacity-2.16.0-2.fc6/i386/metacity-2.16.0-2.fc6.i386.rpm */
928 - /* HACK: "301 Moved Permanently" on empty subdir. */
929 - if (!strncmp("301 ", ne_get_error(u->sess), sizeof("301 ")-1))
934 -fprintf(stderr, "*** Fetch from %s:%d failed:\n\t%s\n",
935 - u->host, u->port, ne_get_error(u->sess));
944 -/* =============================================================== */
945 -static int my_result(const char * msg, int ret, /*@null@*/ FILE * fp)
946 - /*@modifies *fp @*/
948 - /* HACK: don't print unless debugging. */
949 - if (_dav_debug >= 0)
954 - fprintf(fp, "*** %s: ", msg);
956 - /* HACK FTPERR_NE_FOO == -NE_FOO error impedance match */
958 - fprintf(fp, "%s: %s\n", ftpStrerror(-ret), ne_get_error(sess));
960 - fprintf(fp, "%s\n", ftpStrerror(-ret));
966 -static void hexdump(const unsigned char * buf, ssize_t len)
972 - for (i = 0; i < len; i++) {
973 - if (i != 0 && (i%16) == 0)
974 - fprintf(stderr, "\n");
975 - fprintf(stderr, " %02X", buf[i]);
977 - fprintf(stderr, "\n");
982 -static void davAcceptRanges(void * userdata, /*@null@*/ const char * value)
983 - /*@modifies userdata @*/
985 - urlinfo u = userdata;
987 - if (!(u != NULL && value != NULL)) return;
989 -fprintf(stderr, "*** u %p Accept-Ranges: %s\n", u, value);
990 - if (!strcmp(value, "bytes"))
991 - u->allow |= RPMURL_SERVER_HASRANGE;
992 - if (!strcmp(value, "none"))
993 - u->allow &= ~RPMURL_SERVER_HASRANGE;
997 -#if !defined(HAVE_NEON_NE_GET_RESPONSE_HEADER)
998 -static void davAllHeaders(void * userdata, const char * value)
1000 - FD_t ctrl = userdata;
1002 - if (!(ctrl != NULL && value != NULL)) return;
1004 -fprintf(stderr, "<- %s\n", value);
1009 -static void davContentLength(void * userdata, /*@null@*/ const char * value)
1010 - /*@modifies userdata @*/
1012 - FD_t ctrl = userdata;
1014 - if (!(ctrl != NULL && value != NULL)) return;
1015 -if (_dav_debug < 0)
1016 -fprintf(stderr, "*** fd %p Content-Length: %s\n", ctrl, value);
1018 - ctrl->contentLength = strtoll(value, NULL, 10);
1024 -static void davConnection(void * userdata, /*@null@*/ const char * value)
1025 - /*@modifies userdata @*/
1027 - FD_t ctrl = userdata;
1029 - if (!(ctrl != NULL && value != NULL)) return;
1030 -if (_dav_debug < 0)
1031 -fprintf(stderr, "*** fd %p Connection: %s\n", ctrl, value);
1032 - if (!strcasecmp(value, "close"))
1033 - ctrl->persist = 0;
1034 - else if (!strcasecmp(value, "Keep-Alive"))
1035 - ctrl->persist = 1;
1039 -/*@-mustmod@*/ /* HACK: stash error in *str. */
1040 -int davResp(urlinfo u, FD_t ctrl, /*@unused@*/ char *const * str)
1044 - rc = ne_begin_request(ctrl->req);
1045 - rc = my_result("ne_begin_req(ctrl->req)", rc, NULL);
1047 -if (_dav_debug < 0)
1048 -fprintf(stderr, "*** davResp(%p,%p,%p) sess %p req %p rc %d\n", u, ctrl, str, u->sess, ctrl->req, rc);
1050 - /* HACK FTPERR_NE_FOO == -NE_FOO error impedance match */
1051 -/*@-observertrans@*/
1053 - fdSetSyserrno(ctrl, errno, ftpStrerror(-rc));
1054 -/*@=observertrans@*/
1060 -int davReq(FD_t ctrl, const char * httpCmd, const char * httpArg)
1065 -assert(ctrl != NULL);
1069 -if (_dav_debug < 0)
1070 -fprintf(stderr, "*** davReq(%p,%s,\"%s\") entry sess %p req %p\n", ctrl, httpCmd, (httpArg ? httpArg : ""), u->sess, ctrl->req);
1072 - ctrl->persist = (u->httpVersion > 0 ? 1 : 0);
1073 - ctrl = fdLink(ctrl, "open ctrl (davReq)");
1075 -assert(u->sess != NULL);
1076 -assert(ctrl->req == NULL);
1078 - ctrl->req = ne_request_create(u->sess, httpCmd, httpArg);
1080 -assert(ctrl->req != NULL);
1082 - ne_set_request_private(ctrl->req, "fd", ctrl);
1084 -#if !defined(HAVE_NEON_NE_GET_RESPONSE_HEADER)
1085 - ne_add_response_header_catcher(ctrl->req, davAllHeaders, ctrl);
1087 - ne_add_response_header_handler(ctrl->req, "Content-Length",
1088 - davContentLength, ctrl);
1089 - ne_add_response_header_handler(ctrl->req, "Connection",
1090 - davConnection, ctrl);
1093 - if (!strcmp(httpCmd, "PUT")) {
1094 -#if defined(HAVE_NEON_NE_SEND_REQUEST_CHUNK)
1095 - ctrl->wr_chunked = 1;
1096 - ne_add_request_header(ctrl->req, "Transfer-Encoding", "chunked");
1097 - ne_set_request_chunked(ctrl->req, 1);
1098 - /* HACK: no retries if/when chunking. */
1099 - rc = davResp(u, ctrl, NULL);
1101 - rc = FTPERR_SERVER_IO_ERROR;
1104 - /* HACK: possible Last-Modified: Tue, 02 Nov 2004 14:29:36 GMT */
1105 - /* HACK: possible ETag: "inode-size-mtime" */
1106 -#if !defined(HAVE_NEON_NE_GET_RESPONSE_HEADER)
1107 - ne_add_response_header_handler(ctrl->req, "Accept-Ranges",
1108 - davAcceptRanges, u);
1110 - /* HACK: possible Transfer-Encoding: on GET. */
1112 - /* HACK: other errors may need retry too. */
1113 - /* HACK: neon retries once, gud enuf. */
1114 - /* HACK: retry counter? */
1116 - rc = davResp(u, ctrl, NULL);
1117 - } while (rc == NE_RETRY);
1122 -if (_dav_debug < 0)
1123 -fprintf(stderr, "*** davReq(%p,%s,\"%s\") exit sess %p req %p rc %d\n", ctrl, httpCmd, (httpArg ? httpArg : ""), u->sess, ctrl->req, rc);
1125 -#if defined(HAVE_NEON_NE_GET_RESPONSE_HEADER)
1126 - davContentLength(ctrl,
1127 - ne_get_response_header(ctrl->req, "Content-Length"));
1128 - davConnection(ctrl,
1129 - ne_get_response_header(ctrl->req, "Connection"));
1130 - if (strcmp(httpCmd, "PUT"))
1131 - davAcceptRanges(u,
1132 - ne_get_response_header(ctrl->req, "Accept-Ranges"));
1135 - ctrl = fdLink(ctrl, "open data (davReq)");
1139 -/*@-observertrans@*/
1140 - fdSetSyserrno(ctrl, errno, ftpStrerror(rc));
1141 -/*@=observertrans@*/
1143 - /* HACK balance fd refs. ne_session_destroy to tear down non-keepalive? */
1144 - ctrl = fdLink(ctrl, "error data (davReq)");
1149 -FD_t davOpen(const char * url, /*@unused@*/ int flags,
1150 - /*@unused@*/ mode_t mode, /*@out@*/ urlinfo * uret)
1152 - const char * path = NULL;
1153 - urltype urlType = urlPath(url, &path);
1158 -#if 0 /* XXX makeTempFile() heartburn */
1159 - assert(!(flags & O_RDWR));
1162 -if (_dav_debug < 0)
1163 -fprintf(stderr, "*** davOpen(%s,0x%x,0%o,%p)\n", url, flags, mode, uret);
1164 - rc = davInit(url, &u);
1165 - if (rc || u == NULL || u->sess == NULL)
1168 - if (u->ctrl == NULL)
1169 - u->ctrl = fdNew("persist ctrl (davOpen)");
1170 - if (u->ctrl->nrefs > 2 && u->data == NULL)
1171 - u->data = fdNew("persist data (davOpen)");
1173 - if (u->ctrl->url == NULL)
1174 - fd = fdLink(u->ctrl, "grab ctrl (davOpen persist ctrl)");
1175 - else if (u->data->url == NULL)
1176 - fd = fdLink(u->data, "grab ctrl (davOpen persist data)");
1178 - fd = fdNew("grab ctrl (davOpen)");
1181 - fdSetOpen(fd, url, flags, mode);
1182 - fdSetIo(fd, ufdio);
1184 - fd->ftpFileDoneNeeded = 0;
1185 - fd->rd_timeoutsecs = httpTimeoutSecs;
1186 - fd->contentLength = fd->bytesRemain = -1;
1187 - fd->url = urlLink(u, "url (davOpen)");
1188 - fd = fdLink(fd, "grab data (davOpen)");
1189 -assert(urlType == URL_IS_HTTPS || urlType == URL_IS_HTTP || urlType == URL_IS_HKP);
1190 - fd->urlType = urlType;
1198 - /*@-refcounttrans@*/
1200 - /*@=refcounttrans@*/
1203 -ssize_t davRead(void * cookie, /*@out@*/ char * buf, size_t count)
1209 -assert(count >= 128); /* HACK: see ne_request.h comment */
1211 - rc = ne_read_response_block(fd->req, buf, count);
1213 -if (_dav_debug < 0) {
1214 -fprintf(stderr, "*** davRead(%p,%p,0x%x) rc 0x%x\n", cookie, buf, (unsigned)count, (unsigned)rc);
1223 -ssize_t davWrite(void * cookie, const char * buf, size_t count)
1225 -#if !defined(NEONBLOWSCHUNKS) || defined(HAVE_NEON_NE_SEND_REQUEST_CHUNK) || defined(__LCLINT__)
1231 -#if !defined(NEONBLOWSCHUNKS)
1232 - ne_session * sess;
1234 -assert(fd->req != NULL);
1235 - sess = ne_get_session(fd->req);
1236 -assert(sess != NULL);
1238 - /* HACK: include ne_private.h to access sess->socket for now. */
1239 - xx = ne_sock_fullwrite(sess->socket, buf, count);
1241 -#if defined(HAVE_NEON_NE_SEND_REQUEST_CHUNK) || defined(__LCLINT__)
1242 -assert(fd->req != NULL);
1243 - xx = ne_send_request_chunk(fd->req, buf, count);
1245 - errno = EIO; /* HACK */
1250 - /* HACK: stupid error impedence matching. */
1251 - rc = (xx == 0 ? count : -1);
1253 -if (_dav_debug < 0)
1254 -fprintf(stderr, "*** davWrite(%p,%p,0x%x) rc 0x%x\n", cookie, buf, (unsigned)count, (unsigned)rc);
1257 -hexdump(buf, count);
1263 -int davSeek(void * cookie, /*@unused@*/ _libio_pos_t pos, int whence)
1265 -if (_dav_debug < 0)
1266 -fprintf(stderr, "*** davSeek(%p,pos,%d)\n", cookie, whence);
1270 -/*@-mustmod@*/ /* HACK: fd->req is modified. */
1271 -int davClose(void * cookie)
1278 -assert(fd->req != NULL);
1279 - rc = ne_end_request(fd->req);
1280 - rc = my_result("ne_end_request(req)", rc, NULL);
1282 - ne_request_destroy(fd->req);
1285 -if (_dav_debug < 0)
1286 -fprintf(stderr, "*** davClose(%p) rc %d\n", fd, rc);
1291 -/* =============================================================== */
1292 -int davMkdir(const char * path, mode_t mode)
1295 - const char * src = NULL;
1298 - rc = davInit(path, &u);
1302 - (void) urlPath(path, &src);
1304 - rc = ne_mkcol(u->sess, path);
1306 - if (rc) rc = -1; /* XXX HACK: errno impedance match */
1308 - /* XXX HACK: verify getrestype(remote) == resr_collection */
1312 -fprintf(stderr, "*** davMkdir(%s,0%o) rc %d\n", path, mode, rc);
1316 -int davRmdir(const char * path)
1319 - const char * src = NULL;
1322 - rc = davInit(path, &u);
1326 - (void) urlPath(path, &src);
1328 - /* XXX HACK: only getrestype(remote) == resr_collection */
1330 - rc = ne_delete(u->sess, path);
1332 - if (rc) rc = -1; /* XXX HACK: errno impedance match */
1336 -fprintf(stderr, "*** davRmdir(%s) rc %d\n", path, rc);
1340 -int davRename(const char * oldpath, const char * newpath)
1343 - const char * src = NULL;
1344 - const char * dst = NULL;
1345 - int overwrite = 1; /* HACK: set this correctly. */
1348 - rc = davInit(oldpath, &u);
1352 - (void) urlPath(oldpath, &src);
1353 - (void) urlPath(newpath, &dst);
1355 - /* XXX HACK: only getrestype(remote) != resr_collection */
1357 - rc = ne_move(u->sess, overwrite, src, dst);
1359 - if (rc) rc = -1; /* XXX HACK: errno impedance match */
1363 -fprintf(stderr, "*** davRename(%s,%s) rc %d\n", oldpath, newpath, rc);
1367 -int davUnlink(const char * path)
1370 - const char * src = NULL;
1373 - rc = davInit(path, &u);
1377 - (void) urlPath(path, &src);
1379 - /* XXX HACK: only getrestype(remote) != resr_collection */
1381 - rc = ne_delete(u->sess, src);
1384 - if (rc) rc = -1; /* XXX HACK: errno impedance match */
1387 -fprintf(stderr, "*** davUnlink(%s) rc %d\n", path, rc);
1392 -static int davChdir(const char * path)
1393 - /*@globals h_errno, fileSystem, internalState @*/
1394 - /*@modifies fileSystem, internalState @*/
1396 - return davCommand("CWD", path, NULL);
1398 -#endif /* NOTYET */
1400 -/* =============================================================== */
1402 -static const char * statstr(const struct stat * st,
1403 - /*@returned@*/ /*@out@*/ char * buf)
1404 - /*@modifies *buf @*/
1407 - "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n",
1408 - (unsigned)st->st_dev,
1409 - (unsigned)st->st_ino,
1411 - (unsigned)st->st_nlink,
1414 - (unsigned)st->st_rdev,
1415 - (unsigned)st->st_size);
1420 -static unsigned int dav_st_ino = 0xdead0000;
1423 -int davStat(const char * path, /*@out@*/ struct stat *st)
1424 - /*@globals dav_st_ino, fileSystem, internalState @*/
1425 - /*@modifies *st, dav_st_ino, fileSystem, internalState @*/
1427 - struct fetch_context_s * ctx = NULL;
1431 -/* HACK: neon really wants collections with trailing '/' */
1432 - ctx = fetch_create_context(path, st);
1433 - if (ctx == NULL) {
1434 -fprintf(stderr, "==> %s fetch_create_context ctx %p\n", "davStat", ctx);
1435 -/* HACK: errno = ??? */
1438 - rc = davNLST(ctx);
1440 -/* HACK: errno = ??? */
1444 - if (st->st_mode == 0)
1445 - st->st_mode = (ctx->ac > 1 ? S_IFDIR : S_IFREG);
1446 - st->st_size = (ctx->sizes ? ctx->sizes[0] : st->st_size);
1447 - st->st_mtime = (ctx->mtimes ? ctx->mtimes[0] : st->st_mtime);
1448 - st->st_atime = st->st_ctime = st->st_mtime; /* HACK */
1449 - if (S_ISDIR(st->st_mode)) {
1451 - st->st_mode |= 0755;
1453 - if (S_ISREG(st->st_mode)) {
1455 - st->st_mode |= 0644;
1458 - /* XXX fts(3) needs/uses st_ino, make something up for now. */
1459 - if (st->st_ino == 0)
1460 - st->st_ino = dav_st_ino++;
1463 -if (_dav_debug < 0)
1464 -fprintf(stderr, "*** davStat(%s) rc %d\n%s", path, rc, statstr(st, buf));
1465 - ctx = fetch_destroy_context(ctx);
1471 -int davLstat(const char * path, /*@out@*/ struct stat *st)
1472 - /*@globals dav_st_ino, fileSystem, internalState @*/
1473 - /*@modifies *st, dav_st_ino, fileSystem, internalState @*/
1475 - struct fetch_context_s * ctx = NULL;
1479 -/* HACK: neon really wants collections with trailing '/' */
1480 - ctx = fetch_create_context(path, st);
1481 - if (ctx == NULL) {
1482 -/* HACK: errno = ??? */
1485 - rc = davNLST(ctx);
1487 -/* HACK: errno = ??? */
1491 - if (st->st_mode == 0)
1492 - st->st_mode = (ctx->ac > 1 ? S_IFDIR : S_IFREG);
1493 - st->st_size = (ctx->sizes ? ctx->sizes[0] : st->st_size);
1494 - st->st_mtime = (ctx->mtimes ? ctx->mtimes[0] : st->st_mtime);
1495 - st->st_atime = st->st_ctime = st->st_mtime; /* HACK */
1496 - if (S_ISDIR(st->st_mode)) {
1498 - st->st_mode |= 0755;
1500 - if (S_ISREG(st->st_mode)) {
1502 - st->st_mode |= 0644;
1505 - /* XXX fts(3) needs/uses st_ino, make something up for now. */
1506 - if (st->st_ino == 0)
1507 - st->st_ino = dav_st_ino++;
1508 -if (_dav_debug < 0)
1509 -fprintf(stderr, "*** davLstat(%s) rc %d\n%s\n", path, rc, statstr(st, buf));
1511 - ctx = fetch_destroy_context(ctx);
1517 -static int davReadlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
1518 - /*@globals h_errno, fileSystem, internalState @*/
1519 - /*@modifies *buf, fileSystem, internalState @*/
1522 - rc = davNLST(path, DO_FTP_READLINK, NULL, buf, bufsiz);
1523 -if (_dav_debug < 0)
1524 -fprintf(stderr, "*** davReadlink(%s) rc %d\n", path, rc);
1527 -#endif /* NOTYET */
1529 /* =============================================================== */
1531 int avmagicdir = 0x3607113;
1532 @@ -1660,179 +145,3 @@
1537 -/* =============================================================== */
1539 -int davmagicdir = 0x8440291;
1541 -int davClosedir(/*@only@*/ DIR * dir)
1543 - DAVDIR avdir = (DAVDIR)dir;
1545 -if (_dav_debug < 0)
1546 -fprintf(stderr, "*** davClosedir(%p)\n", avdir);
1548 -#if defined(HAVE_PTHREAD_H)
1549 -/*@-moduncon -noeffectuncon @*/
1550 - (void) pthread_mutex_destroy(&avdir->lock);
1551 -/*@=moduncon =noeffectuncon @*/
1554 - avdir = _free(avdir);
1558 -struct dirent * davReaddir(DIR * dir)
1560 - DAVDIR avdir = (DAVDIR)dir;
1561 - struct dirent * dp;
1563 - unsigned char * dt;
1567 - if (avdir == NULL || !ISDAVMAGIC(avdir) || avdir->data == NULL) {
1568 - /* XXX TODO: EBADF errno. */
1572 - dp = (struct dirent *) avdir->data;
1573 - av = (const char **) (dp + 1);
1575 - dt = (unsigned char *) (av + (ac + 1));
1576 - i = avdir->offset + 1;
1579 - if (i < 0 || i >= ac || av[i] == NULL)
1583 - avdir->offset = i;
1585 - /* XXX glob(3) uses REAL_DIR_ENTRY(dp) test on d_ino */
1587 - dp->d_ino = i + 1; /* W2DO? */
1588 - dp->d_reclen = 0; /* W2DO? */
1590 -#if !(defined(hpux) || defined(__hpux) || defined(sun))
1591 -#if !defined(__APPLE__) && !defined(__FreeBSD_kernel__) && !defined(__FreeBSD__)
1592 - dp->d_off = 0; /* W2DO? */
1595 - dp->d_type = dt[i];
1600 - strncpy(dp->d_name, av[i], sizeof(dp->d_name));
1601 -if (_dav_debug < 0)
1602 -fprintf(stderr, "*** davReaddir(%p) %p \"%s\"\n", (void *)avdir, dp, dp->d_name);
1608 -DIR * davOpendir(const char * path)
1610 - struct fetch_context_s * ctx;
1612 - struct dirent * dp;
1614 - const char ** av, ** nav;
1615 - unsigned char * dt;
1620 - /* HACK: glob does not pass dirs with trailing '/' */
1621 - nb = strlen(path)+1;
1623 - if (path[nb-1] != '/') {
1624 - char * npath = alloca(nb+1);
1626 - (void) stpcpy( stpcpy(npath, path), "/");
1631 -if (_dav_debug < 0)
1632 -fprintf(stderr, "*** davOpendir(%s)\n", path);
1634 - /* Load DAV collection into argv. */
1635 - ctx = fetch_create_context(path, NULL);
1636 - if (ctx == NULL) {
1637 -/* HACK: errno = ??? */
1640 - rc = davNLST(ctx);
1642 -/* HACK: errno = ??? */
1650 - while (av[ac] != NULL)
1651 - nb += strlen(av[ac++]) + 1;
1652 - ac += 2; /* for "." and ".." */
1653 - nb += sizeof(".") + sizeof("..");
1655 - nb += sizeof(*avdir) + sizeof(*dp) + ((ac + 1) * sizeof(*av)) + (ac + 1);
1656 - avdir = xcalloc(1, nb);
1658 - dp = (struct dirent *) (avdir + 1);
1659 - nav = (const char **) (dp + 1);
1660 - dt = (unsigned char *) (nav + (ac + 1));
1661 - t = (char *) (dt + ac + 1);
1664 - avdir->fd = davmagicdir;
1666 - avdir->data = (char *) dp;
1668 - avdir->allocation = nb;
1670 - avdir->offset = -1;
1671 - avdir->filepos = 0;
1673 -#if defined(HAVE_PTHREAD_H)
1674 -/*@-moduncon -noeffectuncon -nullpass @*/
1675 - (void) pthread_mutex_init(&avdir->lock, NULL);
1676 -/*@=moduncon =noeffectuncon =nullpass @*/
1680 -/*@-dependenttrans -unrecog@*/
1681 - dt[nac] = DT_DIR; nav[nac++] = t; t = stpcpy(t, "."); t++;
1682 - dt[nac] = DT_DIR; nav[nac++] = t; t = stpcpy(t, ".."); t++;
1683 -/*@=dependenttrans =unrecog@*/
1685 - /* Copy DAV items into DIR elments. */
1688 - while (av[ac] != NULL) {
1690 - dt[nac] = (S_ISDIR(ctx->modes[ac]) ? DT_DIR : DT_REG);
1691 - t = stpcpy(t, av[ac]);
1698 - ctx = fetch_destroy_context(ctx);
1701 - return (DIR *) avdir;
1706 -char * davRealpath(const char * path, char * resolved_path)
1708 -assert(resolved_path == NULL); /* XXX no POSIXly broken realpath(3) here. */
1709 - /* XXX TODO: handle redirects. For now, just dupe the path. */
1710 - return xstrdup(path);
1712 --- rpm-4.5/rpmio/rpmdav.h 2007-05-25 20:36:36.000000000 +0300
1713 +++ rpm-4.4.9/rpmio/rpmdav.h 2008-09-04 17:21:50.369579599 +0300
1715 extern int avmagicdir;
1716 #define ISAVMAGIC(_dir) (!memcmp((_dir), &avmagicdir, sizeof(avmagicdir)))
1721 -extern int davmagicdir;
1722 -#define ISDAVMAGIC(_dir) (!memcmp((_dir), &davmagicdir, sizeof(davmagicdir)))
1728 /*@globals fileSystem, internalState @*/
1729 /*@modifies fileSystem, internalState @*/;
1732 - * Send a http request.
1734 - * @param httpCmd http command
1735 - * @param httpArg http command argument (NULL if none)
1736 - * @returns 0 on success
1738 -int davReq(FD_t ctrl, const char * httpCmd, /*@null@*/ const char * httpArg)
1739 - /*@globals fileSystem, internalState @*/
1740 - /*@modifies ctrl, fileSystem, internalState @*/;
1743 - * Read a http response.
1746 - * @retval *str error msg
1747 - * @returns 0 on success
1750 -int davResp(urlinfo u, FD_t ctrl, /*@out@*/ /*@null@*/ char *const * str)
1751 - /*@globals fileSystem, internalState @*/
1752 - /*@modifies ctrl, *str, fileSystem, internalState @*/;
1758 -FD_t davOpen(const char * url, /*@unused@*/ int flags,
1759 - /*@unused@*/ mode_t mode, /*@out@*/ urlinfo * uret)
1760 - /*@globals internalState @*/
1761 - /*@modifies *uret, internalState @*/;
1766 -ssize_t davRead(void * cookie, /*@out@*/ char * buf, size_t count)
1767 - /*@globals fileSystem, internalState @*/
1768 - /*@modifies buf, fileSystem, internalState @*/
1769 - /*@requires maxSet(buf) >= (count - 1) @*/
1770 - /*@ensures maxRead(buf) == result @*/;
1775 -ssize_t davWrite(void * cookie, const char * buf, size_t count)
1776 - /*@globals fileSystem, internalState @*/
1777 - /*@modifies fileSystem, internalState @*/;
1781 -int davSeek(void * cookie, _libio_pos_t pos, int whence)
1782 - /*@globals fileSystem, internalState @*/
1783 - /*@modifies fileSystem, internalState @*/;
1787 -int davClose(void * cookie)
1788 - /*@globals fileSystem, internalState @*/
1789 - /*@modifies cookie, fileSystem, internalState @*/;
1793 -int davMkdir(const char * path, mode_t mode)
1794 - /*@globals fileSystem, internalState @*/
1795 - /*@modifies fileSystem, internalState @*/;
1799 -int davRmdir(const char * path)
1800 - /*@globals fileSystem, internalState @*/
1801 - /*@modifies fileSystem, internalState @*/;
1805 -int davRename(const char * oldpath, const char * newpath)
1806 - /*@globals fileSystem, internalState @*/
1807 - /*@modifies fileSystem, internalState @*/;
1811 -int davUnlink(const char * path)
1812 - /*@globals fileSystem, internalState @*/
1813 - /*@modifies fileSystem, internalState @*/;
1816 - * Close a DAV collection.
1817 - * @param dir argv DIR
1818 - * @return 0 always
1820 -int davClosedir(/*@only@*/ DIR * dir)
1821 - /*@globals fileSystem @*/
1822 - /*@modifies dir, fileSystem @*/;
1825 - * Return next entry from a DAV collection.
1826 - * @param dir argv DIR
1827 - * @return next entry
1829 -/*@dependent@*/ /*@null@*/
1830 -struct dirent * davReaddir(DIR * dir)
1831 - /*@globals fileSystem @*/
1832 - /*@modifies fileSystem @*/;
1835 - * Create an argv directory from DAV collection.
1836 - * @param path URL for DAV collection path
1837 - * @return argv DIR
1840 -DIR * davOpendir(const char * path)
1841 - /*@globals fileSystem, internalState @*/
1842 - /*@modifies fileSystem, internalState @*/;
1847 -int davStat(const char * path, /*@out@*/ struct stat * st)
1848 - /*@globals fileSystem, internalState @*/
1849 - /*@modifies *st, fileSystem, internalState @*/;
1854 -int davLstat(const char * path, /*@out@*/ struct stat * st)
1855 - /*@globals fileSystem, internalState @*/
1856 - /*@modifies *st, fileSystem, internalState @*/;
1861 --- rpm-4.5/rpmio/rpmio.c 2008-09-04 18:04:37.362241187 +0300
1862 +++ rpm-4.5/rpmio/rpmio.c 2008-09-04 18:05:08.695569896 +0300
1863 @@ -155,11 +155,6 @@
1870 -int _dav_debug = 0;
1872 /* =============================================================== */
1875 @@ -386,13 +381,6 @@
1877 fdstat_enter(fd, FDSTAT_READ);
1879 - /* HACK: flimsy wiring for davRead */
1880 - if (fd->req != NULL) {
1881 - rc = davRead(fd, buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
1882 - /* XXX Chunked davRead EOF. */
1884 - fd->bytesRemain = 0;
1886 rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
1888 fdstat_exit(fd, FDSTAT_READ, rc);
1889 @@ -420,10 +408,6 @@
1891 fdstat_enter(fd, FDSTAT_WRITE);
1893 - /* HACK: flimsy wiring for davWrite */
1894 - if (fd->req != NULL)
1895 - rc = davWrite(fd, buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
1897 rc = write(fdno, buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
1899 fdstat_exit(fd, FDSTAT_WRITE, rc);
1900 @@ -470,11 +454,6 @@
1903 fdstat_enter(fd, FDSTAT_CLOSE);
1904 - /* HACK: flimsy wiring for davClose */
1906 - if (fd->req != NULL)
1907 - rc = davClose(fd);
1909 rc = ((fdno >= 0) ? close(fdno) : -2);
1911 fdstat_exit(fd, FDSTAT_CLOSE, rc);
1912 @@ -544,10 +523,6 @@
1916 - /* HACK: flimsy wiring for davWrite */
1917 - if (fd->req != NULL)
1920 if ((fdno = fdFileno(fd)) < 0)
1921 return -1; /* XXX W2DO? */
1923 @@ -599,10 +574,6 @@
1927 - /* HACK: flimsy wiring for davRead */
1928 - if (fd->req != NULL)
1931 if ((fdno = fdFileno(fd)) < 0)
1932 return -1; /* XXX W2DO? */
1934 @@ -2265,29 +2236,6 @@
1938 - case URL_IS_HTTPS:
1941 - fd = davOpen(url, flags, mode, &u);
1942 - if (fd == NULL || u == NULL)
1945 - cmd = ((flags & O_WRONLY)
1946 - ? ((flags & O_APPEND) ? "PUT" :
1947 - ((flags & O_CREAT) ? "PUT" : "PUT"))
1949 - u->openError = davReq(fd, cmd, path);
1950 - if (u->openError < 0) {
1951 - /* XXX make sure that we can exit through ufdClose */
1952 - fd = fdLink(fd, "error ctrl (ufdOpen HTTP)");
1953 - fd = fdLink(fd, "error data (ufdOpen HTTP)");
1955 - fd->bytesRemain = ((!strcmp(cmd, "GET"))
1956 - ? fd->contentLength : -1);
1957 - fd->wr_chunked = ((!strcmp(cmd, "PUT"))
1958 - ? fd->wr_chunked : 0);
1962 assert(!(flags & O_RDWR));
1963 fd = fdDup( ((flags & O_WRONLY) ? STDOUT_FILENO : STDIN_FILENO) );
1964 @@ -2911,10 +2859,8 @@
1965 if (fd->nfps > 0 && fpno == -1 &&
1966 fd->fps[fd->nfps-1].io == ufdio &&
1967 fd->fps[fd->nfps-1].fp == fp &&
1968 - (fd->fps[fd->nfps-1].fdno >= 0 || fd->req != NULL))
1969 + (fd->fps[fd->nfps-1].fdno >= 0))
1971 - int hadreqpersist = (fd->req != NULL);
1976 @@ -2924,26 +2870,9 @@
1978 if (fdGetFdno(fd) >= 0)
1981 - hadreqpersist = 0;
1985 - /* HACK: flimsy Keepalive wiring. */
1986 - if (hadreqpersist) {
1991 -/*@-refcounttrans@*/
1992 - (void) fdClose(fd);
1993 -/*@=refcounttrans@*/
1994 - fdSetFp(fd, NULL);
1996 -/*@-refcounttrans@*/
1997 - (void) fdClose(fd);
1998 -/*@=refcounttrans@*/
2003 @@ -3223,7 +3152,7 @@
2005 fprintf(stderr, "*** Fopen ufdio path %s fmode %s\n", path, fmode);
2006 fd = ufdOpen(path, flags, perms);
2007 - if (fd == NULL || !(fdFileno(fd) >= 0 || fd->req != NULL))
2008 + if (fd == NULL || !(fdFileno(fd) >= 0))
2012 @@ -3234,7 +3163,7 @@
2015 /* XXX persistent HTTP/1.1 returns the previously opened fp */
2016 - if (isHTTP && ((fp = fdGetFp(fd)) != NULL) && ((fdno = fdGetFdno(fd)) >= 0 || fd->req != NULL))
2017 + if (isHTTP && ((fp = fdGetFp(fd)) != NULL) && ((fdno = fdGetFdno(fd)) >= 0))
2020 fdPush(fd, fpio, fp, fileno(fp)); /* Push fpio onto stack */
2021 @@ -3276,10 +3205,6 @@
2024 if (fd == NULL) return -1;
2025 - if (fd->req != NULL) {
2026 - /* HACK: flimsy wiring for neon errors. */
2027 - rc = (fd->syserrno || fd->errcookie != NULL) ? -1 : 0;
2029 for (i = fd->nfps; rc == 0 && i >= 0; i--) {
2031 FDSTACK_t * fps = &fd->fps[i];
2032 @@ -3317,9 +3242,6 @@
2036 - if (fd->req != NULL)
2037 - rc = 123456789; /* HACK: https has no steenkin fileno. */
2039 for (i = fd->nfps ; rc == -1 && i >= 0; i--) {
2041 rc = fd->fps[i].fdno;
2042 --- rpm-4.5/rpmio/librpmio.vers~ 2008-07-09 12:38:31.000000000 +0300
2043 +++ rpm-4.5/rpmio/librpmio.vers 2008-09-04 17:52:56.158976430 +0300
2070 --- rpm-4.5/lib/poptALL.c~ 2007-10-23 18:53:08.000000000 +0300
2071 +++ rpm-4.5/lib/poptALL.c 2008-09-04 17:53:21.845642132 +0300
2073 extern int _ftp_debug;
2075 extern int _av_debug;
2077 -extern int _dav_debug;
2082 N_("debug FTP/HTTP data stream"), NULL},
2083 { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1,
2084 N_("debug argv collections"), NULL},
2085 - { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1,
2086 - N_("debug WebDAV data stream"), NULL},
2087 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
2089 { "miredebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_mire_debug, -1,
2090 --- rpm-4.5/rpmio/rpmrpc.c 2008-09-04 17:56:39.132287618 +0300
2091 +++ rpm-4.5/rpmio/rpmrpc.c 2008-09-04 17:57:38.618948392 +0300
2094 return ftpMkdir(path, mode);
2095 /*@notreached@*/ break;
2096 - case URL_IS_HTTPS:
2098 - return davMkdir(path, mode);
2099 - /*@notreached@*/ break;
2103 @@ -105,15 +101,6 @@
2105 return ftpChdir(path);
2106 /*@notreached@*/ break;
2107 - case URL_IS_HTTPS:
2110 - return davChdir(path);
2112 - errno = EINVAL; /* XXX W2DO? */
2115 - /*@notreached@*/ break;
2119 @@ -138,10 +125,6 @@
2121 return ftpRmdir(path);
2122 /*@notreached@*/ break;
2123 - case URL_IS_HTTPS:
2125 - return davRmdir(path);
2126 - /*@notreached@*/ break;
2130 @@ -245,10 +228,6 @@
2132 oldut = urlPath(oldpath, &oe);
2134 - case URL_IS_HTTPS:
2136 - return davRename(oldpath, newpath);
2137 - /*@notreached@*/ break;
2138 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
2140 case URL_IS_UNKNOWN:
2141 @@ -343,10 +322,6 @@
2143 return ftpUnlink(path);
2144 /*@notreached@*/ break;
2145 - case URL_IS_HTTPS:
2147 - return davUnlink(path);
2148 - /*@notreached@*/ break;
2152 @@ -1354,10 +1329,6 @@
2154 return ftpStat(path, st);
2155 /*@notreached@*/ break;
2156 - case URL_IS_HTTPS:
2158 - return davStat(path, st);
2159 - /*@notreached@*/ break;
2163 @@ -1384,10 +1355,6 @@
2165 return ftpLstat(path, st);
2166 /*@notreached@*/ break;
2167 - case URL_IS_HTTPS:
2169 - return davLstat(path, st);
2170 - /*@notreached@*/ break;
2174 @@ -1630,14 +1597,6 @@
2176 return ftpReadlink(path, buf, bufsiz);
2177 /*@notreached@*/ break;
2178 - case URL_IS_HTTPS:
2181 - return davReadlink(path, buf, bufsiz);
2185 - /*@notreached@*/ break;
2189 @@ -1787,10 +1746,6 @@
2191 return ftpOpendir(path);
2192 /*@notreached@*/ break;
2193 - case URL_IS_HTTPS:
2195 - return davOpendir(path);
2196 - /*@notreached@*/ break;
2200 @@ -1815,8 +1770,6 @@
2203 return avReaddir(dir);
2204 - if (ISDAVMAGIC(dir))
2205 - return davReaddir(dir);
2206 return readdir(dir);
2209 @@ -1828,8 +1781,6 @@
2212 return avClosedir(dir);
2213 - if (ISDAVMAGIC(dir))
2214 - return davClosedir(dir);
2215 return closedir(dir);
2218 @@ -1852,14 +1803,6 @@
2220 return ftpRealpath(path, resolved_path);
2221 /*@notreached@*/ break;
2222 - case URL_IS_HTTPS:
2226 - return davRealpath(path, resolved_path);
2227 - /*@notreached@*/ break;
2231 return xstrdup(path);
2232 /*@notreached@*/ break;
2233 --- rpm-4.5/./rpmio/rpmio_internal.h~ 2008-06-10 02:19:26.000000000 +0300
2234 +++ rpm-4.5/./rpmio/rpmio_internal.h 2008-09-04 18:00:31.015598325 +0300
2237 void * url; /* ufdio: URL info */
2239 - void * req; /* ufdio: HTTP request */
2241 int rd_timeoutsecs; /* ufdRead: per FD_t timer */
2242 ssize_t bytesRemain; /* ufdio: */
2243 --- rpm-4.5/rpmio/rpmurl.h~ 2008-06-10 02:19:26.000000000 +0300
2244 +++ rpm-4.5/rpmio/rpmurl.h 2008-09-04 18:14:00.546141703 +0300
2247 FD_t data; /*!< per-xfer data channel */
2250 - void * capabilities; /*!< neon: ne_server_capabilities ptr */
2252 - void * lockstore; /*!< neon: ne_lock_store ptr */
2254 - void * sess; /*!< neon: ne_session ptr */
2255 - off_t current; /*!< neon: current body offset. */
2256 - off_t total; /*!< neon: total body length. */
2257 - int connstatus; /*!< neon: connection status. */
2260 ne_conn_namelookup, /* lookup up hostname (info = hostname) */
2261 --- rpm-4.5/rpmio/url.c~ 2008-06-10 02:19:26.000000000 +0300
2262 +++ rpm-4.5/rpmio/url.c 2008-09-04 20:05:19.011716915 +0300
2264 (u->scheme ? u->scheme : ""));
2268 u->buf = _free(u->buf);
2269 u->url = _free(u->url);
2270 u->scheme = _free((void *)u->scheme);
2271 --- rpm-4.5/perl/Makefile.PL.in~ 2008-10-05 01:31:09.000000000 +0300
2272 +++ rpm-4.5/perl/Makefile.PL.in 2008-10-05 01:32:12.688278120 +0300
2275 'VERSION_FROM' => 'RPM.pm', # finds $VERSION
2276 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1
2277 - 'LIBS' => [join(' ', @ldaddp) . ' ' . join(' ', @ldadd) . ' @LIBS@ @WITH_POPT_LIB@ @WITH_BEECRYPT_LIB@ -lneon'],
2278 + 'LIBS' => [join(' ', @ldaddp) . ' ' . join(' ', @ldadd) . ' @LIBS@ @WITH_POPT_LIB@ @WITH_BEECRYPT_LIB@'],
2279 'DEFINE' => join(" ", @defines), # e.g., '-DHAVE_SOMETHING'
2280 'INC' => join(' ', map { '-I@top_srcdir@/'. $_ } @libdir) . ' @CPPFLAGS@',
2281 'TYPEMAPS' => [ 'typemap' ],
2282 --- rpm-4.5/configure.ac.orig 2011-02-21 16:29:42.000000000 +0100
2283 +++ rpm-4.5/configure.ac 2011-02-21 16:31:00.574910173 +0100
2284 @@ -591,28 +591,7 @@
2288 -AC_CHECK_HEADER([neon/ne_session.h], [
2289 - AC_CHECK_LIB(neon, ne_session_create, [
2290 - AC_DEFINE(HAVE_LIBNEON, 1, [Define to 1 if you have the 'neon' library (-lneon).])
2291 - AC_CHECK_LIB(neon, ne_get_response_header, [
2292 - AC_DEFINE(HAVE_NEON_NE_GET_RESPONSE_HEADER, 1, [Define to 1 if you have ne_get_response_header() in libneon.])
2294 - AC_CHECK_LIB(neon, ne_send_request_chunk, [
2295 - AC_DEFINE(HAVE_NEON_NE_SEND_REQUEST_CHUNK, 1, [Define to 1 if you have ne_send_request_chunk() in libneon.])
2297 - WITH_NEON_INCLUDE="-I${includedir}/neon"
2298 - WITH_NEON_LIB="-lneon"
2301 - if test -d neon ; then
2302 - AC_DEFINE(HAVE_LIBNEON, 1, [Define to 1 if you have the 'neon' library (-lneon).])
2303 -# XXX HAVE_NEON_NE_GET_RESPONSE_HEADER assumes libneon-0.25 devel internal
2304 - AC_DEFINE(HAVE_NEON_NE_GET_RESPONSE_HEADER, 1, [Define to 1 if you have ne_get_response_header() in libneon.])
2305 - WITH_NEON_SUBDIR=neon
2306 - WITH_NEON_INCLUDE="-I\${top_srcdir}/${WITH_NEON_SUBDIR}/src"
2307 - WITH_NEON_LIB="\${top_builddir}/${WITH_NEON_SUBDIR}/src/libneon.la"
2311 AC_SUBST(WITH_NEON_SUBDIR)
2312 AC_SUBST(WITH_NEON_INCLUDE)
2313 AC_SUBST(WITH_NEON_LIB)