Changeset 7735

Show
Ignore:
Timestamp:
03/21/07 19:35:12 (22 months ago)
Author:
BradNeuberg
Message:

Created infrastructure to be able to give a 'testDomain' and a 'testDomainAddress' to test disconnected web applications on your own local machine -- Polipo doesn't look up the etc/hosts file, which would be difficult to parse, so we use this as an alternative. Tested on Safari, Firefox, and IE on Windows and Mac/x86

Location:
trunk/src/dot
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/dot/Makefile

    r7625 r7735  
    3535        cp -f proxy/config.win proxy-build/win/config 
    3636        cp -f proxy/default-pac proxy-build/win/.offline-pac 
     37        cp -f proxy/default-pac proxy-build/win/offline-pac 
    3738 
    3839run: 
  • trunk/src/dot/proxy-build/mac/x86/config

    r7727 r7735  
    4141# socksParentProxy = "localhost:9050" 
    4242# socksProxyType = socks5 
     43 
     44# A test URL that will actually resolve to the address given by  
     45# 'testDomainAddress'; useful because Polipo does not resolve your local  
     46# etc/hosts.conf file, which can 
     47# make testing disconnected web applications running on your local machine 
     48# difficult 
     49testDomain = "brad.com" 
     50testDomainAddress = "127.0.0.1" 
    4351 
    4452 
  • trunk/src/dot/proxy-build/win/config

    r7728 r7735  
    4141# socksParentProxy = "localhost:9050" 
    4242# socksProxyType = socks5 
     43 
     44# A test URL that will actually resolve to the address given by  
     45# 'testDomainAddress'; useful because Polipo does not resolve your local  
     46# etc/hosts.conf file, which can 
     47# make testing disconnected web applications running on your local machine 
     48# difficult 
     49testDomain = "brad.com" 
     50testDomainAddress = "192.168.1.108" 
    4351 
    4452 
  • trunk/src/dot/proxy/client.c

    r7727 r7735  
    870870       URL then remove it. */ 
    871871    url = removeBrowserBust(url); 
     872     
     873    /* if the domain is a fake domain, such as brad.com, that should 
     874       actually resolve against the local host then transform it. */ 
     875    url = handleTestDomain(url); 
    872876 
    873877    i = httpParseHeaders(1, url, 
     
    23212325    return internAtom(buffer); 
    23222326} 
     2327 
     2328/** Inside of the Polipo configuration file, a fake 'testDomain'  
     2329    can be specified that will actually resolve to the address 
     2330    given in 'testDomainAddress', such as 127.0.0.1; this can be  
     2331    useful for testing disconnected web applications that are  
     2332    running on your local laptop. */ 
     2333AtomPtr handleTestDomain(AtomPtr url){ 
     2334    char buffer[4096]; 
     2335    char *paramLoc = NULL; 
     2336    char *testDomainPtr = NULL; 
     2337    int finalLength, end, urlLoc, bufferLoc, finishedFinding = 0; 
     2338     
     2339    assert(url != NULL); 
     2340     
     2341    if(urlIsLocal(url->string, url->length)) 
     2342        return url; 
     2343     
     2344    if(testDomain == NULL || testDomainAddress == NULL) 
     2345        return url; 
     2346         
     2347    /* prevent buffer overflow attack */ 
     2348    /* the length after we have replaced the domain in  
     2349        'testDomain' with 'testDomainAddress' */ 
     2350    finalLength = url->length - testDomain->length  
     2351                    + testDomainAddress->length; 
     2352    if(finalLength >= 4095) 
     2353        return url; 
     2354     
     2355    /* do we have the test domain in our url? */     
     2356    paramLoc = strstr(url->string, testDomain->string); 
     2357    if(paramLoc == NULL) 
     2358        return url; 
     2359         
     2360    /* convert this into an actual location now using 
     2361       pointer arithmetic */ 
     2362    end = paramLoc - url->string; 
     2363         
     2364    /* copy up to this into our buffer */ 
     2365    strncpy(buffer, url->string, end); 
     2366    buffer[end] = '\0'; 
     2367     
     2368    /* now add the new address */ 
     2369    strncat(buffer, testDomainAddress->string,  
     2370            testDomainAddress->length); 
     2371    bufferLoc = strlen(buffer); 
     2372     
     2373    /* in the original string, find where the end of 
     2374        testDomain is */ 
     2375    testDomainPtr = testDomain->string; 
     2376    while(finishedFinding == 0){ 
     2377        if(*testDomainPtr != *paramLoc){ 
     2378            finishedFinding = 1; 
     2379            break; 
     2380        } 
     2381        paramLoc++; 
     2382        testDomainPtr++; 
     2383    } 
     2384    urlLoc = paramLoc - url->string; 
     2385     
     2386    /* now add the rest of this to our buffer */ 
     2387    while(urlLoc < url->length){ 
     2388        buffer[bufferLoc] = url->string[urlLoc]; 
     2389        bufferLoc++; 
     2390        urlLoc++; 
     2391    } 
     2392    buffer[bufferLoc] = '\0'; 
     2393     
     2394    /* decommision the old AtomPtr and create a new one */ 
     2395    releaseAtom(url); 
     2396    return internAtom(buffer); 
     2397} 
  • trunk/src/dot/proxy/client.h

    r7690 r7735  
    6767                           StreamRequestPtr srequest); 
    6868AtomPtr removeBrowserBust(AtomPtr url); 
     69AtomPtr handleTestDomain(AtomPtr url); 
  • trunk/src/dot/proxy/config.mac

    r7727 r7735  
    4141# socksParentProxy = "localhost:9050" 
    4242# socksProxyType = socks5 
     43 
     44# A test URL that will actually resolve to the address given by  
     45# 'testDomainAddress'; useful because Polipo does not resolve your local  
     46# etc/hosts.conf file, which can 
     47# make testing disconnected web applications running on your local machine 
     48# difficult 
     49testDomain = "brad.com" 
     50testDomainAddress = "127.0.0.1" 
    4351 
    4452 
  • trunk/src/dot/proxy/config.sample

    r7622 r7735  
    4242# socksProxyType = socks5 
    4343 
     44# A test URL that will actually resolve to the address given by  
     45# 'testDomainAddress'; useful because Polipo does not resolve your local  
     46# etc/hosts.conf file, which can 
     47# make testing disconnected web applications running on your local machine 
     48# difficult 
     49# testDomain = "brad.com" 
     50# testDomainAddress = "127.0.0.1" 
    4451 
    4552### Memory 
  • trunk/src/dot/proxy/config.win

    r7727 r7735  
    4141# socksParentProxy = "localhost:9050" 
    4242# socksProxyType = socks5 
     43 
     44# A test URL that will actually resolve to the address given by  
     45# 'testDomainAddress'; useful because Polipo does not resolve your local  
     46# etc/hosts.conf file, which can 
     47# make testing disconnected web applications running on your local machine 
     48# difficult 
     49testDomain = "brad.com" 
     50testDomainAddress = "192.168.1.108" 
    4351 
    4452 
  • trunk/src/dot/proxy/http.c

    r7727 r7735  
    6969 
    7070int disableVia = 1; 
     71 
     72AtomPtr testDomain = NULL; 
     73AtomPtr testDomainAddress = NULL; 
    7174 
    7275/* 0 means that all failures lead to errors.  1 means that failures to 
     
    124127    CONFIG_VARIABLE(dontTrustVaryETag, CONFIG_TRISTATE, 
    125128                    "Whether to trust the ETag when there's Vary."); 
     129    CONFIG_VARIABLE(testDomain, CONFIG_ATOM, 
     130                    "Fake domain for resolving against 'testDomainAddress' for testing purposes."); 
     131    CONFIG_VARIABLE(testDomainAddress, CONFIG_ATOM, 
     132                    "The address to resolve for 'testDomain'."); 
    126133    preinitHttpParser(); 
    127134} 
  • trunk/src/dot/proxy/http.h

    r7727 r7735  
    142142extern int disableVia; 
    143143extern int dontTrustVaryETag; 
     144extern AtomPtr testDomain; 
     145extern AtomPtr testDomainAddress; 
    144146 
    145147void preinitHttp(void); 
  • trunk/src/dot/proxy/local.c

    r7627 r7735  
    173173    cut_length = (cut_end - cut_start) + 2; 
    174174    host_ptr = (char *)malloc((unsigned) cut_length); 
     175    if(host_ptr == NULL) 
     176        return -1; 
    175177    cut_ptr = host_ptr; 
    176178    for(index = cut_start; index <= cut_end  
     
    186188 
    187189    *host_results = host_ptr; 
     190     
     191    /* if we have a 'testDomain', transform this host into 
     192        our 'testDomainAddress' value given in the config file. */ 
     193    if(testDomain == NULL || testDomainAddress == NULL) 
     194        return 1; 
     195     
     196    if(strlen(host_ptr) != testDomain->length) 
     197        return 1; 
     198         
     199    if(strcmp(host_ptr, testDomain->string) != 0) 
     200        return 1; 
     201         
     202    /* change the host to our full testDomainAddress */ 
     203    free(host_ptr); 
     204    host_ptr = (char *)malloc((unsigned int)(testDomainAddress->length + 1)); 
     205    if(host_ptr == NULL) 
     206        return -1; 
     207    strcpy(host_ptr, testDomainAddress->string); 
     208    *host_results = host_ptr; 
     209     
    188210    return 1; 
    189211}