Changeset 7413
- Timestamp:
- 02/22/07 21:59:08 (23 months ago)
- Location:
- trunk/dot/proxy
- Files:
-
- 10 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/dot/proxy/client.c
r7359 r7413 726 726 AtomPtr headers; 727 727 CacheControlRec cache_control; 728 AtomPtr via, expect, auth ;728 AtomPtr via, expect, auth, referer; 729 729 HTTPConditionPtr condition; 730 730 HTTPRangeRec range; 731 732 printf("httpClientRequest\n"); 733 734 referer = NULL; 731 735 732 736 assert(!request->chandler); … … 738 742 &cache_control, &condition, &body_te, 739 743 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 740 &expect, &range, NULL, NULL, &via, &auth );744 &expect, &range, NULL, NULL, &via, &auth, &referer); 741 745 if(i < 0) { 742 746 releaseAtom(url); … … 796 800 request->cache_control = cache_control; 797 801 request->via = via; 802 request->referer = referer; 798 803 request->headers = headers; 799 804 request->condition = condition; -
trunk/dot/proxy/config.sample
r7390 r7413 84 84 # applications 85 85 86 # disableOfflineSupport = false87 88 86 disableOfflineSupport = false; 89 87 -
trunk/dot/proxy/http.c
r7359 r7413 646 646 httpDestroyCondition(request->condition); 647 647 releaseAtom(request->via); 648 releaseAtom(request->referer); 648 649 assert(request->chandler == NULL); 649 650 releaseAtom(request->error_message); -
trunk/dot/proxy/http.h
r7359 r7413 39 39 HTTPConditionPtr condition; 40 40 AtomPtr via; 41 AtomPtr referer; 41 42 struct _ConditionHandler *chandler; 42 43 ObjectPtr can_mutate; -
trunk/dot/proxy/http_parse.c
r7359 r7413 739 739 HTTPRangePtr range_return, HTTPRangePtr content_range_return, 740 740 char **location_return, AtomPtr *via_return, 741 AtomPtr *auth_return )741 AtomPtr *auth_return, AtomPtr *referer_return) 742 742 { 743 743 int local = url ? urlIsLocal(url->string, url->length) : 0; … … 762 762 AtomPtr auth = NULL; 763 763 AtomPtr expect = NULL; 764 AtomPtr referer = NULL; 764 765 HTTPConditionPtr condition; 765 766 time_t ims = -1, inms = -1; … … 799 800 800 801 name = internAtomLowerN(buf + name_start, name_end - name_start); 801 802 802 if(name == atomConnection) { 803 803 j = getNextTokenInList(buf, value_start, … … 917 917 } else if(name == atomReferer) { 918 918 int h; 919 920 if(referer_return) { 921 referer = internAtomN(buf + value_start, value_end - value_start); 922 if(referer == NULL) { 923 do_log(L_ERROR, "Couldn't allocate referer.\n"); 924 goto fail; 925 } 926 } 927 919 928 if(censorReferer == 0 || 920 929 (censorReferer == 1 && url != NULL && … … 1349 1358 releaseAtom(expect); 1350 1359 } 1360 if(referer_return) 1361 *referer_return = referer; 1362 else { 1363 if(referer) 1364 releaseAtom(referer); 1365 } 1351 1366 if(auth_return) 1352 1367 *auth_return = auth; -
trunk/dot/proxy/http_parse.h
r7359 r7413 48 48 time_t*, time_t*, time_t*, time_t*, time_t*, 49 49 int*, int*, char**, AtomPtr*, 50 HTTPRangePtr, HTTPRangePtr, char**, AtomPtr*, AtomPtr*); 50 HTTPRangePtr, HTTPRangePtr, char**, AtomPtr*, AtomPtr*, 51 AtomPtr*); 51 52 int httpFindHeader(AtomPtr header, const char *headers, int hlen, 52 53 int *value_begin_return, int *value_end_return); -
trunk/dot/proxy/local.c
r7390 r7413 115 115 } 116 116 117 #ifndef NO_DISK_CACHE118 119 static void120 recursiveIndexDiskObjects(FILE *out, char *root)121 {122 indexDiskObjects(out, root, 1);123 }124 125 static void126 plainIndexDiskObjects(FILE *out, char *root)127 {128 indexDiskObjects(out, root, 0);129 }130 #endif131 132 static void133 serversList(FILE *out, char *dummy)134 {135 listServers(out);136 }137 138 117 static int 139 118 matchUrl(char *base, ObjectPtr object) … … 145 124 return 0; 146 125 return (object->key_size == n) || (((char*)object->key)[n] == '?'); 126 } 127 128 #ifndef NO_OFFLINE_SUPPORT 129 130 static int getHost(AtomPtr referer, char **host_results){ 131 int cut_start = -1, cut_end = -1, cut_length; 132 int index; 133 char *cut_ptr; 134 char *host_ptr; 135 136 /* get the host name */ 137 /* find where the host name begins */ 138 for(index = 0; index < strlen(referer->string); index++){ 139 if(referer->string[index] == '/' 140 && (index + 1) < strlen(referer->string) 141 && referer->string[index + 1] == '/'){ 142 index = index + 2; 143 break; 144 } 145 } 146 147 if(index == strlen(referer->string)){ 148 /* nothing left to process */ 149 return -1; 150 } 151 152 /* find the end cut for where the host name is */ 153 cut_start = index; 154 while(index < strlen(referer->string)){ 155 if(referer->string[index] == '/' 156 || referer->string[index] == '?' 157 || referer->string[index] == ':' 158 || (index + 1) == strlen(referer->string)){ 159 cut_end = index - 1; 160 break; 161 } 162 index++; 163 } 164 165 if(cut_end == -1){ 166 return -1; 167 } 168 169 /* 170 +1 for index arrays starting at 0, 171 another +1 for end of string null character 172 */ 173 cut_length = (cut_end - cut_start) + 2; 174 host_ptr = (char *)malloc((unsigned) cut_length); 175 cut_ptr = host_ptr; 176 for(index = cut_start; index <= cut_end 177 && index < strlen(referer->string); index++){ 178 *cut_ptr = referer->string[index]; 179 cut_ptr++; 180 } 181 *cut_ptr = '\0'; 182 183 if(strlen(host_ptr) == 0){ 184 return -1; 185 } 186 187 *host_results = host_ptr; 188 return 1; 189 } 190 191 static void 192 handleOfflineAPI(ObjectPtr object, HTTPRequestPtr requestor) 193 { 194 AtomPtr referer; 195 char *host_ptr = NULL; 196 int safe_scheme = 0; 197 int status; 198 199 if(requestor->referer == NULL 200 || requestor->referer->string == NULL 201 || strlen(requestor->referer->string) == 0) { 202 goto fail; 203 } 204 205 referer = requestor->referer; 206 207 /* make sure we have a scheme we know how to work with */ 208 if(strlen(referer->string) >= 4 209 && lwrcmp(referer->string, "http", 4) == 0) { 210 safe_scheme = 1; 211 }else if(strlen(referer->string) >= 5 212 && lwrcmp(referer->string, "https", 5) == 0) { 213 safe_scheme = 1; 214 } 215 216 if(safe_scheme == 0){ 217 goto fail; 218 } 219 220 /* get the host inside of the referer header */ 221 status = getHost(referer, &host_ptr); 222 if(status == -1){ 223 goto fail; 224 } 225 226 /* 227 get the type of API request desired: 228 addOfflineHost, removeOfflineHost, isHostAvailableOffline, 229 isRunning, getVersion 230 */ 231 printf("results=%s\n", host_ptr); 232 if(matchUrl("/polipo/offline?addOfflineHost", object)){ 233 status = addOfflineHost(host_ptr); 234 objectPrintf(object, 0, 235 "%s('addOfflineHost', %s);", 236 OFF_JAVASCRIPT_CALLBACK, 237 (status == 1) ? "true" : "false"); 238 object->length = object->size; 239 }else if(matchUrl("/polipo/offline?removeOfflineHost", object)){ 240 status = removeOfflineHost(host_ptr); 241 objectPrintf(object, 0, 242 "%s('removeOfflineHost', %s);", 243 OFF_JAVASCRIPT_CALLBACK, 244 (status == 1) ? "true" : "false"); 245 object->length = object->size; 246 }else if(matchUrl("/polipo/offline?isHostAvailableOffline", object)){ 247 status = isHostAvailableOffline(host_ptr); 248 objectPrintf(object, 0, 249 "%s('isHostAvailableOffline', %s);", 250 OFF_JAVASCRIPT_CALLBACK, 251 (status == 1) ? "true" : "false"); 252 object->length = object->size; 253 }else if(matchUrl("/polipo/offline?isRunning", object)){ 254 objectPrintf(object, 0, 255 "%s('isRunning', true);", 256 OFF_JAVASCRIPT_CALLBACK); 257 object->length = object->size; 258 }else if(matchUrl("/polipo/offline?getVersion", object)){ 259 objectPrintf(object, 0, 260 "%s('getVersion', '%s');", 261 OFF_JAVASCRIPT_CALLBACK, 262 OFF_OFFLINE_VERSION); 263 object->length = object->size; 264 }else{ 265 goto fail; 266 } 267 268 if(host_ptr){ 269 free(host_ptr); 270 } 271 272 return; 273 274 fail: 275 objectPrintf(object, 0, 276 "%s('UnknownMethod', null);", 277 OFF_JAVASCRIPT_CALLBACK); 278 object->length = object->size; 279 280 if(host_ptr){ 281 free(host_ptr); 282 } 283 } 284 285 #endif 286 287 #ifndef NO_DISK_CACHE 288 289 static void 290 recursiveIndexDiskObjects(FILE *out, char *root) 291 { 292 indexDiskObjects(out, root, 1); 293 } 294 295 static void 296 plainIndexDiskObjects(FILE *out, char *root) 297 { 298 indexDiskObjects(out, root, 0); 299 } 300 #endif 301 302 static void 303 serversList(FILE *out, char *dummy) 304 { 305 listServers(out); 147 306 } 148 307 … … 202 361 "</body></html>\n"); 203 362 object->length = object->size; 363 #ifndef NO_OFFLINE_SUPPORT 204 364 } else if(disableOfflineSupport == 0 && 205 365 matchUrl("/polipo/offline", object)) { 206 objectPrintf(object, 0, 207 "alert(\"Hello from content type world\")"); 208 object->length = object->size; 366 handleOfflineAPI(object, requestor); 367 #endif 209 368 } else if(matchUrl("/polipo/status", object)) { 210 369 objectPrintf(object, 0, -
trunk/dot/proxy/off.c
r7378 r7413 115 115 struct offline_list_entry *entry_ptr; 116 116 struct offline_list_entry *new_entry_ptr; 117 int status; 117 118 118 119 if(isValidHost(host) == 0){ /* invalid host */ … … 154 155 } 155 156 156 return 1; /* success */ 157 /* try to save the offline list */ 158 status = saveOfflineList(); 159 160 return status; 157 161 } 158 162 … … 160 164 struct offline_list_entry *entry_ptr, *prev_ptr, 161 165 *found_ptr; 166 int successful = 0; 162 167 163 168 found_ptr = NULL; … … 197 202 offline_list_ptr = found_ptr->next_ptr; 198 203 free(found_ptr); 199 return 1; /* success */204 successful = 1; 200 205 } 201 206 … … 204 209 prev_ptr->next_ptr = NULL; 205 210 free(found_ptr); 206 return 1; /* success */211 successful = 1; 207 212 } 208 213 … … 211 216 prev_ptr->next_ptr = found_ptr->next_ptr; 212 217 free(found_ptr); 213 return 1; /* success */ 214 } 215 216 return 0; /* failed */ 218 successful = 1; 219 } 220 221 if(successful == 0){ 222 return 0; /* failed */ 223 }else{ 224 /* try to save the offline list */ 225 successful = saveOfflineList(); 226 return successful; 227 } 217 228 } 218 229 -
trunk/dot/proxy/off.h
r7374 r7413 15 15 #define OFF_BOOTSTRAP_HOST "offline.web.app" 16 16 17 /* 18 The JavaScript callback function name that will receive 19 the results of a call to the offline API. Two arguments 20 will be given: the API function that was called, such as 21 "isRunning", and the results of this call, which is call 22 dependent. If an unknown method was called then the 23 method name is "UnknownMethod". 24 25 Example: 26 27 durableCacheCallback("isRunning", true); 28 */ 29 #define OFF_JAVASCRIPT_CALLBACK "durableCacheCallback" 30 31 /* 32 The version of our offline system. This is not the same as 33 our Polipo version, since the offline architecture could 34 potentially include other components such as SQLite. 35 */ 36 #define OFF_OFFLINE_VERSION "0.01" 17 37 18 38 /** -
trunk/dot/proxy/server.c
r7359 r7413 1899 1899 &date, &last_modified, &expires, NULL, NULL, NULL, 1900 1900 &age, &etag, NULL, NULL, &content_range, 1901 NULL, &via, NULL );1901 NULL, &via, NULL, NULL); 1902 1902 if(rc < 0) { 1903 1903 do_log(L_ERROR, "Couldn't parse server headers\n");