poldek: poldek/vfile/ne_uri.c (NEW), poldek/vfile/Makefile.am, pol...
mis
mis at pld-linux.org
Mon Jul 2 17:57:24 CEST 2007
Author: mis Date: Mon Jul 2 15:57:24 2007 GMT
Module: poldek Tag: HEAD
---- Log message:
- uri_escape() from neon lib (#5808 at oldbugs.pld-linux.org)
---- Files affected:
poldek/poldek/vfile:
ne_uri.c (NONE -> 1.1) (NEW), Makefile.am (1.40 -> 1.41) , misc.c (1.12 -> 1.13)
poldek/poldek/vfile/vfff:
http.c (1.7 -> 1.8)
---- Diffs:
================================================================
Index: poldek/poldek/vfile/ne_uri.c
diff -u /dev/null poldek/poldek/vfile/ne_uri.c:1.1
--- /dev/null Mon Jul 2 17:57:24 2007
+++ poldek/poldek/vfile/ne_uri.c Mon Jul 2 17:57:19 2007
@@ -0,0 +1,155 @@
+/*
+ Stolen from neon library
+ $Id$
+*/
+
+/*
+ URI manipulation routines.
+ Copyright (C) 1999-2006, Joe Orton <joe at manyfish.co.uk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA
+
+*/
+
+#include "config.h"
+
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <stdio.h>
+
+#include <ctype.h>
+
+#include <trurl/nmalloc.h>
+
+/* URI ABNF from RFC 3986: */
+
+#define PS (0x0001) /* "+" */
+#define PC (0x0002) /* "%" */
+#define DS (0x0004) /* "-" */
+#define DT (0x0008) /* "." */
+#define US (0x0010) /* "_" */
+#define TD (0x0020) /* "~" */
+#define FS (0x0040) /* "/" */
+#define CL (0x0080) /* ":" */
+#define AT (0x0100) /* "@" */
+#define QU (0x0200) /* "?" */
+
+#define DG (0x0400) /* DIGIT */
+#define AL (0x0800) /* ALPHA */
+
+#define GD (0x1000) /* gen-delims = "#" / "[" / "]"
+ * ... except ":", "/", "@", and "?" */
+
+#define SD (0x2000) /* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
+ * / "*" / "+" / "," / ";" / "="
+ * ... except "+" which is PS */
+
+#define OT (0x4000) /* others */
+
+#define URI_ALPHA (AL)
+#define URI_DIGIT (DG)
+
+/* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" */
+#define URI_UNRESERVED (AL | DG | DS | DT | US | TD)
+/* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */
+#define URI_SCHEME (AL | DG | PS | DS | DT)
+/* real sub-delims definition, including "+" */
+#define URI_SUBDELIM (PS | SD)
+/* real gen-delims definition, including ":", "/", "@" and "?" */
+#define URI_GENDELIM (GD | CL | FS | AT | QU)
+/* userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) */
+#define URI_USERINFO (URI_UNRESERVED | PC | URI_SUBDELIM | CL)
+/* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" */
+#define URI_PCHAR (URI_UNRESERVED | PC | URI_SUBDELIM | CL | AT)
+/* invented: segchar = pchar / "/" */
+#define URI_SEGCHAR (URI_PCHAR | FS)
+/* query = fragment = *( pchar / "/" / "?" ) */
+#define URI_QUERY (URI_PCHAR | FS | QU)
+
+/* any characters which should be path-escaped: */
+#define URI_ESCAPE ((URI_GENDELIM & ~(FS)) | URI_SUBDELIM | OT | PC)
+
+static const unsigned int uri_chars[256] = {
+/* 0xXX x0 x2 x4 x6 x8 xA xC xE */
+/* 0x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* 1x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* 2x */ OT, SD, OT, GD, SD, PC, SD, SD, SD, SD, SD, PS, SD, DS, DT, FS,
+/* 3x */ DG, DG, DG, DG, DG, DG, DG, DG, DG, DG, CL, SD, OT, SD, OT, QU,
+/* 4x */ AT, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL,
+/* 5x */ AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, GD, OT, GD, OT, US,
+/* 6x */ OT, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL,
+/* 7x */ AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, OT, OT, OT, TD, OT,
+/* 8x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* 9x */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* Ax */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* Bx */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* Cx */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* Dx */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* Ex */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT,
+/* Fx */ OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT, OT
+};
+
+#define uri_lookup(ch) (uri_chars[(unsigned char)ch])
+
+/* CH must be an unsigned char; evaluates to 1 if CH should be
+ * percent-encoded. */
+#define path_escape_ch(ch) (uri_lookup(ch) & URI_ESCAPE)
+
+static char *ne_path_escape(const char *path)
+{
+ const unsigned char *pnt;
+ char *ret, *p;
+ size_t count = 0;
+
+ for (pnt = (const unsigned char *)path; *pnt != '\0'; pnt++) {
+ count += path_escape_ch(*pnt);
+ }
+
+ if (count == 0)
+ return NULL;
+
+ p = ret = n_malloc(strlen(path) + 2 * count + 1);
+ for (pnt = (const unsigned char *)path; *pnt != '\0'; pnt++) {
+ if (path_escape_ch(*pnt)) {
+ /* Escape it - %<hex><hex> */
+ sprintf(p, "%%%02x", (unsigned char) *pnt);
+ p += 3;
+ } else {
+ *p++ = *pnt;
+ }
+ }
+ *p = '\0';
+ return ret;
+}
+
+char *vfff_uri_escape(const char *path)
+{
+ return ne_path_escape(path);
+}
+
+
================================================================
Index: poldek/poldek/vfile/Makefile.am
diff -u poldek/poldek/vfile/Makefile.am:1.40 poldek/poldek/vfile/Makefile.am:1.41
--- poldek/poldek/vfile/Makefile.am:1.40 Tue Aug 22 17:43:00 2006
+++ poldek/poldek/vfile/Makefile.am Mon Jul 2 17:57:19 2007
@@ -13,9 +13,9 @@
libvfile_la_LDFLAGS = -version-info $(LIBVERSION) -export-symbols libvfile.sym
libvfile_la_SOURCES = vfile.c fetch.c vfetch.c vfprogress.c misc.c \
- p_open.c extcompr.c vfreq.c vfreq.h \
- vflock.c vfffmod.c \
- vopen3.c vopen3.h vfile_intern.h
+ p_open.c extcompr.c vfreq.c vfreq.h \
+ vflock.c vfffmod.c ne_uri.c \
+ vopen3.c vopen3.h vfile_intern.h
libvfile_la_LIBADD = vfff/libvfff.la
================================================================
Index: poldek/poldek/vfile/misc.c
diff -u poldek/poldek/vfile/misc.c:1.12 poldek/poldek/vfile/misc.c:1.13
--- poldek/poldek/vfile/misc.c:1.12 Wed Nov 2 20:45:40 2005
+++ poldek/poldek/vfile/misc.c Mon Jul 2 17:57:19 2007
@@ -78,9 +78,10 @@
default:
ndots = -1;
- if (!isalnum(*p) && strchr("-+/._@!~", *p) == NULL) {
+ if (!isalnum(*p) && strchr("-+/._@!~%{}[]()", *p) == NULL) {
vf_logerr("%s:%c non alphanumeric characters not allowed\n",
path, *p);
+ n_assert(0);
return 0;
}
================================================================
Index: poldek/poldek/vfile/vfff/http.c
diff -u poldek/poldek/vfile/vfff/http.c:1.7 poldek/poldek/vfile/vfff/http.c:1.8
--- poldek/poldek/vfile/vfff/http.c:1.7 Sun May 15 17:47:04 2005
+++ poldek/poldek/vfile/vfff/http.c Mon Jul 2 17:57:19 2007
@@ -47,6 +47,8 @@
#include "i18n.h"
#include "sigint/sigint.h"
+extern char *vfff_uri_escape(const char *path);
+
#ifndef VERSION
# define VERSION "3.1415926535897931"
#endif
@@ -119,17 +121,17 @@
extern int vhttp_misc_base64(char *b64, int size, const char *bin);
-static char *make_req_line(char *buf, int size, char *fmt, ...)
+static char *make_req_line(char *buf, int size, const char *method, const char *uri)
{
- va_list args;
- int n = 0;
+ char *escaped = NULL;
+ if ((escaped = vfff_uri_escape(uri)))
+ uri = escaped;
- va_start(args, fmt);
- n = n_vsnprintf(buf, size, fmt, args);
- va_end(args);
-
- n += n_snprintf(&buf[n], size - n, " HTTP/1.1\r\n");
+ n_snprintf(buf, size, "%s %s HTTP/1.1\r\n", method, uri);
+
+ if (escaped)
+ free(escaped);
return buf;
}
@@ -802,7 +804,7 @@
if (cn->state != VCN_ALIVE)
return 0;
- make_req_line(req_line, sizeof(req_line), "HEAD /");
+ make_req_line(req_line, sizeof(req_line), "HEAD", "/");
if (!httpcn_req(cn, req_line, NULL))
return 0;
@@ -883,7 +885,7 @@
vfff_errno = 0;
*rreq->redirected_to = '\0';
- make_req_line(req_line, sizeof(req_line), "HEAD %s", rreq->uri);
+ make_req_line(req_line, sizeof(req_line), "HEAD", rreq->uri);
if (!httpcn_req(cn, req_line, NULL))
return 0;
@@ -948,7 +950,7 @@
if (rreq->out_fdoff < 0)
rreq->out_fdoff = 0;
- make_req_line(req_line, sizeof(req_line), "GET %s", rreq->uri);
+ make_req_line(req_line, sizeof(req_line), "GET", rreq->uri);
if (rreq->out_fdoff > 0)
httpcn_req(cn, req_line, "Range: bytes=%ld-\r\n", rreq->out_fdoff);
================================================================
---- CVS-web:
http://cvs.pld-linux.org/poldek/poldek/vfile/Makefile.am?r1=1.40&r2=1.41&f=u
http://cvs.pld-linux.org/poldek/poldek/vfile/misc.c?r1=1.12&r2=1.13&f=u
http://cvs.pld-linux.org/poldek/poldek/vfile/vfff/http.c?r1=1.7&r2=1.8&f=u
More information about the pld-cvs-commit
mailing list