Fossil SCM

Several minor internal cleanups to the json code which i thought i had committed last week :/.

stephan 2012-07-13 15:06 trunk
Commit 055dfb1223c42a2d89e388f5cf9d42c3b9f1c044
+2 -2
--- src/json.c
+++ src/json.c
@@ -1698,11 +1698,11 @@
16981698
assert(NULL!=a);
16991699
}
17001700
if(!colNames){
17011701
colNamesV = cson_sqlite3_column_names(pStmt->pStmt);
17021702
assert(NULL != colNamesV);
1703
- cson_value_add_reference(colNamesV)/*avoids an ownership problem*/;
1703
+ /*Why? cson_value_add_reference(colNamesV) avoids an ownership problem*/;
17041704
colNames = cson_value_get_array(colNamesV);
17051705
assert(NULL != colNames);
17061706
}
17071707
row = cson_sqlite3_row_to_object2(pStmt->pStmt, colNames);
17081708
if(!row && !warnMsg){
@@ -1709,14 +1709,14 @@
17091709
warnMsg = "Could not convert at least one result row to JSON.";
17101710
continue;
17111711
}
17121712
if( 0 != cson_array_append(a, row) ){
17131713
cson_value_free(row);
1714
- assert( 0 && "Alloc error.");
17151714
if(pTgt != a) {
17161715
cson_free_array(a);
17171716
}
1717
+ assert( 0 && "Alloc error.");
17181718
return NULL;
17191719
}
17201720
}
17211721
cson_value_free(colNamesV);
17221722
if(warnMsg){
17231723
--- src/json.c
+++ src/json.c
@@ -1698,11 +1698,11 @@
1698 assert(NULL!=a);
1699 }
1700 if(!colNames){
1701 colNamesV = cson_sqlite3_column_names(pStmt->pStmt);
1702 assert(NULL != colNamesV);
1703 cson_value_add_reference(colNamesV)/*avoids an ownership problem*/;
1704 colNames = cson_value_get_array(colNamesV);
1705 assert(NULL != colNames);
1706 }
1707 row = cson_sqlite3_row_to_object2(pStmt->pStmt, colNames);
1708 if(!row && !warnMsg){
@@ -1709,14 +1709,14 @@
1709 warnMsg = "Could not convert at least one result row to JSON.";
1710 continue;
1711 }
1712 if( 0 != cson_array_append(a, row) ){
1713 cson_value_free(row);
1714 assert( 0 && "Alloc error.");
1715 if(pTgt != a) {
1716 cson_free_array(a);
1717 }
 
1718 return NULL;
1719 }
1720 }
1721 cson_value_free(colNamesV);
1722 if(warnMsg){
1723
--- src/json.c
+++ src/json.c
@@ -1698,11 +1698,11 @@
1698 assert(NULL!=a);
1699 }
1700 if(!colNames){
1701 colNamesV = cson_sqlite3_column_names(pStmt->pStmt);
1702 assert(NULL != colNamesV);
1703 /*Why? cson_value_add_reference(colNamesV) avoids an ownership problem*/;
1704 colNames = cson_value_get_array(colNamesV);
1705 assert(NULL != colNames);
1706 }
1707 row = cson_sqlite3_row_to_object2(pStmt->pStmt, colNames);
1708 if(!row && !warnMsg){
@@ -1709,14 +1709,14 @@
1709 warnMsg = "Could not convert at least one result row to JSON.";
1710 continue;
1711 }
1712 if( 0 != cson_array_append(a, row) ){
1713 cson_value_free(row);
 
1714 if(pTgt != a) {
1715 cson_free_array(a);
1716 }
1717 assert( 0 && "Alloc error.");
1718 return NULL;
1719 }
1720 }
1721 cson_value_free(colNamesV);
1722 if(warnMsg){
1723
--- src/json_detail.h
+++ src/json_detail.h
@@ -172,10 +172,13 @@
172172
** <0 = CLI only, >0 = HTTP only, 0==both
173173
**
174174
** Now that we can simulate POST in CLI mode, the distinction
175175
** between them has disappeared in most (or all) cases, so 0 is the
176176
** the standard value.
177
+ **
178
+ ** 201207: this is not needed any more. We can get rid of it. Or
179
+ ** keep it around in case it becomes useful again at some point.
177180
*/
178181
char runMode;
179182
} JsonPageDef;
180183
181184
/*
@@ -212,26 +215,10 @@
212215
** set in that case, so the caller must check that or pass it on up
213216
** the dispatch chain).
214217
*/
215218
cson_value * json_page_dispatch_helper(JsonPageDef const * pages);
216219
217
-/*
218
-** Implements the /json/wiki family of pages/commands.
219
-**
220
-*/
221
-cson_value * json_page_wiki();
222
-
223
-/*
224
-** Implements /json/timeline/wiki and /json/wiki/timeline.
225
-*/
226
-cson_value * json_timeline_wiki();
227
-
228
-/*
229
-** Implements /json/timeline family of functions.
230
-*/
231
-cson_value * json_page_timeline();
232
-
233220
/*
234221
** Convenience wrapper around cson_value_new_string().
235222
** Returns NULL if str is NULL or on allocation error.
236223
*/
237224
cson_value * json_new_string( char const * str );
238225
--- src/json_detail.h
+++ src/json_detail.h
@@ -172,10 +172,13 @@
172 ** <0 = CLI only, >0 = HTTP only, 0==both
173 **
174 ** Now that we can simulate POST in CLI mode, the distinction
175 ** between them has disappeared in most (or all) cases, so 0 is the
176 ** the standard value.
 
 
 
