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.

jan.nijtmans 2013-02-01 12:33 trunk
Commit fe56e5aa4f000b9498966c0aabf050e7973ffb19
2 files changed +5 -19 +8 -1
+5 -19
--- src/http.c
+++ src/http.c
@@ -120,16 +120,10 @@
120120
blob_appendf(pHdr, "Content-Type: application/x-fossil\r\n");
121121
}
122122
blob_appendf(pHdr, "Content-Length: %d\r\n\r\n", blob_size(pPayload));
123123
}
124124
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
-
131125
/*
132126
** Sign the content in pSend, compress it, and send it to the server
133127
** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
134128
** in pRecv. pRecv is assumed to be uninitialized when
135129
** this routine is called - this routine will initialize it.
@@ -136,20 +130,11 @@
136130
**
137131
** The server address is contain in the "g" global structure. The
138132
** url_parse() routine should have been called prior to this routine
139133
** in order to fill this structure appropriately.
140134
*/
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){
151136
Blob login; /* The login card */
152137
Blob payload; /* The complete payload including login card */
153138
Blob hdr; /* The HTTP request header */
154139
int closeConnection; /* True to close the connection when done */
155140
int iLength; /* Length of the reply payload */
@@ -245,14 +230,15 @@
245230
closeConnection = 1;
246231
}else if( c=='k' || c=='K' ){
247232
closeConnection = 0;
248233
}
249234
}else if( rc==302 && fossil_strnicmp(zLine, "location:", 9)==0 ){
250
- if ( numRedirects>=MAX_REDIRECTS ){
235
+ int i, j;
236
+
237
+ if ( --maxRedirect == 0){
251238
fossil_fatal("redirect limit exceeded");
252239
}
253
- int i, j;
254240
for(i=9; zLine[i] && zLine[i]==' '; i++){}
255241
if( zLine[i]==0 ) fossil_fatal("malformed redirect: %s", zLine);
256242
j = strlen(zLine) - 1;
257243
while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
258244
j -= 4;
@@ -259,11 +245,11 @@
259245
zLine[j] = 0;
260246
}
261247
fossil_print("redirect to %s\n", &zLine[i]);
262248
url_parse(&zLine[i]);
263249
transport_close();
264
- return _http_exchange(pSend, pReply, useLogin, numRedirects + 1);
250
+ return http_exchange(pSend, pReply, useLogin, maxRedirect);
265251
}else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
266252
if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){
267253
isCompressed = 0;
268254
}else if( fossil_strnicmp(&zLine[14],
269255
"application/x-fossil-uncompressed", -1)==0 ){
270256
--- 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 @@
2020
#include "config.h"
2121
#include "xfer.h"
2222
2323
#include <time.h>
2424
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
+
2531
/*
2632
** This structure holds information about the current state of either
2733
** a client or a server that is participating in xfer.
2834
*/
2935
typedef struct Xfer Xfer;
@@ -1480,11 +1486,12 @@
14801486
xfer.nIGotSent = 0;
14811487
if( syncFlags & SYNC_VERBOSE ){
14821488
fossil_print("waiting for server...");
14831489
}
14841490
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) ){
14861493
nErr++;
14871494
break;
14881495
}
14891496
lastPctDone = -1;
14901497
blob_reset(&send);
14911498
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button