Fossil SCM

minor internal refactoring of /json/wiki/get in prep for /json/wiki/preview.

stephan 2012-03-10 16:47 trunk
Commit 73816973fb79ad26ee23fc6919bd98f1cf55f4d4
1 file changed +30 -16
+30 -16
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -186,10 +186,39 @@
186186
else if('n'==*zFormat){
187187
contentFormat = 0;
188188
}
189189
return contentFormat;
190190
}
191
+
192
+/*
193
+** Helper for /json/wiki/get and /json/wiki/preview. At least one of
194
+** zPageName (wiki page name) or zSymname must be set to a
195
+** non-empty/non-NULL value. zSymname takes precedence. On success
196
+** the result of one of json_get_wiki_page_by_rid() or
197
+** json_get_wiki_page_by_name() will be returned (owned by the
198
+** caller). On error g.json's error state is set and NULL is returned.
199
+*/
200
+static cson_value * json_wiki_get_by_name_or_symname(char const * zPageName,
201
+ char const * zSymname,
202
+ char contentFormat ){
203
+ if(!zSymname || !*zSymname){
204
+ return json_get_wiki_page_by_name(zPageName, contentFormat);
205
+ }else{
206
+ int rid = symbolic_name_to_rid( zSymname ? zSymname : zPageName, "w" );
207
+ if(rid<0){
208
+ json_set_err(FSL_JSON_E_AMBIGUOUS_UUID,
209
+ "UUID [%s] is ambiguious.", zSymname);
210
+ return NULL;
211
+ }else if(rid==0){
212
+ json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
213
+ "UUID [%s] does not resolve to a wiki page.", zSymname);
214
+ return NULL;
215
+ }else{
216
+ return json_get_wiki_page_by_rid(rid, contentFormat);
217
+ }
218
+ }
219
+}
191220
192221
/*
193222
** Implementation of /json/wiki/get.
194223
**
195224
*/
@@ -230,26 +259,11 @@
230259
/* TODO: see if we have a page named zPageName. If not, try to resolve
231260
zPageName as a UUID.
232261
*/
233262
234263
contentFormat = json_wiki_get_content_format_flag(contentFormat);
235
- if(!zSymName || !*zSymName){
236
- return json_get_wiki_page_by_name(zPageName, contentFormat);
237
- }else{
238
- int rid = symbolic_name_to_rid( zSymName ? zSymName : zPageName, "w" );
239
- if(rid<0){
240
- json_set_err(FSL_JSON_E_AMBIGUOUS_UUID,
241
- "UUID [%s] is ambiguious.", zSymName);
242
- return NULL;
243
- }else if(rid==0){
244
- json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
245
- "UUID [%s] does not resolve to a wiki page.", zSymName);
246
- return NULL;
247
- }else{
248
- return json_get_wiki_page_by_rid(rid, contentFormat);
249
- }
250
- }
264
+ return json_wiki_get_by_name_or_symname( zPageName, zSymName, contentFormat );
251265
}
252266
253267
/*
254268
** Internal impl of /wiki/save and /wiki/create. If createMode is 0
255269
** and the page already exists then a
256270
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -186,10 +186,39 @@
186 else if('n'==*zFormat){
187 contentFormat = 0;
188 }
189 return contentFormat;
190 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
192 /*
193 ** Implementation of /json/wiki/get.
194 **
195 */
@@ -230,26 +259,11 @@
230 /* TODO: see if we have a page named zPageName. If not, try to resolve
231 zPageName as a UUID.
232 */
233
234 contentFormat = json_wiki_get_content_format_flag(contentFormat);
235 if(!zSymName || !*zSymName){
236 return json_get_wiki_page_by_name(zPageName, contentFormat);
237 }else{
238 int rid = symbolic_name_to_rid( zSymName ? zSymName : zPageName, "w" );
239 if(rid<0){
240 json_set_err(FSL_JSON_E_AMBIGUOUS_UUID,
241 "UUID [%s] is ambiguious.", zSymName);
242 return NULL;
243 }else if(rid==0){
244 json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
245 "UUID [%s] does not resolve to a wiki page.", zSymName);
246 return NULL;
247 }else{
248 return json_get_wiki_page_by_rid(rid, contentFormat);
249 }
250 }
251 }
252
253 /*
254 ** Internal impl of /wiki/save and /wiki/create. If createMode is 0
255 ** and the page already exists then a
256
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -186,10 +186,39 @@
186 else if('n'==*zFormat){
187 contentFormat = 0;
188 }
189 return contentFormat;
190 }
191
192 /*
193 ** Helper for /json/wiki/get and /json/wiki/preview. At least one of
194 ** zPageName (wiki page name) or zSymname must be set to a
195 ** non-empty/non-NULL value. zSymname takes precedence. On success
196 ** the result of one of json_get_wiki_page_by_rid() or
197 ** json_get_wiki_page_by_name() will be returned (owned by the
198 ** caller). On error g.json's error state is set and NULL is returned.
199 */
200 static cson_value * json_wiki_get_by_name_or_symname(char const * zPageName,
201 char const * zSymname,
202 char contentFormat ){
203 if(!zSymname || !*zSymname){
204 return json_get_wiki_page_by_name(zPageName, contentFormat);
205 }else{
206 int rid = symbolic_name_to_rid( zSymname ? zSymname : zPageName, "w" );
207 if(rid<0){
208 json_set_err(FSL_JSON_E_AMBIGUOUS_UUID,
209 "UUID [%s] is ambiguious.", zSymname);
210 return NULL;
211 }else if(rid==0){
212 json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND,
213 "UUID [%s] does not resolve to a wiki page.", zSymname);
214 return NULL;
215 }else{
216 return json_get_wiki_page_by_rid(rid, contentFormat);
217 }
218 }
219 }
220
221 /*
222 ** Implementation of /json/wiki/get.
223 **
224 */
@@ -230,26 +259,11 @@
259 /* TODO: see if we have a page named zPageName. If not, try to resolve
260 zPageName as a UUID.
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

Keyboard Shortcuts

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