Fossil SCM

Minor error handling cleanups (nicer resultText strings). Removed a call to sqlite3_config() from the JSON bootstrap code which _seems_ to be the cause of an SQLITE_MISUSE warning.

stephan 2011-10-02 23:59 UTC json-multitag-test
Commit af72cc7599d357f15cabba936ca3d891bbfd7c44
+8 -2
--- src/json.c
+++ src/json.c
@@ -899,12 +899,18 @@
899899
900900
if(g.isHTTP){
901901
cgi_set_content_type(json_guess_content_type())
902902
/* reminder: must be done after g.json.jsonp is initialized */
903903
;
904
- /* avoids debug messages on stderr in JSON mode */
905
- sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0);
904
+#if 0
905
+ /* Calling this seems to trigger an SQLITE_MISUSE warning???
906
+ Maybe it's not legal to set the logger more than once?
907
+ */
908
+ sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0)
909
+ /* avoids debug messages on stderr in JSON mode */
910
+ ;
911
+#endif
906912
}
907913
908914
g.json.cmd.v = cson_value_new_array();
909915
g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
910916
json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 );
911917
--- src/json.c
+++ src/json.c
@@ -899,12 +899,18 @@
899
900 if(g.isHTTP){
901 cgi_set_content_type(json_guess_content_type())
902 /* reminder: must be done after g.json.jsonp is initialized */
903 ;
904 /* avoids debug messages on stderr in JSON mode */
905 sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0);
 
 
 
 
 
 
906 }
907
908 g.json.cmd.v = cson_value_new_array();
909 g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
910 json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 );
911
--- src/json.c
+++ src/json.c
@@ -899,12 +899,18 @@
899
900 if(g.isHTTP){
901 cgi_set_content_type(json_guess_content_type())
902 /* reminder: must be done after g.json.jsonp is initialized */
903 ;
904 #if 0
905 /* Calling this seems to trigger an SQLITE_MISUSE warning???
906 Maybe it's not legal to set the logger more than once?
907 */
908 sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0)
909 /* avoids debug messages on stderr in JSON mode */
910 ;
911 #endif
912 }
913
914 g.json.cmd.v = cson_value_new_array();
915 g.json.cmd.a = cson_value_get_array(g.json.cmd.v);
916 json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 );
917
--- src/json_branch.c
+++ src/json_branch.c
@@ -69,11 +69,12 @@
6969
char const * range = NULL;
7070
int which = 0;
7171
char * sawConversionError = NULL;
7272
Stmt q;
7373
if( !g.perm.Read ){
74
- g.json.resultCode = FSL_JSON_E_DENIED;
74
+ json_set_err(FSL_JSON_E_DENIED,
75
+ "Requires 'o' permissions.");
7576
return NULL;
7677
}
7778
payV = cson_value_new_object();
7879
pay = cson_value_get_object(payV);
7980
listV = cson_value_new_array();
@@ -308,19 +309,23 @@
308309
#endif
309310
return 0;
310311
}
311312
312313
314
+/*
315
+** Impl of /json/branch/create.
316
+*/
313317
static cson_value * json_branch_create(){
314318
cson_value * payV = NULL;
315319
cson_object * pay = NULL;
316320
int rc = 0;
317321
BranchCreateOptions opt;
318322
char * zUuid = NULL;
319323
int rid = 0;
320324
if( !g.perm.Write ){
321
- g.json.resultCode = FSL_JSON_E_DENIED;
325
+ json_set_err(FSL_JSON_E_DENIED,
326
+ "Requires 'i' permissions.");
322327
return NULL;
323328
}
324329
if(0){
325330
char const * x = json_command_arg(g.json.dispatchDepth+1);
326331
fprintf(stderr,"command arg=%s\n",x);
327332
--- src/json_branch.c
+++ src/json_branch.c
@@ -69,11 +69,12 @@
69 char const * range = NULL;
70 int which = 0;
71 char * sawConversionError = NULL;
72 Stmt q;
73 if( !g.perm.Read ){
74 g.json.resultCode = FSL_JSON_E_DENIED;
 
75 return NULL;
76 }
77 payV = cson_value_new_object();
78 pay = cson_value_get_object(payV);
79 listV = cson_value_new_array();
@@ -308,19 +309,23 @@
308 #endif
309 return 0;
310 }
311
312
 
 
 
313 static cson_value * json_branch_create(){
314 cson_value * payV = NULL;
315 cson_object * pay = NULL;
316 int rc = 0;
317 BranchCreateOptions opt;
318 char * zUuid = NULL;
319 int rid = 0;
320 if( !g.perm.Write ){
321 g.json.resultCode = FSL_JSON_E_DENIED;
 
322 return NULL;
323 }
324 if(0){
325 char const * x = json_command_arg(g.json.dispatchDepth+1);
326 fprintf(stderr,"command arg=%s\n",x);
327
--- src/json_branch.c
+++ src/json_branch.c
@@ -69,11 +69,12 @@
69 char const * range = NULL;
70 int which = 0;
71 char * sawConversionError = NULL;
72 Stmt q;
73 if( !g.perm.Read ){
74 json_set_err(FSL_JSON_E_DENIED,
75 "Requires 'o' permissions.");
76 return NULL;
77 }
78 payV = cson_value_new_object();
79 pay = cson_value_get_object(payV);
80 listV = cson_value_new_array();
@@ -308,19 +309,23 @@
309 #endif
310 return 0;
311 }
312
313
314 /*
315 ** Impl of /json/branch/create.
316 */
317 static cson_value * json_branch_create(){
318 cson_value * payV = NULL;
319 cson_object * pay = NULL;
320 int rc = 0;
321 BranchCreateOptions opt;
322 char * zUuid = NULL;
323 int rid = 0;
324 if( !g.perm.Write ){
325 json_set_err(FSL_JSON_E_DENIED,
326 "Requires 'i' permissions.");
327 return NULL;
328 }
329 if(0){
330 char const * x = json_command_arg(g.json.dispatchDepth+1);
331 fprintf(stderr,"command arg=%s\n",x);
332
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -53,10 +53,20 @@
5353
** Implements the /json/timeline family of pages/commands. Far from
5454
** complete.
5555
**
5656
*/
5757
cson_value * json_page_timeline(){
58
+#if 0
59
+ /* The original timeline code does not require 'h' access,
60
+ but it arguably should. For JSON mode i think one could argue
61
+ that History permissions are required.
62
+ */
63
+ if(! g.perm.History && !g.perm.Read ){
64
+ json_set_err(FSL_JSON_E_DENIED, "Timeline requires 'h' or 'o' access.");
65
+ return NULL;
66
+ }
67
+#endif
5868
return json_page_dispatch_helper(&JsonPageDefs_Timeline[0]);
5969
}
6070
6171
/*
6272
** Create a temporary table suitable for storing timeline data.
@@ -375,12 +385,15 @@
375385
int showFiles = 0;
376386
Stmt q = empty_Stmt;
377387
char warnRowToJsonFailed = 0;
378388
char warnStringToArrayFailed = 0;
379389
Blob sql = empty_blob;
380
- if( !g.perm.Read/* && !g.perm.RdTkt && !g.perm.RdWiki*/ ){
381
- g.json.resultCode = FSL_JSON_E_DENIED;
390
+ if( !g.perm.Read ){
391
+ /* IMO this falls more under the category of g.perm.History, but
392
+ i'm following the original timeline impl here.
393
+ */
394
+ json_set_err( FSL_JSON_E_DENIED, "Checkin timeline requires 'o' access." );
382395
return NULL;
383396
}
384397
if( g.isHTTP ){
385398
showFiles = json_getenv_bool("files",0);
386399
}else{
@@ -468,12 +481,12 @@
468481
cson_value * listV = NULL;
469482
cson_array * list = NULL;
470483
int check = 0;
471484
Stmt q = empty_Stmt;
472485
Blob sql = empty_blob;
473
- if( !g.perm.Read || !g.perm.RdWiki ){
474
- g.json.resultCode = FSL_JSON_E_DENIED;
486
+ if( !g.perm.RdWiki && !g.perm.Read ){
487
+ json_set_err( FSL_JSON_E_DENIED, "Wiki timeline requires 'o' or 'j' access.");
475488
return NULL;
476489
}
477490
payV = cson_value_new_object();
478491
pay = cson_value_get_object(payV);
479492
check = json_timeline_setup_sql( "w", &sql, pay );
@@ -541,12 +554,12 @@
541554
cson_value * listV = NULL;
542555
cson_array * list = NULL;
543556
int check = 0;
544557
Stmt q = empty_Stmt;
545558
Blob sql = empty_blob;
546
- if( !g.perm.Read || !g.perm.RdTkt ){
547
- g.json.resultCode = FSL_JSON_E_DENIED;
559
+ if( !g.perm.RdTkt && !g.perm.Read ){
560
+ json_set_err(FSL_JSON_E_DENIED, "Ticket timeline requires 'o' or 'r' access.");
548561
return NULL;
549562
}
550563
payV = cson_value_new_object();
551564
pay = cson_value_get_object(payV);
552565
check = json_timeline_setup_sql( "t", &sql, pay );
553566
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -53,10 +53,20 @@
53 ** Implements the /json/timeline family of pages/commands. Far from
54 ** complete.
55 **
56 */
57 cson_value * json_page_timeline(){
 
 
 
 
 
 
 
 
 
 
58 return json_page_dispatch_helper(&JsonPageDefs_Timeline[0]);
59 }
60
61 /*
62 ** Create a temporary table suitable for storing timeline data.
@@ -375,12 +385,15 @@
375 int showFiles = 0;
376 Stmt q = empty_Stmt;
377 char warnRowToJsonFailed = 0;
378 char warnStringToArrayFailed = 0;
379 Blob sql = empty_blob;
380 if( !g.perm.Read/* && !g.perm.RdTkt && !g.perm.RdWiki*/ ){
381 g.json.resultCode = FSL_JSON_E_DENIED;
 
 
 
382 return NULL;
383 }
384 if( g.isHTTP ){
385 showFiles = json_getenv_bool("files",0);
386 }else{
@@ -468,12 +481,12 @@
468 cson_value * listV = NULL;
469 cson_array * list = NULL;
470 int check = 0;
471 Stmt q = empty_Stmt;
472 Blob sql = empty_blob;
473 if( !g.perm.Read || !g.perm.RdWiki ){
474 g.json.resultCode = FSL_JSON_E_DENIED;
475 return NULL;
476 }
477 payV = cson_value_new_object();
478 pay = cson_value_get_object(payV);
479 check = json_timeline_setup_sql( "w", &sql, pay );
@@ -541,12 +554,12 @@
541 cson_value * listV = NULL;
542 cson_array * list = NULL;
543 int check = 0;
544 Stmt q = empty_Stmt;
545 Blob sql = empty_blob;
546 if( !g.perm.Read || !g.perm.RdTkt ){
547 g.json.resultCode = FSL_JSON_E_DENIED;
548 return NULL;
549 }
550 payV = cson_value_new_object();
551 pay = cson_value_get_object(payV);
552 check = json_timeline_setup_sql( "t", &sql, pay );
553
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -53,10 +53,20 @@
53 ** Implements the /json/timeline family of pages/commands. Far from
54 ** complete.
55 **
56 */
57 cson_value * json_page_timeline(){
58 #if 0
59 /* The original timeline code does not require 'h' access,
60 but it arguably should. For JSON mode i think one could argue
61 that History permissions are required.
62 */
63 if(! g.perm.History && !g.perm.Read ){
64 json_set_err(FSL_JSON_E_DENIED, "Timeline requires 'h' or 'o' access.");
65 return NULL;
66 }
67 #endif
68 return json_page_dispatch_helper(&JsonPageDefs_Timeline[0]);
69 }
70
71 /*
72 ** Create a temporary table suitable for storing timeline data.
@@ -375,12 +385,15 @@
385 int showFiles = 0;
386 Stmt q = empty_Stmt;
387 char warnRowToJsonFailed = 0;
388 char warnStringToArrayFailed = 0;
389 Blob sql = empty_blob;
390 if( !g.perm.Read ){
391 /* IMO this falls more under the category of g.perm.History, but
392 i'm following the original timeline impl here.
393 */
394 json_set_err( FSL_JSON_E_DENIED, "Checkin timeline requires 'o' access." );
395 return NULL;
396 }
397 if( g.isHTTP ){
398 showFiles = json_getenv_bool("files",0);
399 }else{
@@ -468,12 +481,12 @@
481 cson_value * listV = NULL;
482 cson_array * list = NULL;
483 int check = 0;
484 Stmt q = empty_Stmt;
485 Blob sql = empty_blob;
486 if( !g.perm.RdWiki && !g.perm.Read ){
487 json_set_err( FSL_JSON_E_DENIED, "Wiki timeline requires 'o' or 'j' access.");
488 return NULL;
489 }
490 payV = cson_value_new_object();
491 pay = cson_value_get_object(payV);
492 check = json_timeline_setup_sql( "w", &sql, pay );
@@ -541,12 +554,12 @@
554 cson_value * listV = NULL;
555 cson_array * list = NULL;
556 int check = 0;
557 Stmt q = empty_Stmt;
558 Blob sql = empty_blob;
559 if( !g.perm.RdTkt && !g.perm.Read ){
560 json_set_err(FSL_JSON_E_DENIED, "Ticket timeline requires 'o' or 'r' access.");
561 return NULL;
562 }
563 payV = cson_value_new_object();
564 pay = cson_value_get_object(payV);
565 check = json_timeline_setup_sql( "t", &sql, pay );
566
+30 -15
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -60,19 +60,21 @@
6060
char const * zBody = NULL;
6161
char const * zPageName;
6262
char const * zFormat = NULL;
6363
char * zUuid = NULL;
6464
Stmt q;
65
- if( !g.perm.RdWiki ){
66
- g.json.resultCode = FSL_JSON_E_DENIED;
65
+ if( !g.perm.RdWiki && !g.perm.Read ){
66
+ json_set_err(FSL_JSON_E_DENIED,
67
+ "Requires 'o' or 'j' access.");
6768
return NULL;
6869
}
6970
zPageName = g.isHTTP
7071
? json_getenv_cstr("page")
7172
: find_option("page","p",1);
7273
if(!zPageName||!*zPageName){
73
- g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
74
+ json_set_err(FSL_JSON_E_MISSING_ARGS,
75
+ "'page' argument is missing.");
7476
return NULL;
7577
}
7678
7779
zFormat = g.isHTTP
7880
? json_getenv_cstr("format")
@@ -90,11 +92,12 @@
9092
" ORDER BY x.mtime DESC LIMIT 1",
9193
zPageName
9294
);
9395
if( (SQLITE_ROW != db_step(&q)) ){
9496
manifest_destroy(pWiki);
95
- g.json.resultCode = FSL_JSON_E_UNKNOWN;
97
+ json_set_err(FSL_JSON_E_UNKNOWN,
98
+ "Error reading wiki page manifest.");
9699
return NULL;
97100
}
98101
rid = db_column_int(&q,0);
99102
zUuid = db_column_malloc(&q,1);
100103
db_finalize(&q);
@@ -103,11 +106,12 @@
103106
zBody = pWiki->zWiki;
104107
}
105108
if( zBody==0 ){
106109
manifest_destroy(pWiki);
107110
free(zUuid);
108
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
111
+ json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
112
+ "Wiki body is empty (is that possible?)");
109113
return NULL;
110114
}
111115
112116
{
113117
unsigned int len;
@@ -176,17 +180,20 @@
176180
char const * zPageName;
177181
unsigned int contentLen = 0;
178182
int rid;
179183
if( (createMode && !g.perm.NewWiki)
180184
|| (!createMode && !g.perm.WrWiki)){
181
- g.json.resultCode = FSL_JSON_E_DENIED;
185
+ json_set_err(FSL_JSON_E_DENIED,
186
+ "Requires '%c' permissions.",
187
+ (createMode ? 'f' : 'k'));
182188
return NULL;
183189
}
184190
nameV = json_req_payload_get("name");
185191
if(!nameV){
186
- g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
187
- goto error;
192
+ json_set_err( FSL_JSON_E_MISSING_ARGS,
193
+ "'name' parameter is missing.");
194
+ return NULL;
188195
}
189196
zPageName = cson_string_cstr(cson_value_get_string(nameV));
190197
rid = db_int(0,
191198
"SELECT x.rid FROM tag t, tagxref x"
192199
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
@@ -194,30 +201,36 @@
194201
zPageName
195202
);
196203
197204
if(rid){
198205
if(createMode){
199
- g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
206
+ json_set_err(FSL_JSON_E_RESOURCE_ALREADY_EXISTS,
207
+ "Wiki page '%s' already exists.",
208
+ zPageName);
200209
goto error;
201210
}
202211
}else if(!allowCreateIfExists){
203
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
212
+ json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
213
+ "Wiki page '%s' not found.",
214
+ zPageName);
204215
goto error;
205216
}
206217
207218
contentV = json_req_payload_get("content");
208219
if( !contentV ){
209220
if( createMode || (!rid && allowCreateIfExists) ){
210221
contentV = emptyContent = cson_value_new_string("",0);
211222
}else{
212
- g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
223
+ json_set_err(FSL_JSON_E_MISSING_ARGS,
224
+ "'content' parameter is missing.");
213225
goto error;
214226
}
215227
}
216228
if( !cson_value_is_string(nameV)
217229
|| !cson_value_is_string(contentV)){
218
- g.json.resultCode = FSL_JSON_E_INVALID_ARGS;
230
+ json_set_err(FSL_JSON_E_INVALID_ARGS,
231
+ "'name' and 'content' parameters must be strings.");
219232
goto error;
220233
}
221234
jstr = cson_value_get_string(contentV);
222235
contentLen = (int)cson_string_length_bytes(jstr);
223236
if(contentLen){
@@ -273,12 +286,13 @@
273286
*/
274287
static cson_value * json_wiki_list(){
275288
cson_value * listV = NULL;
276289
cson_array * list = NULL;
277290
Stmt q;
278
- if( !g.perm.RdWiki ){
279
- g.json.resultCode = FSL_JSON_E_DENIED;
291
+ if( !g.perm.RdWiki && !g.perm.Read ){
292
+ json_set_err(FSL_JSON_E_DENIED,
293
+ "Requires 'j' or 'o' permissions.");
280294
return NULL;
281295
}
282296
db_prepare(&q,"SELECT"
283297
" substr(tagname,6) as name"
284298
" FROM tag WHERE tagname GLOB 'wiki-*'"
@@ -294,12 +308,13 @@
294308
goto error;
295309
}
296310
}
297311
goto end;
298312
error:
299
- g.json.resultCode = FSL_JSON_E_UNKNOWN;
300313
cson_value_free(listV);
301314
listV = NULL;
315
+ json_set_err(FSL_JSON_E_UNKNOWN,
316
+ "Error creating wiki page list.");
302317
end:
303318
db_finalize(&q);
304319
return listV;
305320
}
306321
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -60,19 +60,21 @@
60 char const * zBody = NULL;
61 char const * zPageName;
62 char const * zFormat = NULL;
63 char * zUuid = NULL;
64 Stmt q;
65 if( !g.perm.RdWiki ){
66 g.json.resultCode = FSL_JSON_E_DENIED;
 
67 return NULL;
68 }
69 zPageName = g.isHTTP
70 ? json_getenv_cstr("page")
71 : find_option("page","p",1);
72 if(!zPageName||!*zPageName){
73 g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
 
74 return NULL;
75 }
76
77 zFormat = g.isHTTP
78 ? json_getenv_cstr("format")
@@ -90,11 +92,12 @@
90 " ORDER BY x.mtime DESC LIMIT 1",
91 zPageName
92 );
93 if( (SQLITE_ROW != db_step(&q)) ){
94 manifest_destroy(pWiki);
95 g.json.resultCode = FSL_JSON_E_UNKNOWN;
 
96 return NULL;
97 }
98 rid = db_column_int(&q,0);
99 zUuid = db_column_malloc(&q,1);
100 db_finalize(&q);
@@ -103,11 +106,12 @@
103 zBody = pWiki->zWiki;
104 }
105 if( zBody==0 ){
106 manifest_destroy(pWiki);
107 free(zUuid);
108 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
 
109 return NULL;
110 }
111
112 {
113 unsigned int len;
@@ -176,17 +180,20 @@
176 char const * zPageName;
177 unsigned int contentLen = 0;
178 int rid;
179 if( (createMode && !g.perm.NewWiki)
180 || (!createMode && !g.perm.WrWiki)){
181 g.json.resultCode = FSL_JSON_E_DENIED;
 
 
182 return NULL;
183 }
184 nameV = json_req_payload_get("name");
185 if(!nameV){
186 g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
187 goto error;
 
188 }
189 zPageName = cson_string_cstr(cson_value_get_string(nameV));
190 rid = db_int(0,
191 "SELECT x.rid FROM tag t, tagxref x"
192 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
@@ -194,30 +201,36 @@
194 zPageName
195 );
196
197 if(rid){
198 if(createMode){
199 g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
 
 
200 goto error;
201 }
202 }else if(!allowCreateIfExists){
203 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
 
 
204 goto error;
205 }
206
207 contentV = json_req_payload_get("content");
208 if( !contentV ){
209 if( createMode || (!rid && allowCreateIfExists) ){
210 contentV = emptyContent = cson_value_new_string("",0);
211 }else{
212 g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
 
213 goto error;
214 }
215 }
216 if( !cson_value_is_string(nameV)
217 || !cson_value_is_string(contentV)){
218 g.json.resultCode = FSL_JSON_E_INVALID_ARGS;
 
219 goto error;
220 }
221 jstr = cson_value_get_string(contentV);
222 contentLen = (int)cson_string_length_bytes(jstr);
223 if(contentLen){
@@ -273,12 +286,13 @@
273 */
274 static cson_value * json_wiki_list(){
275 cson_value * listV = NULL;
276 cson_array * list = NULL;
277 Stmt q;
278 if( !g.perm.RdWiki ){
279 g.json.resultCode = FSL_JSON_E_DENIED;
 
280 return NULL;
281 }
282 db_prepare(&q,"SELECT"
283 " substr(tagname,6) as name"
284 " FROM tag WHERE tagname GLOB 'wiki-*'"
@@ -294,12 +308,13 @@
294 goto error;
295 }
296 }
297 goto end;
298 error:
299 g.json.resultCode = FSL_JSON_E_UNKNOWN;
300 cson_value_free(listV);
301 listV = NULL;
 
 
302 end:
303 db_finalize(&q);
304 return listV;
305 }
306
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -60,19 +60,21 @@
60 char const * zBody = NULL;
61 char const * zPageName;
62 char const * zFormat = NULL;
63 char * zUuid = NULL;
64 Stmt q;
65 if( !g.perm.RdWiki && !g.perm.Read ){
66 json_set_err(FSL_JSON_E_DENIED,
67 "Requires 'o' or 'j' access.");
68 return NULL;
69 }
70 zPageName = g.isHTTP
71 ? json_getenv_cstr("page")
72 : find_option("page","p",1);
73 if(!zPageName||!*zPageName){
74 json_set_err(FSL_JSON_E_MISSING_ARGS,
75 "'page' argument is missing.");
76 return NULL;
77 }
78
79 zFormat = g.isHTTP
80 ? json_getenv_cstr("format")
@@ -90,11 +92,12 @@
92 " ORDER BY x.mtime DESC LIMIT 1",
93 zPageName
94 );
95 if( (SQLITE_ROW != db_step(&q)) ){
96 manifest_destroy(pWiki);
97 json_set_err(FSL_JSON_E_UNKNOWN,
98 "Error reading wiki page manifest.");
99 return NULL;
100 }
101 rid = db_column_int(&q,0);
102 zUuid = db_column_malloc(&q,1);
103 db_finalize(&q);
@@ -103,11 +106,12 @@
106 zBody = pWiki->zWiki;
107 }
108 if( zBody==0 ){
109 manifest_destroy(pWiki);
110 free(zUuid);
111 json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
112 "Wiki body is empty (is that possible?)");
113 return NULL;
114 }
115
116 {
117 unsigned int len;
@@ -176,17 +180,20 @@
180 char const * zPageName;
181 unsigned int contentLen = 0;
182 int rid;
183 if( (createMode && !g.perm.NewWiki)
184 || (!createMode && !g.perm.WrWiki)){
185 json_set_err(FSL_JSON_E_DENIED,
186 "Requires '%c' permissions.",
187 (createMode ? 'f' : 'k'));
188 return NULL;
189 }
190 nameV = json_req_payload_get("name");
191 if(!nameV){
192 json_set_err( FSL_JSON_E_MISSING_ARGS,
193 "'name' parameter is missing.");
194 return NULL;
195 }
196 zPageName = cson_string_cstr(cson_value_get_string(nameV));
197 rid = db_int(0,
198 "SELECT x.rid FROM tag t, tagxref x"
199 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
@@ -194,30 +201,36 @@
201 zPageName
202 );
203
204 if(rid){
205 if(createMode){
206 json_set_err(FSL_JSON_E_RESOURCE_ALREADY_EXISTS,
207 "Wiki page '%s' already exists.",
208 zPageName);
209 goto error;
210 }
211 }else if(!allowCreateIfExists){
212 json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
213 "Wiki page '%s' not found.",
214 zPageName);
215 goto error;
216 }
217
218 contentV = json_req_payload_get("content");
219 if( !contentV ){
220 if( createMode || (!rid && allowCreateIfExists) ){
221 contentV = emptyContent = cson_value_new_string("",0);
222 }else{
223 json_set_err(FSL_JSON_E_MISSING_ARGS,
224 "'content' parameter is missing.");
225 goto error;
226 }
227 }
228 if( !cson_value_is_string(nameV)
229 || !cson_value_is_string(contentV)){
230 json_set_err(FSL_JSON_E_INVALID_ARGS,
231 "'name' and 'content' parameters must be strings.");
232 goto error;
233 }
234 jstr = cson_value_get_string(contentV);
235 contentLen = (int)cson_string_length_bytes(jstr);
236 if(contentLen){
@@ -273,12 +286,13 @@
286 */
287 static cson_value * json_wiki_list(){
288 cson_value * listV = NULL;
289 cson_array * list = NULL;
290 Stmt q;
291 if( !g.perm.RdWiki && !g.perm.Read ){
292 json_set_err(FSL_JSON_E_DENIED,
293 "Requires 'j' or 'o' permissions.");
294 return NULL;
295 }
296 db_prepare(&q,"SELECT"
297 " substr(tagname,6) as name"
298 " FROM tag WHERE tagname GLOB 'wiki-*'"
@@ -294,12 +308,13 @@
308 goto error;
309 }
310 }
311 goto end;
312 error:
 
313 cson_value_free(listV);
314 listV = NULL;
315 json_set_err(FSL_JSON_E_UNKNOWN,
316 "Error creating wiki page list.");
317 end:
318 db_finalize(&q);
319 return listV;
320 }
321

Keyboard Shortcuts

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