Fossil SCM

More cleaning up of error lower-level handling to output JSON instead of HTML in a few more cases.

stephan 2011-09-17 16:01 UTC json
Commit 9b842564f746286f4255d79a1ee1d9b6c4b153fd
+20 -10
--- src/cgi.c
+++ src/cgi.c
@@ -948,20 +948,30 @@
948948
** Panic and die while processing a webpage.
949949
*/
950950
void cgi_panic(const char *zFormat, ...){
951951
va_list ap;
952952
cgi_reset_content();
953
- cgi_set_status(500, "Internal Server Error");
954
- cgi_printf(
955
- "<html><body><h1>Internal Server Error</h1>\n"
956
- "<plaintext>"
957
- );
958
- va_start(ap, zFormat);
959
- vxprintf(pContent,zFormat,ap);
960
- va_end(ap);
961
- cgi_reply();
962
- fossil_exit(1);
953
+ if( g.json.isJsonMode ){
954
+ char * zMsg;
955
+ va_start(ap, zFormat);
956
+ zMsg = vmprintf(zFormat,ap);
957
+ va_end(ap);
958
+ json_err( FSL_JSON_E_PANIC, zMsg, 1 );
959
+ free(zMsg);
960
+ fossil_exit( g.isCGI ? 0 : 1 );
961
+ }else{
962
+ cgi_set_status(500, "Internal Server Error");
963
+ cgi_printf(
964
+ "<html><body><h1>Internal Server Error</h1>\n"
965
+ "<plaintext>"
966
+ );
967
+ va_start(ap, zFormat);
968
+ vxprintf(pContent,zFormat,ap);
969
+ va_end(ap);
970
+ cgi_reply();
971
+ fossil_exit(1);
972
+ }
963973
}
964974
965975
/*
966976
** Remove the first space-delimited token from a string and return
967977
** a pointer to it. Add a NULL to the string to terminate the token.
968978
--- src/cgi.c
+++ src/cgi.c
@@ -948,20 +948,30 @@
948 ** Panic and die while processing a webpage.
949 */
950 void cgi_panic(const char *zFormat, ...){
951 va_list ap;
952 cgi_reset_content();
953 cgi_set_status(500, "Internal Server Error");
954 cgi_printf(
955 "<html><body><h1>Internal Server Error</h1>\n"
956 "<plaintext>"
957 );
958 va_start(ap, zFormat);
959 vxprintf(pContent,zFormat,ap);
960 va_end(ap);
961 cgi_reply();
962 fossil_exit(1);
 
 
 
 
 
 
 
 
 
 
963 }
964
965 /*
966 ** Remove the first space-delimited token from a string and return
967 ** a pointer to it. Add a NULL to the string to terminate the token.
968
--- src/cgi.c
+++ src/cgi.c
@@ -948,20 +948,30 @@
948 ** Panic and die while processing a webpage.
949 */
950 void cgi_panic(const char *zFormat, ...){
951 va_list ap;
952 cgi_reset_content();
953 if( g.json.isJsonMode ){
954 char * zMsg;
955 va_start(ap, zFormat);
956 zMsg = vmprintf(zFormat,ap);
957 va_end(ap);
958 json_err( FSL_JSON_E_PANIC, zMsg, 1 );
959 free(zMsg);
960 fossil_exit( g.isCGI ? 0 : 1 );
961 }else{
962 cgi_set_status(500, "Internal Server Error");
963 cgi_printf(
964 "<html><body><h1>Internal Server Error</h1>\n"
965 "<plaintext>"
966 );
967 va_start(ap, zFormat);
968 vxprintf(pContent,zFormat,ap);
969 va_end(ap);
970 cgi_reply();
971 fossil_exit(1);
972 }
973 }
974
975 /*
976 ** Remove the first space-delimited token from a string and return
977 ** a pointer to it. Add a NULL to the string to terminate the token.
978
+7 -52
--- src/json.c
+++ src/json.c
@@ -28,56 +28,11 @@
2828
#include <assert.h>
2929
#include <time.h>
3030
3131
#if INTERFACE
3232
#include "cson_amalgamation.h"
33
-/*
34
-** The "official" list of Fossil/JSON error codes.
35
-** Their values might very well change during initial
36
-** development but after their first public release
37
-** they must stay stable.
38
-** Values must be in the range 1..9999
39
-**
40
-** Numbers evenly dividable by 100 are "categories",
41
-** and error codes for a given category have their
42
-** high bits set to the category value.
43
-**
44
-*/
45
-enum FossilJsonCodes {
46
-
47
-FSL_JSON_E_GENERIC = 1000,
48
-FSL_JSON_E_GENERIC_SUB1 = FSL_JSON_E_GENERIC + 100,
49
-FSL_JSON_E_INVALID_REQUEST = FSL_JSON_E_GENERIC_SUB1 + 1,
50
-FSL_JSON_E_UNKNOWN_COMMAND = FSL_JSON_E_GENERIC_SUB1 + 2,
51
-FSL_JSON_E_UNKNOWN = FSL_JSON_E_GENERIC_SUB1 + 3,
52
-FSL_JSON_E_RESOURCE_NOT_FOUND = FSL_JSON_E_GENERIC_SUB1 + 4,
53
-FSL_JSON_E_TIMEOUT = FSL_JSON_E_GENERIC_SUB1 + 5,
54
-FSL_JSON_E_ASSERT = FSL_JSON_E_GENERIC_SUB1 + 6,
55
-FSL_JSON_E_ALLOC = FSL_JSON_E_GENERIC_SUB1 + 7,
56
-FSL_JSON_E_NYI = FSL_JSON_E_GENERIC_SUB1 + 8,
57
-
58
-FSL_JSON_E_AUTH = 2000,
59
-/* #2001: re-use */
60
-FSL_JSON_E_MISSING_AUTH = FSL_JSON_E_AUTH + 2,
61
-FSL_JSON_E_DENIED = FSL_JSON_E_AUTH + 3,
62
-FSL_JSON_E_WRONG_MODE = FSL_JSON_E_AUTH + 4,
63
-
64
-FSL_JSON_E_LOGIN_FAILED = FSL_JSON_E_AUTH + 100,
65
-FSL_JSON_E_LOGIN_FAILED_NONAME = FSL_JSON_E_LOGIN_FAILED + 1,
66
-FSL_JSON_E_LOGIN_FAILED_NOPW = FSL_JSON_E_LOGIN_FAILED + 2,
67
-FSL_JSON_E_LOGIN_FAILED_NOTFOUND = FSL_JSON_E_LOGIN_FAILED + 3,
68
-
69
-FSL_JSON_E_USAGE = 3000,
70
-FSL_JSON_E_INVALID_ARGS = FSL_JSON_E_USAGE + 1,
71
-FSL_JSON_E_MISSING_ARGS = FSL_JSON_E_USAGE + 2,
72
-
73
-FSL_JSON_E_DB = 4000,
74
-FSL_JSON_E_STMT_PREP = FSL_JSON_E_DB + 1,
75
-FSL_JSON_E_STMT_BIND = FSL_JSON_E_DB + 2,
76
-FSL_JSON_E_STMT_EXEC = FSL_JSON_E_DB + 3,
77
-FSL_JSON_E_DB_LOCKED = FSL_JSON_E_DB + 4
78
-};
33
+#include "json_detail.h" /* workaround for apparent enum limitation in makeheaders */
7934
#endif
8035
8136
/*
8237
** Holds keys used for various JSON API properties.
8338
*/
@@ -638,12 +593,12 @@
638593
**
639594
** If g.isCGI then the generated error object replaces any currently
640595
** buffered page output.
641596
**
642597
** If alsoOutput is true AND g.isCGI then the cgi_reply() is called to
643
-** flush the output (and headers). Generally only do this if you are about
644
-** to call exit().
598
+** flush the output (and headers). Generally only do this if you are
599
+** about to call exit().
645600
**
646601
** !g.isCGI then alsoOutput is ignored and all output is sent to
647602
** stdout immediately.
648603
**
649604
** This clears any previously buffered CGI content, replacing it with
@@ -690,10 +645,12 @@
690645
FSET(MANIFEST_YEAR,"manifestYear");
691646
FSET(RELEASE_VERSION,"releaseVersion");
692647
#undef FSET
693648
cson_object_set( jobj, "releaseVersionNumber",
694649
cson_value_new_integer(RELEASE_VERSION_NUMBER) );
650
+ cson_object_set( jobj, "resultCodeParanoiaLevel",
651
+ cson_value_new_integer(g.json.errorDetailParanoia) );
695652
return jval;
696653
}
697654
698655
#if 0
699656
/* we have a disconnect here between fossil's server-mode QUERY_STRING
@@ -1080,22 +1037,20 @@
10801037
** ...
10811038
**
10821039
*/
10831040
void json_cmd_top(void){
10841041
char const * cmd = NULL;
1085
- unsigned int n;
10861042
int rc = 1002;
10871043
cson_value * payload = NULL;
10881044
JsonPageDef const * pageDef;
10891045
json_mode_bootstrap();
10901046
if( g.argc<3 ){
10911047
goto usage;
10921048
}
10931049
db_find_and_open_repository(0, 0);
10941050
cmd = json_command_arg(1);
1095
- n = cmd ? strlen(cmd) : 0;
1096
- if( n==0 ){
1051
+ if( !cmd || !*cmd ){
10971052
goto usage;
10981053
}
10991054
cgi_set_content_type( cson_cgi_guess_content_type(&g.json.cgiCx) );
11001055
pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
11011056
if( ! pageDef ){
@@ -1116,12 +1071,12 @@
11161071
if((0 != rc) && !g.isCGI){
11171072
/* FIXME: we need a way of passing this error back
11181073
up to the routine which called this callback.
11191074
e.g. add g.errCode.
11201075
*/
1121
- exit(1);
1076
+ fossil_exit(1);
11221077
}
11231078
}
11241079
return;
11251080
usage:
11261081
usage("subcommand");
11271082
}
11281083
11291084
ADDED src/json_detail.h
--- src/json.c
+++ src/json.c
@@ -28,56 +28,11 @@
28 #include <assert.h>
29 #include <time.h>
30
31 #if INTERFACE
32 #include "cson_amalgamation.h"
33 /*
34 ** The "official" list of Fossil/JSON error codes.
35 ** Their values might very well change during initial
36 ** development but after their first public release
37 ** they must stay stable.
38 ** Values must be in the range 1..9999
39 **
40 ** Numbers evenly dividable by 100 are "categories",
41 ** and error codes for a given category have their
42 ** high bits set to the category value.
43 **
44 */
45 enum FossilJsonCodes {
46
47 FSL_JSON_E_GENERIC = 1000,
48 FSL_JSON_E_GENERIC_SUB1 = FSL_JSON_E_GENERIC + 100,
49 FSL_JSON_E_INVALID_REQUEST = FSL_JSON_E_GENERIC_SUB1 + 1,
50 FSL_JSON_E_UNKNOWN_COMMAND = FSL_JSON_E_GENERIC_SUB1 + 2,
51 FSL_JSON_E_UNKNOWN = FSL_JSON_E_GENERIC_SUB1 + 3,
52 FSL_JSON_E_RESOURCE_NOT_FOUND = FSL_JSON_E_GENERIC_SUB1 + 4,
53 FSL_JSON_E_TIMEOUT = FSL_JSON_E_GENERIC_SUB1 + 5,
54 FSL_JSON_E_ASSERT = FSL_JSON_E_GENERIC_SUB1 + 6,
55 FSL_JSON_E_ALLOC = FSL_JSON_E_GENERIC_SUB1 + 7,
56 FSL_JSON_E_NYI = FSL_JSON_E_GENERIC_SUB1 + 8,
57
58 FSL_JSON_E_AUTH = 2000,
59 /* #2001: re-use */
60 FSL_JSON_E_MISSING_AUTH = FSL_JSON_E_AUTH + 2,
61 FSL_JSON_E_DENIED = FSL_JSON_E_AUTH + 3,
62 FSL_JSON_E_WRONG_MODE = FSL_JSON_E_AUTH + 4,
63
64 FSL_JSON_E_LOGIN_FAILED = FSL_JSON_E_AUTH + 100,
65 FSL_JSON_E_LOGIN_FAILED_NONAME = FSL_JSON_E_LOGIN_FAILED + 1,
66 FSL_JSON_E_LOGIN_FAILED_NOPW = FSL_JSON_E_LOGIN_FAILED + 2,
67 FSL_JSON_E_LOGIN_FAILED_NOTFOUND = FSL_JSON_E_LOGIN_FAILED + 3,
68
69 FSL_JSON_E_USAGE = 3000,
70 FSL_JSON_E_INVALID_ARGS = FSL_JSON_E_USAGE + 1,
71 FSL_JSON_E_MISSING_ARGS = FSL_JSON_E_USAGE + 2,
72
73 FSL_JSON_E_DB = 4000,
74 FSL_JSON_E_STMT_PREP = FSL_JSON_E_DB + 1,
75 FSL_JSON_E_STMT_BIND = FSL_JSON_E_DB + 2,
76 FSL_JSON_E_STMT_EXEC = FSL_JSON_E_DB + 3,
77 FSL_JSON_E_DB_LOCKED = FSL_JSON_E_DB + 4
78 };
79 #endif
80
81 /*
82 ** Holds keys used for various JSON API properties.
83 */
@@ -638,12 +593,12 @@
638 **
639 ** If g.isCGI then the generated error object replaces any currently
640 ** buffered page output.
641 **
642 ** If alsoOutput is true AND g.isCGI then the cgi_reply() is called to
643 ** flush the output (and headers). Generally only do this if you are about
644 ** to call exit().
645 **
646 ** !g.isCGI then alsoOutput is ignored and all output is sent to
647 ** stdout immediately.
648 **
649 ** This clears any previously buffered CGI content, replacing it with
@@ -690,10 +645,12 @@
690 FSET(MANIFEST_YEAR,"manifestYear");
691 FSET(RELEASE_VERSION,"releaseVersion");
692 #undef FSET
693 cson_object_set( jobj, "releaseVersionNumber",
694 cson_value_new_integer(RELEASE_VERSION_NUMBER) );
 
 
695 return jval;
696 }
697
698 #if 0
699 /* we have a disconnect here between fossil's server-mode QUERY_STRING
@@ -1080,22 +1037,20 @@
1080 ** ...
1081 **
1082 */
1083 void json_cmd_top(void){
1084 char const * cmd = NULL;
1085 unsigned int n;
1086 int rc = 1002;
1087 cson_value * payload = NULL;
1088 JsonPageDef const * pageDef;
1089 json_mode_bootstrap();
1090 if( g.argc<3 ){
1091 goto usage;
1092 }
1093 db_find_and_open_repository(0, 0);
1094 cmd = json_command_arg(1);
1095 n = cmd ? strlen(cmd) : 0;
1096 if( n==0 ){
1097 goto usage;
1098 }
1099 cgi_set_content_type( cson_cgi_guess_content_type(&g.json.cgiCx) );
1100 pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
1101 if( ! pageDef ){
@@ -1116,12 +1071,12 @@
1116 if((0 != rc) && !g.isCGI){
1117 /* FIXME: we need a way of passing this error back
1118 up to the routine which called this callback.
1119 e.g. add g.errCode.
1120 */
1121 exit(1);
1122 }
1123 }
1124 return;
1125 usage:
1126 usage("subcommand");
1127 }
1128
1129 DDED src/json_detail.h
--- src/json.c
+++ src/json.c
@@ -28,56 +28,11 @@
28 #include <assert.h>
29 #include <time.h>
30
31 #if INTERFACE
32 #include "cson_amalgamation.h"
33 #include "json_detail.h" /* workaround for apparent enum limitation in makeheaders */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34 #endif
35
36 /*
37 ** Holds keys used for various JSON API properties.
38 */
@@ -638,12 +593,12 @@
593 **
594 ** If g.isCGI then the generated error object replaces any currently
595 ** buffered page output.
596 **
597 ** If alsoOutput is true AND g.isCGI then the cgi_reply() is called to
598 ** flush the output (and headers). Generally only do this if you are
599 ** about to call exit().
600 **
601 ** !g.isCGI then alsoOutput is ignored and all output is sent to
602 ** stdout immediately.
603 **
604 ** This clears any previously buffered CGI content, replacing it with
@@ -690,10 +645,12 @@
645 FSET(MANIFEST_YEAR,"manifestYear");
646 FSET(RELEASE_VERSION,"releaseVersion");
647 #undef FSET
648 cson_object_set( jobj, "releaseVersionNumber",
649 cson_value_new_integer(RELEASE_VERSION_NUMBER) );
650 cson_object_set( jobj, "resultCodeParanoiaLevel",
651 cson_value_new_integer(g.json.errorDetailParanoia) );
652 return jval;
653 }
654
655 #if 0
656 /* we have a disconnect here between fossil's server-mode QUERY_STRING
@@ -1080,22 +1037,20 @@
1037 ** ...
1038 **
1039 */
1040 void json_cmd_top(void){
1041 char const * cmd = NULL;
 
1042 int rc = 1002;
1043 cson_value * payload = NULL;
1044 JsonPageDef const * pageDef;
1045 json_mode_bootstrap();
1046 if( g.argc<3 ){
1047 goto usage;
1048 }
1049 db_find_and_open_repository(0, 0);
1050 cmd = json_command_arg(1);
1051 if( !cmd || !*cmd ){
 
1052 goto usage;
1053 }
1054 cgi_set_content_type( cson_cgi_guess_content_type(&g.json.cgiCx) );
1055 pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
1056 if( ! pageDef ){
@@ -1116,12 +1071,12 @@
1071 if((0 != rc) && !g.isCGI){
1072 /* FIXME: we need a way of passing this error back
1073 up to the routine which called this callback.
1074 e.g. add g.errCode.
1075 */
1076 fossil_exit(1);
1077 }
1078 }
1079 return;
1080 usage:
1081 usage("subcommand");
1082 }
1083
1084 DDED src/json_detail.h
--- a/src/json_detail.h
+++ b/src/json_detail.h
@@ -0,0 +1,35 @@
1
+*authToken*/,
2
+ "COMMAND_PATH" /*commandPath*/,
3
+ "payload" /* payload */,
4
+ "requestId" /*requestId*/,
5
+ "resultCode" /*resultCode*/,
6
+ "resultT
7
+** Their values mightultText" /*resultText*/,
8
+ 2
9
+** public release
10
+**..9999
11
+** and error codes
12
+***/,
13
+ "COMMAND_PATH" /*commandPath*/,
14
+ "payload" /* payload */,
15
+ "requestId" /*requestId*/,
16
+ "resultCode" /*resultCode*/,
17
+ "resultText" /*resultText*/,
18
+ 2*autNAMEMMAND_PATH" /*commandPath*/,
19
+ *aMMAND_PATH" /*commandPath*/,
20
+ "payload" /* payload */,
21
+ "requestId" /*requestId*/,
22
+ "resultCode" /*resultCode*/,
23
+ "resultT
24
+** Their values mightultText" /*resultText*/,
25
+ 2
26
+** public release
27
+**..9999
28
+** and error codes
29
+***/,
30
+ "COMMAND_PATH" /*commandPath*/,
31
+ "payload" /* payload */,
32
+ "requestId" /*requestId*/,
33
+ "resultCode" /*resultCode*/,
34
+ "resultText" /*resultText*/,
35
+ 2*aut*TFOUN3
--- a/src/json_detail.h
+++ b/src/json_detail.h
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/json_detail.h
+++ b/src/json_detail.h
@@ -0,0 +1,35 @@
1 *authToken*/,
2 "COMMAND_PATH" /*commandPath*/,
3 "payload" /* payload */,
4 "requestId" /*requestId*/,
5 "resultCode" /*resultCode*/,
6 "resultT
7 ** Their values mightultText" /*resultText*/,
8 2
9 ** public release
10 **..9999
11 ** and error codes
12 ***/,
13 "COMMAND_PATH" /*commandPath*/,
14 "payload" /* payload */,
15 "requestId" /*requestId*/,
16 "resultCode" /*resultCode*/,
17 "resultText" /*resultText*/,
18 2*autNAMEMMAND_PATH" /*commandPath*/,
19 *aMMAND_PATH" /*commandPath*/,
20 "payload" /* payload */,
21 "requestId" /*requestId*/,
22 "resultCode" /*resultCode*/,
23 "resultT
24 ** Their values mightultText" /*resultText*/,
25 2
26 ** public release
27 **..9999
28 ** and error codes
29 ***/,
30 "COMMAND_PATH" /*commandPath*/,
31 "payload" /* payload */,
32 "requestId" /*requestId*/,
33 "resultCode" /*resultCode*/,
34 "resultText" /*resultText*/,
35 2*aut*TFOUN3
+30 -11
--- src/main.c
+++ src/main.c
@@ -26,11 +26,11 @@
2626
#include <sys/types.h>
2727
#include <sys/stat.h>
2828
#include <stdlib.h> /* atexit() */
2929
3030
#if INTERFACE
31
-#include "cson_amalgamation.h" /* JSON API */
31
+#include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
3232
3333
/*
3434
** Number of elements in an array
3535
*/
3636
#define count(X) (sizeof(X)/sizeof(X[0]))
@@ -1034,13 +1034,17 @@
10341034
10351035
if( szFile<1024 ){
10361036
if( zNotFound ){
10371037
cgi_redirect(zNotFound);
10381038
}else{
1039
- @ <h1>Not Found</h1>
1040
- cgi_set_status(404, "not found");
1041
- cgi_reply();
1039
+ if(g.json.isJsonMode){
1040
+ json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
1041
+ }else{
1042
+ @ <h1>Not Found</h1>
1043
+ cgi_set_status(404, "not found");
1044
+ cgi_reply();
1045
+ }
10421046
}
10431047
return;
10441048
}
10451049
break;
10461050
}
@@ -1065,11 +1069,16 @@
10651069
zPathInfo = "/xfer";
10661070
}
10671071
set_base_url();
10681072
if( zPathInfo==0 || zPathInfo[0]==0
10691073
|| (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
1070
- fossil_redirect_home();
1074
+ if(g.json.isJsonMode){
1075
+ json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
1076
+ fossil_exit(0);
1077
+ }else{
1078
+ fossil_redirect_home() /*does not return*/;
1079
+ }
10711080
}else{
10721081
zPath = mprintf("%s", zPathInfo);
10731082
}
10741083
10751084
/* Make g.zPath point to the first element of the path. Make
@@ -1126,10 +1135,12 @@
11261135
break;
11271136
}
11281137
if( g.zExtra ){
11291138
/* CGI parameters get this treatment elsewhere, but places like getfile
11301139
** will use g.zExtra directly.
1140
+ ** Reminder: the login mechanism uses 'name' differently, and may
1141
+ ** eventually have a problem/collision with this.
11311142
*/
11321143
dehttpize(g.zExtra);
11331144
cgi_set_parameter_nocopy("name", g.zExtra);
11341145
}
11351146
@@ -1136,17 +1147,25 @@
11361147
/* Locate the method specified by the path and execute the function
11371148
** that implements that method.
11381149
*/
11391150
if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) &&
11401151
name_search("not_found", aWebpage, count(aWebpage), &idx) ){
1141
- cgi_set_status(404,"Not Found");
1142
- @ <h1>Not Found</h1>
1143
- @ <p>Page not found: %h(g.zPath)</p>
1152
+ if(g.json.isJsonMode){
1153
+ json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,0);
1154
+ }else{
1155
+ cgi_set_status(404,"Not Found");
1156
+ @ <h1>Not Found</h1>
1157
+ @ <p>Page not found: %h(g.zPath)</p>
1158
+ }
11441159
}else if( aWebpage[idx].xFunc!=page_xfer && db_schema_is_outofdate() ){
1145
- @ <h1>Server Configuration Error</h1>
1146
- @ <p>The database schema on the server is out-of-date. Please ask
1147
- @ the administrator to run <b>fossil rebuild</b>.</p>
1160
+ if(g.json.isJsonMode){
1161
+ json_err(FSL_JSON_E_DB_NEEDS_REBUILD,NULL,0);
1162
+ }else{
1163
+ @ <h1>Server Configuration Error</h1>
1164
+ @ <p>The database schema on the server is out-of-date. Please ask
1165
+ @ the administrator to run <b>fossil rebuild</b>.</p>
1166
+ }
11481167
}else{
11491168
aWebpage[idx].xFunc();
11501169
}
11511170
11521171
/* Return the result.
11531172
--- src/main.c
+++ src/main.c
@@ -26,11 +26,11 @@
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdlib.h> /* atexit() */
29
30 #if INTERFACE
31 #include "cson_amalgamation.h" /* JSON API */
32
33 /*
34 ** Number of elements in an array
35 */
36 #define count(X) (sizeof(X)/sizeof(X[0]))
@@ -1034,13 +1034,17 @@
1034
1035 if( szFile<1024 ){
1036 if( zNotFound ){
1037 cgi_redirect(zNotFound);
1038 }else{
1039 @ <h1>Not Found</h1>
1040 cgi_set_status(404, "not found");
1041 cgi_reply();
 
 
 
 
1042 }
1043 return;
1044 }
1045 break;
1046 }
@@ -1065,11 +1069,16 @@
1065 zPathInfo = "/xfer";
1066 }
1067 set_base_url();
1068 if( zPathInfo==0 || zPathInfo[0]==0
1069 || (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
1070 fossil_redirect_home();
 
 
 
 
 
1071 }else{
1072 zPath = mprintf("%s", zPathInfo);
1073 }
1074
1075 /* Make g.zPath point to the first element of the path. Make
@@ -1126,10 +1135,12 @@
1126 break;
1127 }
1128 if( g.zExtra ){
1129 /* CGI parameters get this treatment elsewhere, but places like getfile
1130 ** will use g.zExtra directly.
 
 
1131 */
1132 dehttpize(g.zExtra);
1133 cgi_set_parameter_nocopy("name", g.zExtra);
1134 }
1135
@@ -1136,17 +1147,25 @@
1136 /* Locate the method specified by the path and execute the function
1137 ** that implements that method.
1138 */
1139 if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) &&
1140 name_search("not_found", aWebpage, count(aWebpage), &idx) ){
1141 cgi_set_status(404,"Not Found");
1142 @ <h1>Not Found</h1>
1143 @ <p>Page not found: %h(g.zPath)</p>
 
 
 
 
1144 }else if( aWebpage[idx].xFunc!=page_xfer && db_schema_is_outofdate() ){
1145 @ <h1>Server Configuration Error</h1>
1146 @ <p>The database schema on the server is out-of-date. Please ask
1147 @ the administrator to run <b>fossil rebuild</b>.</p>
 
 
 
 
1148 }else{
1149 aWebpage[idx].xFunc();
1150 }
1151
1152 /* Return the result.
1153
--- src/main.c
+++ src/main.c
@@ -26,11 +26,11 @@
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdlib.h> /* atexit() */
29
30 #if INTERFACE
31 #include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
32
33 /*
34 ** Number of elements in an array
35 */
36 #define count(X) (sizeof(X)/sizeof(X[0]))
@@ -1034,13 +1034,17 @@
1034
1035 if( szFile<1024 ){
1036 if( zNotFound ){
1037 cgi_redirect(zNotFound);
1038 }else{
1039 if(g.json.isJsonMode){
1040 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
1041 }else{
1042 @ <h1>Not Found</h1>
1043 cgi_set_status(404, "not found");
1044 cgi_reply();
1045 }
1046 }
1047 return;
1048 }
1049 break;
1050 }
@@ -1065,11 +1069,16 @@
1069 zPathInfo = "/xfer";
1070 }
1071 set_base_url();
1072 if( zPathInfo==0 || zPathInfo[0]==0
1073 || (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
1074 if(g.json.isJsonMode){
1075 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,1);
1076 fossil_exit(0);
1077 }else{
1078 fossil_redirect_home() /*does not return*/;
1079 }
1080 }else{
1081 zPath = mprintf("%s", zPathInfo);
1082 }
1083
1084 /* Make g.zPath point to the first element of the path. Make
@@ -1126,10 +1135,12 @@
1135 break;
1136 }
1137 if( g.zExtra ){
1138 /* CGI parameters get this treatment elsewhere, but places like getfile
1139 ** will use g.zExtra directly.
1140 ** Reminder: the login mechanism uses 'name' differently, and may
1141 ** eventually have a problem/collision with this.
1142 */
1143 dehttpize(g.zExtra);
1144 cgi_set_parameter_nocopy("name", g.zExtra);
1145 }
1146
@@ -1136,17 +1147,25 @@
1147 /* Locate the method specified by the path and execute the function
1148 ** that implements that method.
1149 */
1150 if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) &&
1151 name_search("not_found", aWebpage, count(aWebpage), &idx) ){
1152 if(g.json.isJsonMode){
1153 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,0);
1154 }else{
1155 cgi_set_status(404,"Not Found");
1156 @ <h1>Not Found</h1>
1157 @ <p>Page not found: %h(g.zPath)</p>
1158 }
1159 }else if( aWebpage[idx].xFunc!=page_xfer && db_schema_is_outofdate() ){
1160 if(g.json.isJsonMode){
1161 json_err(FSL_JSON_E_DB_NEEDS_REBUILD,NULL,0);
1162 }else{
1163 @ <h1>Server Configuration Error</h1>
1164 @ <p>The database schema on the server is out-of-date. Please ask
1165 @ the administrator to run <b>fossil rebuild</b>.</p>
1166 }
1167 }else{
1168 aWebpage[idx].xFunc();
1169 }
1170
1171 /* Return the result.
1172

Keyboard Shortcuts

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