Fossil SCM
Cleaned up wiki formatting code a bit. Added wiki uuid to /json/wiki/get response payload.
Commit
3f512ca41b5aeb3392814ec16496566f22f66083
Parent
c990e7ec25cbf97…
1 file changed
+29
-14
+29
-14
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -43,12 +43,13 @@ | ||
| 43 | 43 | static cson_value * json_wiki_get(){ |
| 44 | 44 | int rid; |
| 45 | 45 | Manifest *pWiki = 0; |
| 46 | 46 | char const * zBody = NULL; |
| 47 | 47 | char const * zPageName; |
| 48 | - char doParse = 0/*not yet implemented*/; | |
| 49 | 48 | char const * zFormat = NULL; |
| 49 | + char * zUuid = NULL; | |
| 50 | + Stmt q; | |
| 50 | 51 | if( !g.perm.RdWiki ){ |
| 51 | 52 | g.json.resultCode = FSL_JSON_E_DENIED; |
| 52 | 53 | return NULL; |
| 53 | 54 | } |
| 54 | 55 | zPageName = g.isHTTP |
| @@ -63,38 +64,52 @@ | ||
| 63 | 64 | ? json_getenv_cstr("format") |
| 64 | 65 | : find_option("format","f",1); |
| 65 | 66 | if(!zFormat || !*zFormat){ |
| 66 | 67 | zFormat = "raw"; |
| 67 | 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); | |
| 68 | 87 | |
| 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 | 88 | if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){ |
| 75 | 89 | zBody = pWiki->zWiki; |
| 76 | 90 | } |
| 77 | 91 | if( zBody==0 ){ |
| 78 | 92 | manifest_destroy(pWiki); |
| 93 | + free(zUuid); | |
| 79 | 94 | g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND; |
| 80 | 95 | return NULL; |
| 81 | - }else{ | |
| 96 | + } | |
| 97 | + | |
| 98 | + { | |
| 82 | 99 | unsigned int len; |
| 83 | 100 | cson_value * payV = cson_value_new_object(); |
| 84 | 101 | cson_object * pay = cson_value_get_object(payV); |
| 85 | 102 | 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; | |
| 89 | 106 | cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid)); |
| 90 | 107 | cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser)); |
| 91 | 108 | 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) ){ | |
| 96 | 111 | Blob content = empty_blob; |
| 97 | 112 | Blob raw = empty_blob; |
| 98 | 113 | blob_append(&raw,zBody,-1); |
| 99 | 114 | wiki_convert(&raw,&content,0); |
| 100 | 115 | len = strlen(zBody); |
| 101 | 116 |
| --- 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 |