/* ** Implementation of the /json/diff page. ** ** Arguments: ** ** v1=1st version to diff ** v2=2nd version to diff ** ** Can come from GET, POST.payload, CLI -v1/-v2 or as positional ** parameters following the command name (in HTTP and CLI modes). ** */ cson_value * json_page_diff(){ cson_object * pay = NULL; cson_value * v = NULL; char const * zFrom; char const * zTo; int nContext = 0; char doSBS; char doHtml; if(!g.perm.Read){ json_set_err(FSL_JSON_E_DENIED, "Requires 'o' permissions."); return NULL; } zFrom = json_find_option_cstr("v1",NULL,NULL); if(!zFrom){ zFrom = json_command_arg(2); } if(!zFrom){ json_set_err(FSL_JSON_E_MISSING_ARGS, "Required 'v1' parameter is missing."); return NULL; } zTo = json_find_option_cstr("v2",NULL,NULL); if(!zTo){ zTo = json_command_arg(3); } if(!zTo){ json_set_err(FSL_JSON_E_MISSING_ARGS, "Required 'v2' parameter is missing."); return NULL; } nContext = json_find_option_int("context",NULL,"c",5); doSBS = json_find_option_bool("sbs",NULL,"y",0); doHtml = json_find_option_bool("html",NULL,"h",0); v = json_generate_diff(zFrom, zTo, nContext, doSBS, doHtml); if(!v){ if(!g.json.resultCode){ json_set_err(FSL_JSON_E_UNKNOWN, "Generating diff failed for unknown reason."); } return NULL; } pay = cson_new_object(); cson_object_set(pay, "from", json_new_string(zFrom)); cson_object_set(pay, "to", json_new_string(zTo)); cson_object_set(pay, "diff", v); v = 0; return pay ? cson_object_value(pay) : NULL; }
/* ** Internal helper which returns: ** ** If the "format" (CLI: -f) flag is set function returns the same as ** json_wiki_get_content_format_flag(), else it returns true (non-0) ** if either the includeContent (HTTP) or -content|-c boolean flags ** (CLI) are set. */ static char json_artifact_get_content_format_flag(){ enum { MagicValue = -9 }; char contentFormat = json_wiki_get_content_format_flag(MagicValue); if(MagicValue == contentFormat){ contentFormat = json_find_option_bool("includeContent","content","c",0) /* deprecated */ ? -1 : 0; } return contentFormat; }
/* ** Implementation of /json/timeline/ci. ** ** Still a few TODOs (like figuring out how to structure ** inheritance info). */ static cson_value * json_timeline_ci(){ cson_value * payV = NULL; cson_object * pay = NULL; cson_value * tmp = NULL; cson_value * listV = NULL; cson_array * list = NULL; int check = 0; char verboseFlag; Stmt q = empty_Stmt; char warnRowToJsonFailed = 0; Blob sql = empty_blob; if( !g.perm.Hyperlink ){ /* Reminder to self: HTML impl requires 'o' (Read) rights. */ json_set_err( FSL_JSON_E_DENIED, "Check-in timeline requires 'h' access." ); return NULL; } verboseFlag = json_find_option_bool("verbose",NULL,"v",0); if( !verboseFlag ){ verboseFlag = json_find_option_bool("files",NULL,"f",0); } payV = cson_value_new_object(); pay = cson_value_get_object(payV); check = json_timeline_setup_sql( "ci", &sql, pay ); if(check){ json_set_err(check, "Query initialization failed."); goto error; } #define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \ json_set_err((cson_rc.AllocError==check) \ ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN,\ "Object property insertion failed"); \ goto error;\ } (void)0 #if 0 /* only for testing! */ tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))); SET("timelineSql"); #endif db_multi_exec("%s", blob_buffer(&sql)/*safe-for-%s*/); blob_reset(&sql); db_prepare(&q, "SELECT " " rid AS rid" " FROM json_timeline" " ORDER BY rowid"); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE_ROW == db_step(&q) )){ /* convert each row into a JSON object...*/ int const rid = db_column_int(&q,0); cson_value * rowV = json_artifact_for_ci(rid, verboseFlag); cson_object * row = cson_value_get_object(rowV); if(!row){ if( !warnRowToJsonFailed ){ warnRowToJsonFailed = 1; json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED, "Could not convert at least one timeline result row to JSON." ); } continue; } cson_array_append(list, rowV); } #undef SET goto ok; error: assert( 0 != g.json.resultCode ); cson_value_free(payV); payV = NULL; ok: db_finalize(&q); return payV; }