| ︙ | | |
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
+
+
|
}else{
if( *z ){ *z++ = 0; }
zValue = "";
}
if( fossil_islower(zName[0]) ){
cgi_set_parameter_nocopy(zName, zValue);
}
#ifdef FOSSIL_ENABLE_JSON
json_setenv( zName, cson_value_new_string(zValue,strlen(zValue)) );
#endif /* FOSSIL_ENABLE_JSON */
}
}
/*
** *pz is a string that consists of multiple lines of text. This
** routine finds the end of the current line of text and converts
** the "\n" or "\r\n" that ends that line into a "\000". It then
|
| ︙ | | |
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
|
+
|
}
}
}
}
}
#ifdef FOSSIL_ENABLE_JSON
/*
** Internal helper for cson_data_source_FILE_n().
*/
typedef struct CgiPostReadState_ {
FILE * fh;
unsigned int len;
unsigned int pos;
|
| ︙ | | |
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
+
+
+
|
}
return;
invalidRequest:
cgi_set_content_type(json_guess_content_type());
json_err( FSL_JSON_E_INVALID_REQUEST, NULL, 1 );
fossil_exit( g.isHTTP ? 0 : 1);
}
#endif /* FOSSIL_ENABLE_JSON */
/*
** Initialize the query parameter database. Information is pulled from
** the QUERY_STRING environment variable (if it exists), from standard
** input if there is POST data, and from HTTP_COOKIE.
*/
void cgi_init(void){
char *z;
const char *zType;
int len;
#ifdef FOSSIL_ENABLE_JSON
json_main_bootstrap();
#endif
g.isHTTP = 1;
cgi_destination(CGI_BODY);
z = (char*)P("HTTP_COOKIE");
if( z ){
z = mprintf("%s",z);
add_param_list(z, ';');
|
| ︙ | | |
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
|
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
|
+
+
-
+
|
}else if( fossil_strcmp(zType, "application/x-fossil")==0 ){
blob_read_from_channel(&g.cgiIn, g.httpIn, len);
blob_uncompress(&g.cgiIn, &g.cgiIn);
}else if( fossil_strcmp(zType, "application/x-fossil-debug")==0 ){
blob_read_from_channel(&g.cgiIn, g.httpIn, len);
}else if( fossil_strcmp(zType, "application/x-fossil-uncompressed")==0 ){
blob_read_from_channel(&g.cgiIn, g.httpIn, len);
}
#ifdef FOSSIL_ENABLE_JSON
}else if( fossil_strcmp(zType, "application/json")
else if( fossil_strcmp(zType, "application/json")
|| fossil_strcmp(zType,"text/plain")/*assume this MIGHT be JSON*/
|| fossil_strcmp(zType,"application/javascript")){
g.json.isJsonMode = 1;
cgi_parse_POST_JSON(g.httpIn, (unsigned int)len);
/* FIXMEs:
- See if fossil really needs g.cgiIn to be set for this purpose
|
| ︙ | | |
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
+
|
- If we do that then we might get a disconnect in precedence of
GET/POST arguments. i prefer for GET entries to take precedence
over like-named POST entries, but in order for that to happen we
need to process QUERY_STRING _after_ reading the POST data.
*/
cgi_set_content_type(json_guess_content_type());
}
#endif /* FOSSIL_ENABLE_JSON */
}
}
/*
** This is the comparison function used to sort the aParamQP[] array of
** query parameters and cookies.
|
| ︙ | | |
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
|
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
|
+
-
+
+
+
-
-
-
+
+
+
|
/*
** Panic and die while processing a webpage.
*/
NORETURN void cgi_panic(const char *zFormat, ...){
va_list ap;
cgi_reset_content();
#ifdef FOSSIL_ENABLE_JSON
if( g.json.isJsonMode ){
char * zMsg;
va_start(ap, zFormat);
zMsg = vmprintf(zFormat,ap);
va_end(ap);
json_err( FSL_JSON_E_PANIC, zMsg, 1 );
free(zMsg);
fossil_exit( g.isHTTP ? 0 : 1 );
}else{
}else
#endif /* FOSSIL_ENABLE_JSON */
{
cgi_set_status(500, "Internal Server Error");
cgi_printf(
"<html><body><h1>Internal Server Error</h1>\n"
"<plaintext>"
);
"<html><body><h1>Internal Server Error</h1>\n"
"<plaintext>"
);
va_start(ap, zFormat);
vxprintf(pContent,zFormat,ap);
va_end(ap);
cgi_reply();
fossil_exit(1);
}
}
|
| ︙ | | |