Fossil SCM

Simplify code and no longer rely on MAX_REDIRECTS because 20 password prompts are too many.

andybradford 2014-02-05 06:35 http-auth
Commit 9493a9c763c891146265ab58eb4e39253f281f29
1 file changed +8 -21
+8 -21
--- src/http.c
+++ src/http.c
@@ -28,10 +28,13 @@
2828
#endif
2929
#ifndef fileno
3030
#define fileno(s) _fileno(s)
3131
#endif
3232
#endif
33
+
34
+/* Maximum number of HTTP Authorization attempts */
35
+#define MAX_HTTP_AUTH 2
3336
3437
/* Keep track of HTTP Basic Authorization failures */
3538
static int fSeenHttpAuth = 0;
3639
3740
/*
@@ -276,32 +279,16 @@
276279
while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){
277280
/* printf("[%s]\n", zLine); fflush(stdout); */
278281
if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){
279282
if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err;
280283
if( rc==401 ){
281
- transport_close(GLOBAL_URL());
282
- if( --maxRedirect == 0 ){
283
- fossil_fatal("http authorization limit exceeded");
284
- }
285
- if( g.zHttpAuth==0 ){
284
+ if( fSeenHttpAuth++ < MAX_HTTP_AUTH ){
285
+ if( g.zHttpAuth ){
286
+ if( g.zHttpAuth ) free(g.zHttpAuth);
287
+ }
286288
g.zHttpAuth = prompt_for_httpauth_creds();
287
- }
288
- if( g.zHttpAuth && g.zHttpAuth[0] ){
289
- if( fSeenHttpAuth ){
290
- free(g.zHttpAuth);
291
- g.zHttpAuth = 0;
292
- fSeenHttpAuth = 0;
293
- }else{
294
- fSeenHttpAuth = 1;
295
- }
296
- return http_exchange(pSend, pReply, useLogin, maxRedirect);
297
- }else{
298
- fossil_warning("HTTP Basic Authorization failed.");
299
- if( g.zHttpAuth ){
300
- free(g.zHttpAuth);
301
- g.zHttpAuth = 0;
302
- }
289
+ transport_close(GLOBAL_URL());
303290
return http_exchange(pSend, pReply, useLogin, maxRedirect);
304291
}
305292
}
306293
if( rc!=200 && rc!=302 ){
307294
int ii;
308295
--- src/http.c
+++ src/http.c
@@ -28,10 +28,13 @@
28 #endif
29 #ifndef fileno
30 #define fileno(s) _fileno(s)
31 #endif
32 #endif
 
 
 
33
34 /* Keep track of HTTP Basic Authorization failures */
35 static int fSeenHttpAuth = 0;
36
37 /*
@@ -276,32 +279,16 @@
276 while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){
277 /* printf("[%s]\n", zLine); fflush(stdout); */
278 if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){
279 if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err;
280 if( rc==401 ){
281 transport_close(GLOBAL_URL());
282 if( --maxRedirect == 0 ){
283 fossil_fatal("http authorization limit exceeded");
284 }
285 if( g.zHttpAuth==0 ){
286 g.zHttpAuth = prompt_for_httpauth_creds();
287 }
288 if( g.zHttpAuth && g.zHttpAuth[0] ){
289 if( fSeenHttpAuth ){
290 free(g.zHttpAuth);
291 g.zHttpAuth = 0;
292 fSeenHttpAuth = 0;
293 }else{
294 fSeenHttpAuth = 1;
295 }
296 return http_exchange(pSend, pReply, useLogin, maxRedirect);
297 }else{
298 fossil_warning("HTTP Basic Authorization failed.");
299 if( g.zHttpAuth ){
300 free(g.zHttpAuth);
301 g.zHttpAuth = 0;
302 }
303 return http_exchange(pSend, pReply, useLogin, maxRedirect);
304 }
305 }
306 if( rc!=200 && rc!=302 ){
307 int ii;
308
--- src/http.c
+++ src/http.c
@@ -28,10 +28,13 @@
28 #endif
29 #ifndef fileno
30 #define fileno(s) _fileno(s)
31 #endif
32 #endif
33
34 /* Maximum number of HTTP Authorization attempts */
35 #define MAX_HTTP_AUTH 2
36
37 /* Keep track of HTTP Basic Authorization failures */
38 static int fSeenHttpAuth = 0;
39
40 /*
@@ -276,32 +279,16 @@
279 while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){
280 /* printf("[%s]\n", zLine); fflush(stdout); */
281 if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){
282 if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err;
283 if( rc==401 ){
284 if( fSeenHttpAuth++ < MAX_HTTP_AUTH ){
285 if( g.zHttpAuth ){
286 if( g.zHttpAuth ) free(g.zHttpAuth);
287 }
 
288 g.zHttpAuth = prompt_for_httpauth_creds();
289 transport_close(GLOBAL_URL());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290 return http_exchange(pSend, pReply, useLogin, maxRedirect);
291 }
292 }
293 if( rc!=200 && rc!=302 ){
294 int ii;
295

Keyboard Shortcuts

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