Fossil SCM
Fix out-of-order variable declaration (VC6 cannot handle that). Move MAX_REDIRECTS definition to xfer.c, so it can be converted to a fossil setting later.
Commit
fe56e5aa4f000b9498966c0aabf050e7973ffb19
Parent
13ffb9b4d1eb3f9…
2 files changed
+5
-19
+8
-1
+5
-19
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -120,16 +120,10 @@ | ||
| 120 | 120 | blob_appendf(pHdr, "Content-Type: application/x-fossil\r\n"); |
| 121 | 121 | } |
| 122 | 122 | blob_appendf(pHdr, "Content-Length: %d\r\n\r\n", blob_size(pPayload)); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | -/* | |
| 126 | -** Maximum number of HTTP redirects that any http_exchange() call will | |
| 127 | -** follow before throwing a fatal error. Most browsers use a limit of 20. | |
| 128 | -*/ | |
| 129 | -#define MAX_REDIRECTS 20 | |
| 130 | - | |
| 131 | 125 | /* |
| 132 | 126 | ** Sign the content in pSend, compress it, and send it to the server |
| 133 | 127 | ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply |
| 134 | 128 | ** in pRecv. pRecv is assumed to be uninitialized when |
| 135 | 129 | ** this routine is called - this routine will initialize it. |
| @@ -136,20 +130,11 @@ | ||
| 136 | 130 | ** |
| 137 | 131 | ** The server address is contain in the "g" global structure. The |
| 138 | 132 | ** url_parse() routine should have been called prior to this routine |
| 139 | 133 | ** in order to fill this structure appropriately. |
| 140 | 134 | */ |
| 141 | -int http_exchange(Blob *pSend, Blob *pReply, int useLogin){ | |
| 142 | - return _http_exchange(pSend, pReply, useLogin, 0); | |
| 143 | -} | |
| 144 | - | |
| 145 | -/* | |
| 146 | -** Actual implementation details of http_exchange(). This is done so we can | |
| 147 | -** track the number of redirects without changing the signature of that | |
| 148 | -** function and requiring callers to initialize numRedirects. | |
| 149 | -*/ | |
| 150 | -int _http_exchange(Blob *pSend, Blob *pReply, int useLogin, int numRedirects){ | |
| 135 | +int http_exchange(Blob *pSend, Blob *pReply, int useLogin, int maxRedirect){ | |
| 151 | 136 | Blob login; /* The login card */ |
| 152 | 137 | Blob payload; /* The complete payload including login card */ |
| 153 | 138 | Blob hdr; /* The HTTP request header */ |
| 154 | 139 | int closeConnection; /* True to close the connection when done */ |
| 155 | 140 | int iLength; /* Length of the reply payload */ |
| @@ -245,14 +230,15 @@ | ||
| 245 | 230 | closeConnection = 1; |
| 246 | 231 | }else if( c=='k' || c=='K' ){ |
| 247 | 232 | closeConnection = 0; |
| 248 | 233 | } |
| 249 | 234 | }else if( rc==302 && fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 250 | - if ( numRedirects>=MAX_REDIRECTS ){ | |
| 235 | + int i, j; | |
| 236 | + | |
| 237 | + if ( --maxRedirect == 0){ | |
| 251 | 238 | fossil_fatal("redirect limit exceeded"); |
| 252 | 239 | } |
| 253 | - int i, j; | |
| 254 | 240 | for(i=9; zLine[i] && zLine[i]==' '; i++){} |
| 255 | 241 | if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine); |
| 256 | 242 | j = strlen(zLine) - 1; |
| 257 | 243 | while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){ |
| 258 | 244 | j -= 4; |
| @@ -259,11 +245,11 @@ | ||
| 259 | 245 | zLine[j] = 0; |
| 260 | 246 | } |
| 261 | 247 | fossil_print("redirect to %s\n", &zLine[i]); |
| 262 | 248 | url_parse(&zLine[i]); |
| 263 | 249 | transport_close(); |
| 264 | - return _http_exchange(pSend, pReply, useLogin, numRedirects + 1); | |
| 250 | + return http_exchange(pSend, pReply, useLogin, maxRedirect); | |
| 265 | 251 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 266 | 252 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 267 | 253 | isCompressed = 0; |
| 268 | 254 | }else if( fossil_strnicmp(&zLine[14], |
| 269 | 255 | "application/x-fossil-uncompressed", -1)==0 ){ |
| 270 | 256 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -120,16 +120,10 @@ | |
| 120 | blob_appendf(pHdr, "Content-Type: application/x-fossil\r\n"); |
| 121 | } |
| 122 | blob_appendf(pHdr, "Content-Length: %d\r\n\r\n", blob_size(pPayload)); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | ** Maximum number of HTTP redirects that any http_exchange() call will |
| 127 | ** follow before throwing a fatal error. Most browsers use a limit of 20. |
| 128 | */ |
| 129 | #define MAX_REDIRECTS 20 |
| 130 | |
| 131 | /* |
| 132 | ** Sign the content in pSend, compress it, and send it to the server |
| 133 | ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply |
| 134 | ** in pRecv. pRecv is assumed to be uninitialized when |
| 135 | ** this routine is called - this routine will initialize it. |
| @@ -136,20 +130,11 @@ | |
| 136 | ** |
| 137 | ** The server address is contain in the "g" global structure. The |
| 138 | ** url_parse() routine should have been called prior to this routine |
| 139 | ** in order to fill this structure appropriately. |
| 140 | */ |
| 141 | int http_exchange(Blob *pSend, Blob *pReply, int useLogin){ |
| 142 | return _http_exchange(pSend, pReply, useLogin, 0); |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | ** Actual implementation details of http_exchange(). This is done so we can |
| 147 | ** track the number of redirects without changing the signature of that |
| 148 | ** function and requiring callers to initialize numRedirects. |
| 149 | */ |
| 150 | int _http_exchange(Blob *pSend, Blob *pReply, int useLogin, int numRedirects){ |
| 151 | Blob login; /* The login card */ |
| 152 | Blob payload; /* The complete payload including login card */ |
| 153 | Blob hdr; /* The HTTP request header */ |
| 154 | int closeConnection; /* True to close the connection when done */ |
| 155 | int iLength; /* Length of the reply payload */ |
| @@ -245,14 +230,15 @@ | |
| 245 | closeConnection = 1; |
| 246 | }else if( c=='k' || c=='K' ){ |
| 247 | closeConnection = 0; |
| 248 | } |
| 249 | }else if( rc==302 && fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 250 | if ( numRedirects>=MAX_REDIRECTS ){ |
| 251 | fossil_fatal("redirect limit exceeded"); |
| 252 | } |
| 253 | int i, j; |
| 254 | for(i=9; zLine[i] && zLine[i]==' '; i++){} |
| 255 | if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine); |
| 256 | j = strlen(zLine) - 1; |
| 257 | while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){ |
| 258 | j -= 4; |
| @@ -259,11 +245,11 @@ | |
| 259 | zLine[j] = 0; |
| 260 | } |
| 261 | fossil_print("redirect to %s\n", &zLine[i]); |
| 262 | url_parse(&zLine[i]); |
| 263 | transport_close(); |
| 264 | return _http_exchange(pSend, pReply, useLogin, numRedirects + 1); |
| 265 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 266 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 267 | isCompressed = 0; |
| 268 | }else if( fossil_strnicmp(&zLine[14], |
| 269 | "application/x-fossil-uncompressed", -1)==0 ){ |
| 270 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -120,16 +120,10 @@ | |
| 120 | blob_appendf(pHdr, "Content-Type: application/x-fossil\r\n"); |
| 121 | } |
| 122 | blob_appendf(pHdr, "Content-Length: %d\r\n\r\n", blob_size(pPayload)); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | ** Sign the content in pSend, compress it, and send it to the server |
| 127 | ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply |
| 128 | ** in pRecv. pRecv is assumed to be uninitialized when |
| 129 | ** this routine is called - this routine will initialize it. |
| @@ -136,20 +130,11 @@ | |
| 130 | ** |
| 131 | ** The server address is contain in the "g" global structure. The |
| 132 | ** url_parse() routine should have been called prior to this routine |
| 133 | ** in order to fill this structure appropriately. |
| 134 | */ |
| 135 | int http_exchange(Blob *pSend, Blob *pReply, int useLogin, int maxRedirect){ |
| 136 | Blob login; /* The login card */ |
| 137 | Blob payload; /* The complete payload including login card */ |
| 138 | Blob hdr; /* The HTTP request header */ |
| 139 | int closeConnection; /* True to close the connection when done */ |
| 140 | int iLength; /* Length of the reply payload */ |
| @@ -245,14 +230,15 @@ | |
| 230 | closeConnection = 1; |
| 231 | }else if( c=='k' || c=='K' ){ |
| 232 | closeConnection = 0; |
| 233 | } |
| 234 | }else if( rc==302 && fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 235 | int i, j; |
| 236 | |
| 237 | if ( --maxRedirect == 0){ |
| 238 | fossil_fatal("redirect limit exceeded"); |
| 239 | } |
| 240 | for(i=9; zLine[i] && zLine[i]==' '; i++){} |
| 241 | if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine); |
| 242 | j = strlen(zLine) - 1; |
| 243 | while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){ |
| 244 | j -= 4; |
| @@ -259,11 +245,11 @@ | |
| 245 | zLine[j] = 0; |
| 246 | } |
| 247 | fossil_print("redirect to %s\n", &zLine[i]); |
| 248 | url_parse(&zLine[i]); |
| 249 | transport_close(); |
| 250 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 251 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 252 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 253 | isCompressed = 0; |
| 254 | }else if( fossil_strnicmp(&zLine[14], |
| 255 | "application/x-fossil-uncompressed", -1)==0 ){ |
| 256 |
+8
-1
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -20,10 +20,16 @@ | ||
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "xfer.h" |
| 22 | 22 | |
| 23 | 23 | #include <time.h> |
| 24 | 24 | |
| 25 | +/* | |
| 26 | +** Maximum number of HTTP redirects that any http_exchange() call will | |
| 27 | +** follow before throwing a fatal error. Most browsers use a limit of 20. | |
| 28 | +*/ | |
| 29 | +#define MAX_REDIRECTS 20 | |
| 30 | + | |
| 25 | 31 | /* |
| 26 | 32 | ** This structure holds information about the current state of either |
| 27 | 33 | ** a client or a server that is participating in xfer. |
| 28 | 34 | */ |
| 29 | 35 | typedef struct Xfer Xfer; |
| @@ -1480,11 +1486,12 @@ | ||
| 1480 | 1486 | xfer.nIGotSent = 0; |
| 1481 | 1487 | if( syncFlags & SYNC_VERBOSE ){ |
| 1482 | 1488 | fossil_print("waiting for server..."); |
| 1483 | 1489 | } |
| 1484 | 1490 | fflush(stdout); |
| 1485 | - if( http_exchange(&send, &recv, (syncFlags & SYNC_CLONE)==0 || nCycle>0) ){ | |
| 1491 | + if( http_exchange(&send, &recv, (syncFlags & SYNC_CLONE)==0 || nCycle>0, | |
| 1492 | + MAX_REDIRECTS) ){ | |
| 1486 | 1493 | nErr++; |
| 1487 | 1494 | break; |
| 1488 | 1495 | } |
| 1489 | 1496 | lastPctDone = -1; |
| 1490 | 1497 | blob_reset(&send); |
| 1491 | 1498 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -20,10 +20,16 @@ | |
| 20 | #include "config.h" |
| 21 | #include "xfer.h" |
| 22 | |
| 23 | #include <time.h> |
| 24 | |
| 25 | /* |
| 26 | ** This structure holds information about the current state of either |
| 27 | ** a client or a server that is participating in xfer. |
| 28 | */ |
| 29 | typedef struct Xfer Xfer; |
| @@ -1480,11 +1486,12 @@ | |
| 1480 | xfer.nIGotSent = 0; |
| 1481 | if( syncFlags & SYNC_VERBOSE ){ |
| 1482 | fossil_print("waiting for server..."); |
| 1483 | } |
| 1484 | fflush(stdout); |
| 1485 | if( http_exchange(&send, &recv, (syncFlags & SYNC_CLONE)==0 || nCycle>0) ){ |
| 1486 | nErr++; |
| 1487 | break; |
| 1488 | } |
| 1489 | lastPctDone = -1; |
| 1490 | blob_reset(&send); |
| 1491 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -20,10 +20,16 @@ | |
| 20 | #include "config.h" |
| 21 | #include "xfer.h" |
| 22 | |
| 23 | #include <time.h> |
| 24 | |
| 25 | /* |
| 26 | ** Maximum number of HTTP redirects that any http_exchange() call will |
| 27 | ** follow before throwing a fatal error. Most browsers use a limit of 20. |
| 28 | */ |
| 29 | #define MAX_REDIRECTS 20 |
| 30 | |
| 31 | /* |
| 32 | ** This structure holds information about the current state of either |
| 33 | ** a client or a server that is participating in xfer. |
| 34 | */ |
| 35 | typedef struct Xfer Xfer; |
| @@ -1480,11 +1486,12 @@ | |
| 1486 | xfer.nIGotSent = 0; |
| 1487 | if( syncFlags & SYNC_VERBOSE ){ |
| 1488 | fossil_print("waiting for server..."); |
| 1489 | } |
| 1490 | fflush(stdout); |
| 1491 | if( http_exchange(&send, &recv, (syncFlags & SYNC_CLONE)==0 || nCycle>0, |
| 1492 | MAX_REDIRECTS) ){ |
| 1493 | nErr++; |
| 1494 | break; |
| 1495 | } |
| 1496 | lastPctDone = -1; |
| 1497 | blob_reset(&send); |
| 1498 |