Package: didiwiki / 0.5-13

20_redirect.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From: Alexey Khudyakov <alexey.skladnoy@gmail.com>
Subject: Fixes unicode chars on page names


diff -Naur didiwiki-0.5-deb/src/util.c didiwiki-0.5-patch/src/util.c
--- didiwiki-0.5-deb/src/util.c	2007-04-21 15:56:13.000000000 +0400
+++ didiwiki-0.5-patch/src/util.c	2007-04-21 15:57:27.000000000 +0400
@@ -189,3 +189,47 @@
   out[i] = 0;
   return out;
 }
+
+
+int validURIchar(char c)
+{
+    return 
+        (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+        c == '.' || c == '-' || c == '_' || c == '~' || c == '?';
+    /* question mark isn't allowed character, but I'm not going
+       to encode it */
+}
+
+/*
+ * Encodes character which aren't allowed in URIs
+ * like %D0
+ */
+char urienc[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
+char * util_httpize(const char* url)
+{
+    /* Find length of result string */
+    int i;
+    int len = 0;
+    for(i = 0; url[i]; ++i) {
+        if( validURIchar(url[i]) )
+            len++;
+        else 
+            len += 3;
+    }
+    char * out = malloc(sizeof(char)*(len + 1));
+    if( out == 0 ) return 0;
+    
+    out[len]=0;
+    int j = 0;
+    for( i = 0; url[i]; ++i ) {
+        if( validURIchar(url[i]) )
+            out[j++] = url[i];
+        else {
+            out[j++] = '%';
+            out[j++] = urienc[ (url[i]&0xF0) >> 4 ];
+            out[j++] = urienc[ url[i]&0x0F ];
+        }
+    }
+    return out;
+}
+
diff -Naur didiwiki-0.5-deb/src/util.h didiwiki-0.5-patch/src/util.h
--- didiwiki-0.5-deb/src/util.h	2007-04-21 15:56:13.000000000 +0400
+++ didiwiki-0.5-patch/src/util.h	2007-04-21 15:57:27.000000000 +0400
@@ -16,5 +16,6 @@
 char *
 util_htmlize(const char *in, int n);
 
-
+char * 
+util_httpize(const char* url);
 #endif
diff -Naur didiwiki-0.5-deb/src/wiki.c didiwiki-0.5-patch/src/wiki.c
--- didiwiki-0.5-deb/src/wiki.c	2007-04-21 15:56:13.000000000 +0400
+++ didiwiki-0.5-patch/src/wiki.c	2007-04-21 15:57:27.000000000 +0400
@@ -555,14 +555,17 @@
 
 }
 
-int 
+int
 wiki_redirect(HttpResponse *res, char *location)
 {
-  int   header_len = strlen(location) + 14; 
+  char *location_enc = util_httpize(location);
+  
+  int   header_len = strlen(location_enc) + 14; 
   char *header = alloca(sizeof(char)*header_len);
 
-  snprintf(header, header_len, "Location: %s\r\n", location);
-
+  snprintf(header, header_len, "Location: %s\r\n", location_enc);
+  free(location_enc);
+  
   http_response_append_header(res, header);
   http_response_printf(res, "<html>\n<p>Redirect to %s</p>\n</html>\n", 
 		       location);
@@ -573,6 +576,7 @@
 }
 
 
+
 void
 wiki_show_page(HttpResponse *res, char *wikitext, char *page)
 {