Fossil SCM

Cleaned up wiki formatting code a bit. Added wiki uuid to /json/wiki/get response payload.

stephan 2011-10-01 04:03 UTC json
Commit 3f512ca41b5aeb3392814ec16496566f22f66083
1 file changed +29 -14
+29 -14
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -43,12 +43,13 @@
4343
static cson_value * json_wiki_get(){
4444
int rid;
4545
Manifest *pWiki = 0;
4646
char const * zBody = NULL;
4747
char const * zPageName;
48
- char doParse = 0/*not yet implemented*/;
4948
char const * zFormat = NULL;
49
+ char * zUuid = NULL;
50
+ Stmt q;
5051
if( !g.perm.RdWiki ){
5152
g.json.resultCode = FSL_JSON_E_DENIED;
5253
return NULL;
5354
}
5455
zPageName = g.isHTTP
@@ -63,38 +64,52 @@
6364
? json_getenv_cstr("format")
6465
: find_option("format","f",1);
6566
if(!zFormat || !*zFormat){
6667
zFormat = "raw";
6768
}
69
+ if( 'r' != *zFormat ){
70
+ zFormat = "html";
71
+ }
72
+ db_prepare(&q,
73
+ "SELECT x.rid, b.uuid FROM tag t, tagxref x, blob b"
74
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
75
+ " AND b.rid=x.rid"
76
+ " ORDER BY x.mtime DESC LIMIT 1",
77
+ zPageName
78
+ );
79
+ if( (SQLITE_ROW != db_step(&q)) ){
80
+ manifest_destroy(pWiki);
81
+ g.json.resultCode = FSL_JSON_E_UNKNOWN;
82
+ return NULL;
83
+ }
84
+ rid = db_column_int(&q,0);
85
+ zUuid = mprintf("%s",(char const *)db_column_text(&q,1));
86
+ db_finalize(&q);
6887
69
- rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
70
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
71
- " ORDER BY x.mtime DESC LIMIT 1",
72
- zPageName
73
- );
7488
if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
7589
zBody = pWiki->zWiki;
7690
}
7791
if( zBody==0 ){
7892
manifest_destroy(pWiki);
93
+ free(zUuid);
7994
g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
8095
return NULL;
81
- }else{
96
+ }
97
+
98
+ {
8299
unsigned int len;
83100
cson_value * payV = cson_value_new_object();
84101
cson_object * pay = cson_value_get_object(payV);
85102
cson_object_set(pay,"name",json_new_string(zPageName));
86
- cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
87
- /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
88
- ;
103
+ cson_object_set(pay,"uuid",json_new_string(zUuid));
104
+ free(zUuid);
105
+ zUuid = NULL;
89106
cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
90107
cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
91108
cson_object_set(pay,FossilJsonKeys.timestamp, json_julian_to_timestamp(pWiki->rDate));
92
- cson_object_set(pay,"format",json_new_string(zFormat));
93
- cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
94
- doParse = ('h'==*zFormat) ? 1 : 0;
95
- if( doParse ){
109
+ cson_object_set(pay,"contentFormat",json_new_string(zFormat));
110
+ if( ('h'==*zFormat) ){
96111
Blob content = empty_blob;
97112
Blob raw = empty_blob;
98113
blob_append(&raw,zBody,-1);
99114
wiki_convert(&raw,&content,0);
100115
len = strlen(zBody);
101116
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -43,12 +43,13 @@
43 static cson_value * json_wiki_get(){
44 int rid;
45 Manifest *pWiki = 0;
46 char const * zBody = NULL;
47 char const * zPageName;
48 char doParse = 0/*not yet implemented*/;
49 char const * zFormat = NULL;
 
 
50 if( !g.perm.RdWiki ){
51 g.json.resultCode = FSL_JSON_E_DENIED;
52 return NULL;
53 }
54 zPageName = g.isHTTP
@@ -63,38 +64,52 @@
63 ? json_getenv_cstr("format")
64 : find_option("format","f",1);
65 if(!zFormat || !*zFormat){
66 zFormat = "raw";
67 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
70 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
71 " ORDER BY x.mtime DESC LIMIT 1",
72 zPageName
73 );
74 if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
75 zBody = pWiki->zWiki;
76 }
77 if( zBody==0 ){
78 manifest_destroy(pWiki);
 
79 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
80 return NULL;
81 }else{
 
 
82 unsigned int len;
83 cson_value * payV = cson_value_new_object();
84 cson_object * pay = cson_value_get_object(payV);
85 cson_object_set(pay,"name",json_new_string(zPageName));
86 cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
87 /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
88 ;
89 cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
90 cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
91 cson_object_set(pay,FossilJsonKeys.timestamp, json_julian_to_timestamp(pWiki->rDate));
92 cson_object_set(pay,"format",json_new_string(zFormat));
93 cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
94 doParse = ('h'==*zFormat) ? 1 : 0;
95 if( doParse ){
96 Blob content = empty_blob;
97 Blob raw = empty_blob;
98 blob_append(&raw,zBody,-1);
99 wiki_convert(&raw,&content,0);
100 len = strlen(zBody);
101
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -43,12 +43,13 @@
43 static cson_value * json_wiki_get(){
44 int rid;
45 Manifest *pWiki = 0;
46 char const * zBody = NULL;
47 char const * zPageName;
 
48 char const * zFormat = NULL;
49 char * zUuid = NULL;
50 Stmt q;
51 if( !g.perm.RdWiki ){
52 g.json.resultCode = FSL_JSON_E_DENIED;
53 return NULL;
54 }
55 zPageName = g.isHTTP
@@ -63,38 +64,52 @@
64 ? json_getenv_cstr("format")
65 : find_option("format","f",1);
66 if(!zFormat || !*zFormat){
67 zFormat = "raw";
68 }
69 if( 'r' != *zFormat ){
70 zFormat = "html";
71 }
72 db_prepare(&q,
73 "SELECT x.rid, b.uuid FROM tag t, tagxref x, blob b"
74 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q' "
75 " AND b.rid=x.rid"
76 " ORDER BY x.mtime DESC LIMIT 1",
77 zPageName
78 );
79 if( (SQLITE_ROW != db_step(&q)) ){
80 manifest_destroy(pWiki);
81 g.json.resultCode = FSL_JSON_E_UNKNOWN;
82 return NULL;
83 }
84 rid = db_column_int(&q,0);
85 zUuid = mprintf("%s",(char const *)db_column_text(&q,1));
86 db_finalize(&q);
87
 
 
 
 
 
88 if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
89 zBody = pWiki->zWiki;
90 }
91 if( zBody==0 ){
92 manifest_destroy(pWiki);
93 free(zUuid);
94 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
95 return NULL;
96 }
97
98 {
99 unsigned int len;
100 cson_value * payV = cson_value_new_object();
101 cson_object * pay = cson_value_get_object(payV);
102 cson_object_set(pay,"name",json_new_string(zPageName));
103 cson_object_set(pay,"uuid",json_new_string(zUuid));
104 free(zUuid);
105 zUuid = NULL;
106 cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
107 cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
108 cson_object_set(pay,FossilJsonKeys.timestamp, json_julian_to_timestamp(pWiki->rDate));
109 cson_object_set(pay,"contentFormat",json_new_string(zFormat));
110 if( ('h'==*zFormat) ){
 
 
111 Blob content = empty_blob;
112 Blob raw = empty_blob;
113 blob_append(&raw,zBody,-1);
114 wiki_convert(&raw,&content,0);
115 len = strlen(zBody);
116

Keyboard Shortcuts

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