Fossil SCM

Better error messages when trying to run "fossil ui" with an invalid or unaccessible repository.

drh 2008-06-08 15:45 trunk
Commit dcc48662f838417842f182972517e785e2f3d444
3 files changed +2 -3 +15 -11 +9
+2 -3
--- src/cgi.c
+++ src/cgi.c
@@ -153,11 +153,10 @@
153153
*/
154154
static char *zContentType = "text/html"; /* Content type of the reply */
155155
static char *zReplyStatus = "OK"; /* Reply status description */
156156
static int iReplyStatus = 200; /* Reply status code */
157157
static Blob extraHeader = BLOB_INITIALIZER; /* Extra header text */
158
-static int fullHttpReply = 0; /* True for a full-blown HTTP header */
159158
160159
/*
161160
** Set the reply content type
162161
*/
163162
void cgi_set_content_type(const char *zType){
@@ -285,11 +284,11 @@
285284
iReplyStatus = 304;
286285
zReplyStatus = "Not Modified";
287286
}
288287
#endif
289288
290
- if( fullHttpReply ){
289
+ if( g.fullHttpReply ){
291290
fprintf(g.httpOut, "HTTP/1.0 %d %s\r\n", iReplyStatus, zReplyStatus);
292291
fprintf(g.httpOut, "Date: %s\r\n", cgi_rfc822_datestamp(time(0)));
293292
fprintf(g.httpOut, "Connection: close\r\n");
294293
}else{
295294
fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
@@ -1091,11 +1090,11 @@
10911090
int i;
10921091
struct sockaddr_in remoteName;
10931092
size_t size = sizeof(struct sockaddr_in);
10941093
char zLine[2000]; /* A single line of input. */
10951094
1096
- fullHttpReply = 1;
1095
+ g.fullHttpReply = 1;
10971096
if( fgets(zLine, sizeof(zLine),g.httpIn)==0 ){
10981097
malformed_request();
10991098
}
11001099
zToken = extract_token(zLine, &z);
11011100
if( zToken==0 ){
11021101
--- src/cgi.c
+++ src/cgi.c
@@ -153,11 +153,10 @@
153 */
154 static char *zContentType = "text/html"; /* Content type of the reply */
155 static char *zReplyStatus = "OK"; /* Reply status description */
156 static int iReplyStatus = 200; /* Reply status code */
157 static Blob extraHeader = BLOB_INITIALIZER; /* Extra header text */
158 static int fullHttpReply = 0; /* True for a full-blown HTTP header */
159
160 /*
161 ** Set the reply content type
162 */
163 void cgi_set_content_type(const char *zType){
@@ -285,11 +284,11 @@
285 iReplyStatus = 304;
286 zReplyStatus = "Not Modified";
287 }
288 #endif
289
290 if( fullHttpReply ){
291 fprintf(g.httpOut, "HTTP/1.0 %d %s\r\n", iReplyStatus, zReplyStatus);
292 fprintf(g.httpOut, "Date: %s\r\n", cgi_rfc822_datestamp(time(0)));
293 fprintf(g.httpOut, "Connection: close\r\n");
294 }else{
295 fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
@@ -1091,11 +1090,11 @@
1091 int i;
1092 struct sockaddr_in remoteName;
1093 size_t size = sizeof(struct sockaddr_in);
1094 char zLine[2000]; /* A single line of input. */
1095
1096 fullHttpReply = 1;
1097 if( fgets(zLine, sizeof(zLine),g.httpIn)==0 ){
1098 malformed_request();
1099 }
1100 zToken = extract_token(zLine, &z);
1101 if( zToken==0 ){
1102
--- src/cgi.c
+++ src/cgi.c
@@ -153,11 +153,10 @@
153 */
154 static char *zContentType = "text/html"; /* Content type of the reply */
155 static char *zReplyStatus = "OK"; /* Reply status description */
156 static int iReplyStatus = 200; /* Reply status code */
157 static Blob extraHeader = BLOB_INITIALIZER; /* Extra header text */
 
158
159 /*
160 ** Set the reply content type
161 */
162 void cgi_set_content_type(const char *zType){
@@ -285,11 +284,11 @@
284 iReplyStatus = 304;
285 zReplyStatus = "Not Modified";
286 }
287 #endif
288
289 if( g.fullHttpReply ){
290 fprintf(g.httpOut, "HTTP/1.0 %d %s\r\n", iReplyStatus, zReplyStatus);
291 fprintf(g.httpOut, "Date: %s\r\n", cgi_rfc822_datestamp(time(0)));
292 fprintf(g.httpOut, "Connection: close\r\n");
293 }else{
294 fprintf(g.httpOut, "Status: %d %s\r\n", iReplyStatus, zReplyStatus);
@@ -1091,11 +1090,11 @@
1090 int i;
1091 struct sockaddr_in remoteName;
1092 size_t size = sizeof(struct sockaddr_in);
1093 char zLine[2000]; /* A single line of input. */
1094
1095 g.fullHttpReply = 1;
1096 if( fgets(zLine, sizeof(zLine),g.httpIn)==0 ){
1097 malformed_request();
1098 }
1099 zToken = extract_token(zLine, &z);
1100 if( zToken==0 ){
1101
+15 -11
--- src/main.c
+++ src/main.c
@@ -71,10 +71,11 @@
7171
const char *zContentType; /* The content type of the input HTTP request */
7272
int iErrPriority; /* Priority of current error message */
7373
char *zErrMsg; /* Text of an error message */
7474
Blob cgiIn; /* Input to an xfer www method */
7575
int cgiPanic; /* Write error messages to CGI */
76
+ int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
7677
Th_Interp *interp; /* The TH1 interpreter */
7778
FILE *httpIn; /* Accept HTTP input from here */
7879
FILE *httpOut; /* Send HTTP output here */
7980
int xlinkClusterOnly; /* Set when cloning. Only process clusters */
8081
@@ -244,11 +245,10 @@
244245
z = vmprintf(zFormat, ap);
245246
va_end(ap);
246247
if( g.cgiPanic && once ){
247248
once = 0;
248249
cgi_printf("<p><font color=\"red\">%h</font></p>", z);
249
- style_footer();
250250
cgi_reply();
251251
}else{
252252
fprintf(stderr, "%s: %s\n", g.argv[0], z);
253253
}
254254
db_force_rollback();
@@ -261,11 +261,10 @@
261261
z = vmprintf(zFormat, ap);
262262
va_end(ap);
263263
if( g.cgiPanic ){
264264
g.cgiPanic = 0;
265265
cgi_printf("<p><font color=\"red\">%h</font></p>", z);
266
- style_footer();
267266
cgi_reply();
268267
}else{
269268
fprintf(stderr, "%s: %s\n", g.argv[0], z);
270269
}
271270
db_force_rollback();
@@ -635,24 +634,27 @@
635634
** is delivered on stdout. This method is used to launch an HTTP request
636635
** handler from inetd, for example. The argument is the name of the
637636
** repository.
638637
*/
639638
void cmd_http(void){
640
- const char *zIpAddr = 0;
639
+ const char *zIpAddr;
641640
if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
642641
cgi_panic("no repository specified");
643642
}
644643
g.cgiPanic = 1;
645
- g.httpIn = stdin;
646
- g.httpOut = stdout;
644
+ g.fullHttpReply = 1;
645
+ if( g.argc==6 ){
646
+ g.httpIn = fopen(g.argv[3], "rb");
647
+ g.httpOut = fopen(g.argv[4], "wb");
648
+ zIpAddr = g.argv[5];
649
+ }else{
650
+ g.httpIn = stdin;
651
+ g.httpOut = stdout;
652
+ zIpAddr = 0;
653
+ }
647654
if( g.argc>=3 ){
648655
db_open_repository(g.argv[2]);
649
- if( g.argc==6 ){
650
- g.httpIn = fopen(g.argv[3], "rb");
651
- g.httpOut = fopen(g.argv[4], "wb");
652
- zIpAddr = g.argv[5];
653
- }
654656
}else{
655657
db_must_be_within_tree();
656658
}
657659
cgi_handle_http_request(zIpAddr);
658660
process_one_web_page();
@@ -696,12 +698,14 @@
696698
iPort = 8080;
697699
}
698700
if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
699701
if( g.argc==2 ){
700702
db_must_be_within_tree();
701
- db_close();
703
+ }else{
704
+ db_open_repository(g.argv[2]);
702705
}
706
+ db_close();
703707
#ifndef __MINGW32__
704708
/* Unix implementation */
705709
if( g.argv[1][0]=='u' ){
706710
#if !defined(__DARWIN__) && !defined(__APPLE__)
707711
zBrowser = db_get("web-browser", "firefox");
708712
--- src/main.c
+++ src/main.c
@@ -71,10 +71,11 @@
71 const char *zContentType; /* The content type of the input HTTP request */
72 int iErrPriority; /* Priority of current error message */
73 char *zErrMsg; /* Text of an error message */
74 Blob cgiIn; /* Input to an xfer www method */
75 int cgiPanic; /* Write error messages to CGI */
 
76 Th_Interp *interp; /* The TH1 interpreter */
77 FILE *httpIn; /* Accept HTTP input from here */
78 FILE *httpOut; /* Send HTTP output here */
79 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
80
@@ -244,11 +245,10 @@
244 z = vmprintf(zFormat, ap);
245 va_end(ap);
246 if( g.cgiPanic && once ){
247 once = 0;
248 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
249 style_footer();
250 cgi_reply();
251 }else{
252 fprintf(stderr, "%s: %s\n", g.argv[0], z);
253 }
254 db_force_rollback();
@@ -261,11 +261,10 @@
261 z = vmprintf(zFormat, ap);
262 va_end(ap);
263 if( g.cgiPanic ){
264 g.cgiPanic = 0;
265 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
266 style_footer();
267 cgi_reply();
268 }else{
269 fprintf(stderr, "%s: %s\n", g.argv[0], z);
270 }
271 db_force_rollback();
@@ -635,24 +634,27 @@
635 ** is delivered on stdout. This method is used to launch an HTTP request
636 ** handler from inetd, for example. The argument is the name of the
637 ** repository.
638 */
639 void cmd_http(void){
640 const char *zIpAddr = 0;
641 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
642 cgi_panic("no repository specified");
643 }
644 g.cgiPanic = 1;
645 g.httpIn = stdin;
646 g.httpOut = stdout;
 
 
 
 
 
 
 
 
647 if( g.argc>=3 ){
648 db_open_repository(g.argv[2]);
649 if( g.argc==6 ){
650 g.httpIn = fopen(g.argv[3], "rb");
651 g.httpOut = fopen(g.argv[4], "wb");
652 zIpAddr = g.argv[5];
653 }
654 }else{
655 db_must_be_within_tree();
656 }
657 cgi_handle_http_request(zIpAddr);
658 process_one_web_page();
@@ -696,12 +698,14 @@
696 iPort = 8080;
697 }
698 if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
699 if( g.argc==2 ){
700 db_must_be_within_tree();
701 db_close();
 
702 }
 
703 #ifndef __MINGW32__
704 /* Unix implementation */
705 if( g.argv[1][0]=='u' ){
706 #if !defined(__DARWIN__) && !defined(__APPLE__)
707 zBrowser = db_get("web-browser", "firefox");
708
--- src/main.c
+++ src/main.c
@@ -71,10 +71,11 @@
71 const char *zContentType; /* The content type of the input HTTP request */
72 int iErrPriority; /* Priority of current error message */
73 char *zErrMsg; /* Text of an error message */
74 Blob cgiIn; /* Input to an xfer www method */
75 int cgiPanic; /* Write error messages to CGI */
76 int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
77 Th_Interp *interp; /* The TH1 interpreter */
78 FILE *httpIn; /* Accept HTTP input from here */
79 FILE *httpOut; /* Send HTTP output here */
80 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
81
@@ -244,11 +245,10 @@
245 z = vmprintf(zFormat, ap);
246 va_end(ap);
247 if( g.cgiPanic && once ){
248 once = 0;
249 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
 
250 cgi_reply();
251 }else{
252 fprintf(stderr, "%s: %s\n", g.argv[0], z);
253 }
254 db_force_rollback();
@@ -261,11 +261,10 @@
261 z = vmprintf(zFormat, ap);
262 va_end(ap);
263 if( g.cgiPanic ){
264 g.cgiPanic = 0;
265 cgi_printf("<p><font color=\"red\">%h</font></p>", z);
 
266 cgi_reply();
267 }else{
268 fprintf(stderr, "%s: %s\n", g.argv[0], z);
269 }
270 db_force_rollback();
@@ -635,24 +634,27 @@
634 ** is delivered on stdout. This method is used to launch an HTTP request
635 ** handler from inetd, for example. The argument is the name of the
636 ** repository.
637 */
638 void cmd_http(void){
639 const char *zIpAddr;
640 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
641 cgi_panic("no repository specified");
642 }
643 g.cgiPanic = 1;
644 g.fullHttpReply = 1;
645 if( g.argc==6 ){
646 g.httpIn = fopen(g.argv[3], "rb");
647 g.httpOut = fopen(g.argv[4], "wb");
648 zIpAddr = g.argv[5];
649 }else{
650 g.httpIn = stdin;
651 g.httpOut = stdout;
652 zIpAddr = 0;
653 }
654 if( g.argc>=3 ){
655 db_open_repository(g.argv[2]);
 
 
 
 
 
656 }else{
657 db_must_be_within_tree();
658 }
659 cgi_handle_http_request(zIpAddr);
660 process_one_web_page();
@@ -696,12 +698,14 @@
698 iPort = 8080;
699 }
700 if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
701 if( g.argc==2 ){
702 db_must_be_within_tree();
703 }else{
704 db_open_repository(g.argv[2]);
705 }
706 db_close();
707 #ifndef __MINGW32__
708 /* Unix implementation */
709 if( g.argv[1][0]=='u' ){
710 #if !defined(__DARWIN__) && !defined(__APPLE__)
711 zBrowser = db_get("web-browser", "firefox");
712
--- src/style.c
+++ src/style.c
@@ -40,10 +40,16 @@
4040
const char *zTitle;
4141
const char *zLink;
4242
} aSubmenu[30];
4343
static int nSubmenu = 0;
4444
45
+/*
46
+** Remember that the header has been generated. The footer is omitted
47
+** if an error occurs before the header.
48
+*/
49
+static int headerHasBeenGenerated = 0;
50
+
4551
/*
4652
** Add a new element to the submenu
4753
*/
4854
void style_submenu_element(
4955
const char *zLabel,
@@ -98,17 +104,20 @@
98104
}
99105
Th_Render(zHeader);
100106
Th_Unstore("title"); /* Avoid collisions with ticket field names */
101107
cgi_destination(CGI_BODY);
102108
g.cgiPanic = 1;
109
+ headerHasBeenGenerated = 1;
103110
}
104111
105112
/*
106113
** Draw the footer at the bottom of the page.
107114
*/
108115
void style_footer(void){
109116
const char *zFooter;
117
+
118
+ if( !headerHasBeenGenerated ) return;
110119
111120
/* Go back and put the submenu at the top of the page. We delay the
112121
** creation of the submenu until the end so that we can add elements
113122
** to the submenu while generating page text.
114123
*/
115124
--- src/style.c
+++ src/style.c
@@ -40,10 +40,16 @@
40 const char *zTitle;
41 const char *zLink;
42 } aSubmenu[30];
43 static int nSubmenu = 0;
44
 
 
 
 
 
 
45 /*
46 ** Add a new element to the submenu
47 */
48 void style_submenu_element(
49 const char *zLabel,
@@ -98,17 +104,20 @@
98 }
99 Th_Render(zHeader);
100 Th_Unstore("title"); /* Avoid collisions with ticket field names */
101 cgi_destination(CGI_BODY);
102 g.cgiPanic = 1;
 
103 }
104
105 /*
106 ** Draw the footer at the bottom of the page.
107 */
108 void style_footer(void){
109 const char *zFooter;
 
 
110
111 /* Go back and put the submenu at the top of the page. We delay the
112 ** creation of the submenu until the end so that we can add elements
113 ** to the submenu while generating page text.
114 */
115
--- src/style.c
+++ src/style.c
@@ -40,10 +40,16 @@
40 const char *zTitle;
41 const char *zLink;
42 } aSubmenu[30];
43 static int nSubmenu = 0;
44
45 /*
46 ** Remember that the header has been generated. The footer is omitted
47 ** if an error occurs before the header.
48 */
49 static int headerHasBeenGenerated = 0;
50
51 /*
52 ** Add a new element to the submenu
53 */
54 void style_submenu_element(
55 const char *zLabel,
@@ -98,17 +104,20 @@
104 }
105 Th_Render(zHeader);
106 Th_Unstore("title"); /* Avoid collisions with ticket field names */
107 cgi_destination(CGI_BODY);
108 g.cgiPanic = 1;
109 headerHasBeenGenerated = 1;
110 }
111
112 /*
113 ** Draw the footer at the bottom of the page.
114 */
115 void style_footer(void){
116 const char *zFooter;
117
118 if( !headerHasBeenGenerated ) return;
119
120 /* Go back and put the submenu at the top of the page. We delay the
121 ** creation of the submenu until the end so that we can add elements
122 ** to the submenu while generating page text.
123 */
124

Keyboard Shortcuts

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