summaryrefslogtreecommitdiffstats
path: root/web/attachments/227858-check_httppatch.txt
blob: 08bf2ffa6dbae6a82565f445e0ff9d664335b8de (plain)
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
100
101
102
103
--- check_http.c        2007-03-06 14:45:57.000000000 -0800
+++ -   2007-05-04 11:00:35.226089000 -0700
@@ -110,7 +110,7 @@
 int http_opt_headers_count = 0;
 int onredirect = STATE_OK;
 int use_ssl = FALSE;
-int verbose = FALSE;
+int verbose = TRUE;
 int sd;
 int min_page_len = 0;
 int max_page_len = 0;
@@ -751,6 +751,17 @@
   char *header;
   char *page;
   char *auth;
+/* Patched by T.P -- binary data */
+  char bindata[MAX_INPUT_BUFFER];
+  int bindatalen = 0;
+  int bindatafound = 0;
+  int bufpos=0;
+  int mybuflen=0;
+  char *pointer = http_post_data;
+  unsigned long ascii = 0;
+  char code[3] = {0};
+  char *end = NULL;
+/* End patch */
   int http_status;
   int i = 0;
   size_t pagesize = 0;
@@ -800,14 +811,42 @@
 
   /* either send http POST data */
   if (http_post_data) {
+/*  Patched by T.P -- binary data */
+    while (*pointer) {
+      if (*pointer == '%') {
+        /* Interpret the next two hex chars -- no error checking */
+        memcpy(code,++pointer,2);
+        ascii = strtoul(code,&end,16);
+        bindata[bindatalen] = (char)ascii;
+        pointer += 2;
+      } else if (*pointer == '\\') {
+        /* Skip the escape char -- no error checking */
+        pointer++;
+        bindata[bindatalen++] = *pointer++;
+      } else {
+        /* Just copy the char */
+        bindata[bindatalen] = *pointer++;
+      }
+      bindatalen++;
+    }
+    /* Truncate the original string at the shorter length for future use */
+    http_post_data[bindatalen] = (char)0;
+/* End patch */
     if (http_content_type) {
       asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type);
     } else {
       asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
     }
     
+/* Patched by T.P -- binary data */
+    /* original line
     asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data));
+    */
+    asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, bindatalen);
+    /* Print the original (ascii, truncated) string to fill space */
     asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF);
+    bufpos = strlen(buf) - bindatalen - 2;
+/* End patch */
   }
   else {
     /* or just a newline so the server knows we're done with the request */
@@ -815,13 +854,29 @@
   }
 
   if (verbose) printf ("%s\n", buf);
-  my_send (buf, strlen (buf));
+/* Patched by T.P -- binary data */
+  if (bindatalen) {
+    mybuflen = strlen(buf);
+    /* Overwrite it with the (possibly) binary data */
+    for (i=0;i<bindatalen;i++) {
+      buf[i+bufpos] = bindata[i];
+    }
+    my_send (buf, mybuflen);
+  } else {
+  /* original line */
+    my_send (buf, strlen (buf));
+  }
 
   /* fetch the page */
   full_page = strdup("");
+  pointer=full_page;
   while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) {
+    /* Original lines
     buffer[i] = '\0';
     asprintf (&full_page, "%s%s", full_page, buffer);
+    */
+    memcpy(pointer+pagesize,buffer,i);
+/* End patch */
     pagesize += i;
 
                 if (no_body && document_headers_done (full_page)) {