Fossil SCM

Refactored [23e138e808] a bit to move some new json-only code from main.c to json.c.

stephan 2020-07-09 12:53 trunk
Commit b2ac21832530a457833b97b9a4549082e1356a5a17350efabab05bd71f1b2d1b
2 files changed +33 -35
+33
--- src/json.c
+++ src/json.c
@@ -51,10 +51,43 @@
5151
"requestId" /*requestId*/,
5252
"resultCode" /*resultCode*/,
5353
"resultText" /*resultText*/,
5454
"timestamp" /*timestamp*/
5555
};
56
+
57
+/*
58
+** Given the current request path string, this function returns true
59
+** if it refers to a JSON API path. i.e. if (1) it starts with /json
60
+** or (2) g.zCmdName is "server" and the path starts with
61
+** /somereponame/json. Specifically, it returns 1 in the former case
62
+** and 2 for the latter.
63
+*/
64
+int json_request_is_json_api(const char * zPathInfo){
65
+ int rc = 0;
66
+ if(zPathInfo==0){
67
+ rc = 0;
68
+ }else if(0==strncmp("/json",zPathInfo,5)
69
+ && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
70
+ rc = 1;
71
+ }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){
72
+ /* When running in server "directory" mode, zPathInfo is
73
+ ** prefixed with the repository's name, so in order to determine
74
+ ** whether or not we're really running in json mode we have to
75
+ ** try a bit harder. Problem reported here:
76
+ ** https://fossil-scm.org/forum/forumpost/e4953666d6
77
+ */
78
+ ReCompiled * pReg = 0;
79
+ const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0);
80
+ assert(zErr==0 && "Regex compilation failed?");
81
+ if(zErr==0 &&
82
+ re_match(pReg, (const unsigned char *)zPathInfo, -1)){
83
+ rc = 2;
84
+ }
85
+ re_free(pReg);
86
+ }
87
+ return rc;
88
+}
5689
5790
/*
5891
** Returns true (non-0) if fossil appears to be running in JSON mode.
5992
** and either has JSON POSTed input awaiting consumption or fossil is
6093
** running in HTTP mode (in which case certain JSON data *might* be
6194
--- src/json.c
+++ src/json.c
@@ -51,10 +51,43 @@
51 "requestId" /*requestId*/,
52 "resultCode" /*resultCode*/,
53 "resultText" /*resultText*/,
54 "timestamp" /*timestamp*/
55 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
57 /*
58 ** Returns true (non-0) if fossil appears to be running in JSON mode.
59 ** and either has JSON POSTed input awaiting consumption or fossil is
60 ** running in HTTP mode (in which case certain JSON data *might* be
61
--- src/json.c
+++ src/json.c
@@ -51,10 +51,43 @@
51 "requestId" /*requestId*/,
52 "resultCode" /*resultCode*/,
53 "resultText" /*resultText*/,
54 "timestamp" /*timestamp*/
55 };
56
57 /*
58 ** Given the current request path string, this function returns true
59 ** if it refers to a JSON API path. i.e. if (1) it starts with /json
60 ** or (2) g.zCmdName is "server" and the path starts with
61 ** /somereponame/json. Specifically, it returns 1 in the former case
62 ** and 2 for the latter.
63 */
64 int json_request_is_json_api(const char * zPathInfo){
65 int rc = 0;
66 if(zPathInfo==0){
67 rc = 0;
68 }else if(0==strncmp("/json",zPathInfo,5)
69 && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
70 rc = 1;
71 }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){
72 /* When running in server "directory" mode, zPathInfo is
73 ** prefixed with the repository's name, so in order to determine
74 ** whether or not we're really running in json mode we have to
75 ** try a bit harder. Problem reported here:
76 ** https://fossil-scm.org/forum/forumpost/e4953666d6
77 */
78 ReCompiled * pReg = 0;
79 const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0);
80 assert(zErr==0 && "Regex compilation failed?");
81 if(zErr==0 &&
82 re_match(pReg, (const unsigned char *)zPathInfo, -1)){
83 rc = 2;
84 }
85 re_free(pReg);
86 }
87 return rc;
88 }
89
90 /*
91 ** Returns true (non-0) if fossil appears to be running in JSON mode.
92 ** and either has JSON POSTed input awaiting consumption or fossil is
93 ** running in HTTP mode (in which case certain JSON data *might* be
94
-35
--- src/main.c
+++ src/main.c
@@ -1527,45 +1527,10 @@
15271527
return 1;
15281528
}
15291529
return 0;
15301530
}
15311531
1532
-#ifdef FOSSIL_ENABLE_JSON
1533
-/*
1534
-** Given the current request path string, this function returns true
1535
-** if it refers to a JSON API path. i.e. if (1) it starts with /json
1536
-** or (2) g.zCmdName is "server" and the path starts with
1537
-** /somereponame/json. Specifically, it returns 1 in the former case
1538
-** and 2 for the latter.
1539
-*/
1540
-int json_request_is_json_api(const char * zPathInfo){
1541
- int rc = 0;
1542
- if(zPathInfo==0){
1543
- rc = 0;
1544
- }else if(0==strncmp("/json",zPathInfo,5)
1545
- && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
1546
- rc = 1;
1547
- }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){
1548
- /* When running in server "directory" mode, zPathInfo is
1549
- ** prefixed with the repository's name, so in order to determine
1550
- ** whether or not we're really running in json mode we have to
1551
- ** try a bit harder. Problem reported here:
1552
- ** https://fossil-scm.org/forum/forumpost/e4953666d6
1553
- */
1554
- ReCompiled * pReg = 0;
1555
- const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0);
1556
- assert(zErr==0 && "Regex compilation failed?");
1557
- if(zErr==0 &&
1558
- re_match(pReg, (const unsigned char *)zPathInfo, -1)){
1559
- rc = 2;
1560
- }
1561
- re_free(pReg);
1562
- }
1563
- return rc;
1564
-}
1565
-#endif
1566
-
15671532
/*
15681533
** Preconditions:
15691534
**
15701535
** * Environment variables are set up according to the CGI standard.
15711536
**
15721537
--- src/main.c
+++ src/main.c
@@ -1527,45 +1527,10 @@
1527 return 1;
1528 }
1529 return 0;
1530 }
1531
1532 #ifdef FOSSIL_ENABLE_JSON
1533 /*
1534 ** Given the current request path string, this function returns true
1535 ** if it refers to a JSON API path. i.e. if (1) it starts with /json
1536 ** or (2) g.zCmdName is "server" and the path starts with
1537 ** /somereponame/json. Specifically, it returns 1 in the former case
1538 ** and 2 for the latter.
1539 */
1540 int json_request_is_json_api(const char * zPathInfo){
1541 int rc = 0;
1542 if(zPathInfo==0){
1543 rc = 0;
1544 }else if(0==strncmp("/json",zPathInfo,5)
1545 && (zPathInfo[5]==0 || zPathInfo[5]=='/')){
1546 rc = 1;
1547 }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){
1548 /* When running in server "directory" mode, zPathInfo is
1549 ** prefixed with the repository's name, so in order to determine
1550 ** whether or not we're really running in json mode we have to
1551 ** try a bit harder. Problem reported here:
1552 ** https://fossil-scm.org/forum/forumpost/e4953666d6
1553 */
1554 ReCompiled * pReg = 0;
1555 const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0);
1556 assert(zErr==0 && "Regex compilation failed?");
1557 if(zErr==0 &&
1558 re_match(pReg, (const unsigned char *)zPathInfo, -1)){
1559 rc = 2;
1560 }
1561 re_free(pReg);
1562 }
1563 return rc;
1564 }
1565 #endif
1566
1567 /*
1568 ** Preconditions:
1569 **
1570 ** * Environment variables are set up according to the CGI standard.
1571 **
1572
--- src/main.c
+++ src/main.c
@@ -1527,45 +1527,10 @@
1527 return 1;
1528 }
1529 return 0;
1530 }
1531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1532 /*
1533 ** Preconditions:
1534 **
1535 ** * Environment variables are set up according to the CGI standard.
1536 **
1537

Keyboard Shortcuts

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