Fossil SCM

Added format=raw|html to /json/wiki/get.

stephan 2011-10-01 03:37 UTC json
Commit c990e7ec25cbf970630e34dad2e405a3864e332e
1 file changed +29 -4
+29 -4
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -44,11 +44,11 @@
4444
int rid;
4545
Manifest *pWiki = 0;
4646
char const * zBody = NULL;
4747
char const * zPageName;
4848
char doParse = 0/*not yet implemented*/;
49
-
49
+ char const * zFormat = NULL;
5050
if( !g.perm.RdWiki ){
5151
g.json.resultCode = FSL_JSON_E_DENIED;
5252
return NULL;
5353
}
5454
zPageName = g.isHTTP
@@ -56,10 +56,18 @@
5656
: find_option("page","p",1);
5757
if(!zPageName||!*zPageName){
5858
g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
5959
return NULL;
6060
}
61
+
62
+ zFormat = g.isHTTP
63
+ ? json_getenv_cstr("format")
64
+ : find_option("format","f",1);
65
+ if(!zFormat || !*zFormat){
66
+ zFormat = "raw";
67
+ }
68
+
6169
rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
6270
" WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
6371
" ORDER BY x.mtime DESC LIMIT 1",
6472
zPageName
6573
);
@@ -69,23 +77,40 @@
6977
if( zBody==0 ){
7078
manifest_destroy(pWiki);
7179
g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
7280
return NULL;
7381
}else{
74
- unsigned int const len = strlen(zBody);
82
+ unsigned int len;
7583
cson_value * payV = cson_value_new_object();
7684
cson_object * pay = cson_value_get_object(payV);
7785
cson_object_set(pay,"name",json_new_string(zPageName));
7886
cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
7987
/*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
8088
;
8189
cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
8290
cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
8391
cson_object_set(pay,FossilJsonKeys.timestamp, json_julian_to_timestamp(pWiki->rDate));
84
- cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
92
+ cson_object_set(pay,"format",json_new_string(zFormat));
8593
cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
86
- cson_object_set(pay,"content",cson_value_new_string(zBody,len));
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
+ len = (unsigned int)blob_size(&content);
102
+ cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
103
+ cson_object_set(pay,"content",
104
+ cson_value_new_string(blob_buffer(&content),len));
105
+ blob_reset(&content);
106
+ blob_reset(&raw);
107
+ }else{
108
+ len = strlen(zBody);
109
+ cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
110
+ cson_object_set(pay,"content",cson_value_new_string(zBody,len));
111
+ }
87112
/*TODO: add 'T' (tag) fields*/
88113
/*TODO: add the 'A' card (file attachment) entries?*/
89114
manifest_destroy(pWiki);
90115
return payV;
91116
}
92117
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -44,11 +44,11 @@
44 int rid;
45 Manifest *pWiki = 0;
46 char const * zBody = NULL;
47 char const * zPageName;
48 char doParse = 0/*not yet implemented*/;
49
50 if( !g.perm.RdWiki ){
51 g.json.resultCode = FSL_JSON_E_DENIED;
52 return NULL;
53 }
54 zPageName = g.isHTTP
@@ -56,10 +56,18 @@
56 : find_option("page","p",1);
57 if(!zPageName||!*zPageName){
58 g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
59 return NULL;
60 }
 
 
 
 
 
 
 
 
61 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
62 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
63 " ORDER BY x.mtime DESC LIMIT 1",
64 zPageName
65 );
@@ -69,23 +77,40 @@
69 if( zBody==0 ){
70 manifest_destroy(pWiki);
71 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
72 return NULL;
73 }else{
74 unsigned int const len = strlen(zBody);
75 cson_value * payV = cson_value_new_object();
76 cson_object * pay = cson_value_get_object(payV);
77 cson_object_set(pay,"name",json_new_string(zPageName));
78 cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
79 /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
80 ;
81 cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
82 cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
83 cson_object_set(pay,FossilJsonKeys.timestamp, json_julian_to_timestamp(pWiki->rDate));
84 cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
85 cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
86 cson_object_set(pay,"content",cson_value_new_string(zBody,len));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87 /*TODO: add 'T' (tag) fields*/
88 /*TODO: add the 'A' card (file attachment) entries?*/
89 manifest_destroy(pWiki);
90 return payV;
91 }
92
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -44,11 +44,11 @@
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
@@ -56,10 +56,18 @@
56 : find_option("page","p",1);
57 if(!zPageName||!*zPageName){
58 g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
59 return NULL;
60 }
61
62 zFormat = g.isHTTP
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 );
@@ -69,23 +77,40 @@
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 len = (unsigned int)blob_size(&content);
102 cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
103 cson_object_set(pay,"content",
104 cson_value_new_string(blob_buffer(&content),len));
105 blob_reset(&content);
106 blob_reset(&raw);
107 }else{
108 len = strlen(zBody);
109 cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
110 cson_object_set(pay,"content",cson_value_new_string(zBody,len));
111 }
112 /*TODO: add 'T' (tag) fields*/
113 /*TODO: add the 'A' card (file attachment) entries?*/
114 manifest_destroy(pWiki);
115 return payV;
116 }
117

Keyboard Shortcuts

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