Fossil SCM

Added /json/wiki/preview.

stephan 2012-03-10 17:48 trunk
Commit 0165fa184e58fa86006628de22b23f150144dc00
1 file changed +32
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -24,10 +24,11 @@
2424
#endif
2525
2626
static cson_value * json_wiki_create();
2727
static cson_value * json_wiki_get();
2828
static cson_value * json_wiki_list();
29
+static cson_value * json_wiki_preview();
2930
static cson_value * json_wiki_save();
3031
static cson_value * json_wiki_diff();
3132
/*
3233
** Mapping of /json/wiki/XXX commands/paths to callbacks.
3334
*/
@@ -34,10 +35,11 @@
3435
static const JsonPageDef JsonPageDefs_Wiki[] = {
3536
{"create", json_wiki_create, 0},
3637
{"diff", json_wiki_diff, 0},
3738
{"get", json_wiki_get, 0},
3839
{"list", json_wiki_list, 0},
40
+{"preview", json_wiki_preview, 0},
3941
{"save", json_wiki_save, 0},
4042
{"timeline", json_timeline_wiki,0},
4143
/* Last entry MUST have a NULL name. */
4244
{NULL,NULL,0}
4345
};
@@ -261,10 +263,40 @@
261263
*/
262264
263265
contentFormat = json_wiki_get_content_format_flag(contentFormat);
264266
return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
265267
}
268
+
269
+/*
270
+** Implementation of /json/wiki/preview.
271
+**
272
+*/
273
+static cson_value * json_wiki_preview(){
274
+ char const * zPageName;
275
+ char const * zContent = NULL;
276
+ cson_value * pay = NULL;
277
+ Blob contentOrig = empty_blob;
278
+ Blob contentHtml = empty_blob;
279
+ if( !g.perm.WrWiki ){
280
+ json_set_err(FSL_JSON_E_DENIED,
281
+ "Requires 'k' access.");
282
+ return NULL;
283
+ }
284
+ zContent = cson_string_cstr(cson_value_get_string(g.json.reqPayload.v));
285
+ if(!zContent) {
286
+ json_set_err(FSL_JSON_E_MISSING_ARGS,
287
+ "The 'payload' property must be a string containing the wiki code to preview.");
288
+ return NULL;
289
+ }
290
+ blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(cson_value_get_string(g.json.reqPayload.v)) );
291
+ wiki_convert( &contentOrig, &contentHtml, 0 );
292
+ blob_reset( &contentOrig );
293
+ pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml));
294
+ blob_reset( &contentHtml );
295
+ return pay;
296
+}
297
+
266298
267299
/*
268300
** Internal impl of /wiki/save and /wiki/create. If createMode is 0
269301
** and the page already exists then a
270302
** FSL_JSON_E_RESOURCE_ALREADY_EXISTS error is triggered. If
271303
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -24,10 +24,11 @@
24 #endif
25
26 static cson_value * json_wiki_create();
27 static cson_value * json_wiki_get();
28 static cson_value * json_wiki_list();
 
29 static cson_value * json_wiki_save();
30 static cson_value * json_wiki_diff();
31 /*
32 ** Mapping of /json/wiki/XXX commands/paths to callbacks.
33 */
@@ -34,10 +35,11 @@
34 static const JsonPageDef JsonPageDefs_Wiki[] = {
35 {"create", json_wiki_create, 0},
36 {"diff", json_wiki_diff, 0},
37 {"get", json_wiki_get, 0},
38 {"list", json_wiki_list, 0},
 
39 {"save", json_wiki_save, 0},
40 {"timeline", json_timeline_wiki,0},
41 /* Last entry MUST have a NULL name. */
42 {NULL,NULL,0}
43 };
@@ -261,10 +263,40 @@
261 */
262
263 contentFormat = json_wiki_get_content_format_flag(contentFormat);
264 return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
265 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
267 /*
268 ** Internal impl of /wiki/save and /wiki/create. If createMode is 0
269 ** and the page already exists then a
270 ** FSL_JSON_E_RESOURCE_ALREADY_EXISTS error is triggered. If
271
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -24,10 +24,11 @@
24 #endif
25
26 static cson_value * json_wiki_create();
27 static cson_value * json_wiki_get();
28 static cson_value * json_wiki_list();
29 static cson_value * json_wiki_preview();
30 static cson_value * json_wiki_save();
31 static cson_value * json_wiki_diff();
32 /*
33 ** Mapping of /json/wiki/XXX commands/paths to callbacks.
34 */
@@ -34,10 +35,11 @@
35 static const JsonPageDef JsonPageDefs_Wiki[] = {
36 {"create", json_wiki_create, 0},
37 {"diff", json_wiki_diff, 0},
38 {"get", json_wiki_get, 0},
39 {"list", json_wiki_list, 0},
40 {"preview", json_wiki_preview, 0},
41 {"save", json_wiki_save, 0},
42 {"timeline", json_timeline_wiki,0},
43 /* Last entry MUST have a NULL name. */
44 {NULL,NULL,0}
45 };
@@ -261,10 +263,40 @@
263 */
264
265 contentFormat = json_wiki_get_content_format_flag(contentFormat);
266 return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
267 }
268
269 /*
270 ** Implementation of /json/wiki/preview.
271 **
272 */
273 static cson_value * json_wiki_preview(){
274 char const * zPageName;
275 char const * zContent = NULL;
276 cson_value * pay = NULL;
277 Blob contentOrig = empty_blob;
278 Blob contentHtml = empty_blob;
279 if( !g.perm.WrWiki ){
280 json_set_err(FSL_JSON_E_DENIED,
281 "Requires 'k' access.");
282 return NULL;
283 }
284 zContent = cson_string_cstr(cson_value_get_string(g.json.reqPayload.v));
285 if(!zContent) {
286 json_set_err(FSL_JSON_E_MISSING_ARGS,
287 "The 'payload' property must be a string containing the wiki code to preview.");
288 return NULL;
289 }
290 blob_append( &contentOrig, zContent, (int)cson_string_length_bytes(cson_value_get_string(g.json.reqPayload.v)) );
291 wiki_convert( &contentOrig, &contentHtml, 0 );
292 blob_reset( &contentOrig );
293 pay = cson_value_new_string( blob_str(&contentHtml), (unsigned int)blob_size(&contentHtml));
294 blob_reset( &contentHtml );
295 return pay;
296 }
297
298
299 /*
300 ** Internal impl of /wiki/save and /wiki/create. If createMode is 0
301 ** and the page already exists then a
302 ** FSL_JSON_E_RESOURCE_ALREADY_EXISTS error is triggered. If
303

Keyboard Shortcuts

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