Fossil SCM
Added format=raw|html to /json/wiki/get.
Commit
c990e7ec25cbf970630e34dad2e405a3864e332e
Parent
3bdae54cae52a4d…
1 file changed
+29
-4
+29
-4
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -44,11 +44,11 @@ | ||
| 44 | 44 | int rid; |
| 45 | 45 | Manifest *pWiki = 0; |
| 46 | 46 | char const * zBody = NULL; |
| 47 | 47 | char const * zPageName; |
| 48 | 48 | char doParse = 0/*not yet implemented*/; |
| 49 | - | |
| 49 | + char const * zFormat = NULL; | |
| 50 | 50 | if( !g.perm.RdWiki ){ |
| 51 | 51 | g.json.resultCode = FSL_JSON_E_DENIED; |
| 52 | 52 | return NULL; |
| 53 | 53 | } |
| 54 | 54 | zPageName = g.isHTTP |
| @@ -56,10 +56,18 @@ | ||
| 56 | 56 | : find_option("page","p",1); |
| 57 | 57 | if(!zPageName||!*zPageName){ |
| 58 | 58 | g.json.resultCode = FSL_JSON_E_MISSING_ARGS; |
| 59 | 59 | return NULL; |
| 60 | 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 | + | |
| 61 | 69 | rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
| 62 | 70 | " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" |
| 63 | 71 | " ORDER BY x.mtime DESC LIMIT 1", |
| 64 | 72 | zPageName |
| 65 | 73 | ); |
| @@ -69,23 +77,40 @@ | ||
| 69 | 77 | if( zBody==0 ){ |
| 70 | 78 | manifest_destroy(pWiki); |
| 71 | 79 | g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND; |
| 72 | 80 | return NULL; |
| 73 | 81 | }else{ |
| 74 | - unsigned int const len = strlen(zBody); | |
| 82 | + unsigned int len; | |
| 75 | 83 | cson_value * payV = cson_value_new_object(); |
| 76 | 84 | cson_object * pay = cson_value_get_object(payV); |
| 77 | 85 | cson_object_set(pay,"name",json_new_string(zPageName)); |
| 78 | 86 | cson_object_set(pay,"version",json_new_string(pWiki->zBaseline)) |
| 79 | 87 | /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/ |
| 80 | 88 | ; |
| 81 | 89 | cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid)); |
| 82 | 90 | cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser)); |
| 83 | 91 | 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)); | |
| 85 | 93 | 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 | + } | |
| 87 | 112 | /*TODO: add 'T' (tag) fields*/ |
| 88 | 113 | /*TODO: add the 'A' card (file attachment) entries?*/ |
| 89 | 114 | manifest_destroy(pWiki); |
| 90 | 115 | return payV; |
| 91 | 116 | } |
| 92 | 117 |
| --- 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 |