177 */
178 char runMode;
179 } JsonPageDef;
180
181 /*
@@ -212,26 +215,10 @@
212 ** set in that case, so the caller must check that or pass it on up
213 ** the dispatch chain).
214 */
215 cson_value * json_page_dispatch_helper(JsonPageDef const * pages);
216
217 /*
218 ** Implements the /json/wiki family of pages/commands.
219 **
220 */
221 cson_value * json_page_wiki();
222
223 /*
224 ** Implements /json/timeline/wiki and /json/wiki/timeline.
225 */
226 cson_value * json_timeline_wiki();
227
228 /*
229 ** Implements /json/timeline family of functions.
230 */
231 cson_value * json_page_timeline();
232
233 /*
234 ** Convenience wrapper around cson_value_new_string().
235 ** Returns NULL if str is NULL or on allocation error.
236 */
237 cson_value * json_new_string( char const * str );
238
--- src/json_detail.h
+++ src/json_detail.h
@@ -172,10 +172,13 @@
172 ** <0 = CLI only, >0 = HTTP only, 0==both
173 **
174 ** Now that we can simulate POST in CLI mode, the distinction
175 ** between them has disappeared in most (or all) cases, so 0 is the
176 ** the standard value.
177 **
178 ** 201207: this is not needed any more. We can get rid of it. Or
179 ** keep it around in case it becomes useful again at some point.
180 */
181 char runMode;
182 } JsonPageDef;
183
184 /*
@@ -212,26 +215,10 @@
215 ** set in that case, so the caller must check that or pass it on up
216 ** the dispatch chain).
217 */
218 cson_value * json_page_dispatch_helper(JsonPageDef const * pages);
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220 /*
221 ** Convenience wrapper around cson_value_new_string().
222 ** Returns NULL if str is NULL or on allocation error.
223 */
224 cson_value * json_new_string( char const * str );
225
--- src/json_report.c
+++ src/json_report.c
@@ -51,11 +51,11 @@
5151
if(!g.perm.RdTkt && !g.perm.NewTkt ){
5252
json_set_err(FSL_JSON_E_DENIED,
5353
"Requires 'r' or 'n' permissions.");
5454
return NULL;
5555
}
56
- return json_page_dispatch_helper(&JsonPageDefs_Report[0]);
56
+ return json_page_dispatch_helper(JsonPageDefs_Report);
5757
}
5858
5959
/*
6060
** Searches the environment for a "report" parameter
6161
** (CLI: -report/-r #).
@@ -249,15 +249,15 @@
249249
250250
error:
251251
assert(0 != g.json.resultCode);
252252
cson_value_free( cson_object_value(pay) );
253253
pay = NULL;
254
- end:
254
+ end:
255255
256256
return pay ? cson_object_value(pay) : NULL;
257257
258258
}
259259
260260
static cson_value * json_report_save(){
261261
return NULL;
262262
}
263263
#endif /* FOSSIL_ENABLE_JSON */
264264
--- src/json_report.c
+++ src/json_report.c
@@ -51,11 +51,11 @@
51 if(!g.perm.RdTkt && !g.perm.NewTkt ){
52 json_set_err(FSL_JSON_E_DENIED,
53 "Requires 'r' or 'n' permissions.");
54 return NULL;
55 }
56 return json_page_dispatch_helper(&JsonPageDefs_Report[0]);
57 }
58
59 /*
60 ** Searches the environment for a "report" parameter
61 ** (CLI: -report/-r #).
@@ -249,15 +249,15 @@
249
250 error:
251 assert(0 != g.json.resultCode);
252 cson_value_free( cson_object_value(pay) );
253 pay = NULL;
254 end:
255
256 return pay ? cson_object_value(pay) : NULL;
257
258 }
259
260 static cson_value * json_report_save(){
261 return NULL;
262 }
263 #endif /* FOSSIL_ENABLE_JSON */
264
--- src/json_report.c
+++ src/json_report.c
@@ -51,11 +51,11 @@
51 if(!g.perm.RdTkt && !g.perm.NewTkt ){
52 json_set_err(FSL_JSON_E_DENIED,
53 "Requires 'r' or 'n' permissions.");
54 return NULL;
55 }
56 return json_page_dispatch_helper(JsonPageDefs_Report);
57 }
58
59 /*
60 ** Searches the environment for a "report" parameter
61 ** (CLI: -report/-r #).
@@ -249,15 +249,15 @@
249
250 error:
251 assert(0 != g.json.resultCode);
252 cson_value_free( cson_object_value(pay) );
253 pay = NULL;
254 end:
255
256 return pay ? cson_object_value(pay) : NULL;
257
258 }
259
260 static cson_value * json_report_save(){
261 return NULL;
262 }
263 #endif /* FOSSIL_ENABLE_JSON */
264
+3 -1
--- src/json_user.c
+++ src/json_user.c
@@ -356,11 +356,11 @@
356356
#endif
357357
db_prepare(&q, "%s", blob_str(&sql));
358358
db_exec(&q);
359359
db_finalize(&q);
360360
#if TRY_LOGIN_GROUP
361
- if( zPW || forceLogout ){
361
+ if( zPW || cson_value_get_bool(forceLogout) ){
362362
Blob groupSql = empty_blob;
363363
char * zErr = NULL;
364364
blob_appendf(&groupSql,
365365
"INSERT INTO user(login)"
366366
" SELECT %Q WHERE NOT EXISTS(SELECT 1 FROM user WHERE login=%Q);",
@@ -403,17 +403,19 @@
403403
char const * str = NULL;
404404
char b = -1;
405405
int i = -1;
406406
int uid = -1;
407407
cson_value * payload = NULL;
408
+ /* String properties... */
408409
#define PROP(LK,SK) str = json_find_option_cstr(LK,NULL,SK); \
409410
if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0
410411
PROP("name","n");
411412
PROP("password","p");
412413
PROP("info","i");
413414
PROP("capabilities","c");
414415
#undef PROP
416
+ /* Boolean properties... */
415417
#define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \
416418
if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0
417419
PROP("forceLogout",-1);
418420
#undef PROP
419421
420422
--- src/json_user.c
+++ src/json_user.c
@@ -356,11 +356,11 @@
356 #endif
357 db_prepare(&q, "%s", blob_str(&sql));
358 db_exec(&q);
359 db_finalize(&q);
360 #if TRY_LOGIN_GROUP
361 if( zPW || forceLogout ){
362 Blob groupSql = empty_blob;
363 char * zErr = NULL;
364 blob_appendf(&groupSql,
365 "INSERT INTO user(login)"
366 " SELECT %Q WHERE NOT EXISTS(SELECT 1 FROM user WHERE login=%Q);",
@@ -403,17 +403,19 @@
403 char const * str = NULL;
404 char b = -1;
405 int i = -1;
406 int uid = -1;
407 cson_value * payload = NULL;
 
408 #define PROP(LK,SK) str = json_find_option_cstr(LK,NULL,SK); \
409 if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0
410 PROP("name","n");
411 PROP("password","p");
412 PROP("info","i");
413 PROP("capabilities","c");
414 #undef PROP
 
415 #define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \
416 if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0
417 PROP("forceLogout",-1);
418 #undef PROP
419
420
--- src/json_user.c
+++ src/json_user.c
@@ -356,11 +356,11 @@
356 #endif
357 db_prepare(&q, "%s", blob_str(&sql));
358 db_exec(&q);
359 db_finalize(&q);
360 #if TRY_LOGIN_GROUP
361 if( zPW || cson_value_get_bool(forceLogout) ){
362 Blob groupSql = empty_blob;
363 char * zErr = NULL;
364 blob_appendf(&groupSql,
365 "INSERT INTO user(login)"
366 " SELECT %Q WHERE NOT EXISTS(SELECT 1 FROM user WHERE login=%Q);",
@@ -403,17 +403,19 @@
403 char const * str = NULL;
404 char b = -1;
405 int i = -1;
406 int uid = -1;
407 cson_value * payload = NULL;
408 /* String properties... */
409 #define PROP(LK,SK) str = json_find_option_cstr(LK,NULL,SK); \
410 if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0
411 PROP("name","n");
412 PROP("password","p");
413 PROP("info","i");
414 PROP("capabilities","c");
415 #undef PROP
416 /* Boolean properties... */
417 #define PROP(LK,DFLT) b = json_find_option_bool(LK,NULL,NULL,DFLT); \
418 if(DFLT!=b){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0
419 PROP("forceLogout",-1);
420 #undef PROP
421
422
+7 -3
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -1,8 +1,8 @@
11
#ifdef FOSSIL_ENABLE_JSON
22
/*
3
-** Copyright (c) 2011 D. Richard Hipp
3
+** Copyright (c) 2011-12 D. Richard Hipp
44
**
55
** This program is free software; you can redistribute it and/or
66
** modify it under the terms of the Simplified BSD License (also
77
** known as the "2-Clause License" or "FreeBSD License".)
88
**
@@ -48,13 +48,18 @@
4848
/*
4949
** Implements the /json/wiki family of pages/commands.
5050
**
5151
*/
5252
cson_value * json_page_wiki(){
53
- return json_page_dispatch_helper(&JsonPageDefs_Wiki[0]);
53
+ return json_page_dispatch_helper(JsonPageDefs_Wiki);
5454
}
5555
56
+/*
57
+** Returns the UUID for the given wiki blob RID, or NULL if not
58
+** found. The returned string is allocated via db_text() and must be
59
+** free()d by the caller.
60
+*/
5661
char * json_wiki_get_uuid_for_rid( int rid )
5762
{
5863
return db_text(NULL,
5964
"SELECT b.uuid FROM tag t, tagxref x, blob b"
6065
" WHERE x.tagid=t.tagid AND t.tagname GLOB 'wiki-*' "
@@ -83,11 +88,10 @@
8388
json_set_err( FSL_JSON_E_UNKNOWN,
8489
"Error reading wiki page from manifest (rid=%d).",
8590
rid );
8691
return NULL;
8792
}else{
88
- /*char const * zFormat = NULL;*/
8993
unsigned int len = 0;
9094
cson_object * pay = cson_new_object();
9195
char const * zBody = pWiki->zWiki;
9296
char const * zFormat = NULL;
9397
char * zUuid = json_wiki_get_uuid_for_rid(rid);
9498
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -1,8 +1,8 @@
1 #ifdef FOSSIL_ENABLE_JSON
2 /*
3 ** Copyright (c) 2011 D. Richard Hipp
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the Simplified BSD License (also
7 ** known as the "2-Clause License" or "FreeBSD License".)
8 **
@@ -48,13 +48,18 @@
48 /*
49 ** Implements the /json/wiki family of pages/commands.
50 **
51 */
52 cson_value * json_page_wiki(){
53 return json_page_dispatch_helper(&JsonPageDefs_Wiki[0]);
54 }
55
 
 
 
 
 
56 char * json_wiki_get_uuid_for_rid( int rid )
57 {
58 return db_text(NULL,
59 "SELECT b.uuid FROM tag t, tagxref x, blob b"
60 " WHERE x.tagid=t.tagid AND t.tagname GLOB 'wiki-*' "
@@ -83,11 +88,10 @@
83 json_set_err( FSL_JSON_E_UNKNOWN,
84 "Error reading wiki page from manifest (rid=%d).",
85 rid );
86 return NULL;
87 }else{
88 /*char const * zFormat = NULL;*/
89 unsigned int len = 0;
90 cson_object * pay = cson_new_object();
91 char const * zBody = pWiki->zWiki;
92 char const * zFormat = NULL;
93 char * zUuid = json_wiki_get_uuid_for_rid(rid);
94
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -1,8 +1,8 @@
1 #ifdef FOSSIL_ENABLE_JSON
2 /*
3 ** Copyright (c) 2011-12 D. Richard Hipp
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the Simplified BSD License (also
7 ** known as the "2-Clause License" or "FreeBSD License".)
8 **
@@ -48,13 +48,18 @@
48 /*
49 ** Implements the /json/wiki family of pages/commands.
50 **
51 */
52 cson_value * json_page_wiki(){
53 return json_page_dispatch_helper(JsonPageDefs_Wiki);
54 }
55
56 /*
57 ** Returns the UUID for the given wiki blob RID, or NULL if not
58 ** found. The returned string is allocated via db_text() and must be
59 ** free()d by the caller.
60 */
61 char * json_wiki_get_uuid_for_rid( int rid )
62 {
63 return db_text(NULL,
64 "SELECT b.uuid FROM tag t, tagxref x, blob b"
65 " WHERE x.tagid=t.tagid AND t.tagname GLOB 'wiki-*' "
@@ -83,11 +88,10 @@
88 json_set_err( FSL_JSON_E_UNKNOWN,
89 "Error reading wiki page from manifest (rid=%d).",
90 rid );
91 return NULL;
92 }else{
 
93 unsigned int len = 0;
94 cson_object * pay = cson_new_object();
95 char const * zBody = pWiki->zWiki;
96 char const * zFormat = NULL;
97 char * zUuid = json_wiki_get_uuid_for_rid(rid);
98

Keyboard Shortcuts

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