Omit questions if none present and fix parsing sites with no questions.
This commit is contained in:
parent
4a555748cd
commit
81358c16f9
@ -304,27 +304,29 @@ static bool mpw_marshal_write_json(
|
|||||||
if (strftime( dateString, sizeof( dateString ), "%FT%TZ", gmtime( &site->lastUsed ) ))
|
if (strftime( dateString, sizeof( dateString ), "%FT%TZ", gmtime( &site->lastUsed ) ))
|
||||||
json_object_object_add( json_site, "last_used", json_object_new_string( dateString ) );
|
json_object_object_add( json_site, "last_used", json_object_new_string( dateString ) );
|
||||||
|
|
||||||
json_object *json_site_questions = json_object_new_object();
|
if (site->questions_count) {
|
||||||
json_object_object_add( json_site, "questions", json_site_questions );
|
json_object *json_site_questions = json_object_new_object();
|
||||||
for (size_t q = 0; q < site->questions_count; ++q) {
|
json_object_object_add( json_site, "questions", json_site_questions );
|
||||||
MPMarshalledQuestion *question = &site->questions[q];
|
for (size_t q = 0; q < site->questions_count; ++q) {
|
||||||
if (!question->keyword)
|
MPMarshalledQuestion *question = &site->questions[q];
|
||||||
continue;
|
if (!question->keyword)
|
||||||
|
continue;
|
||||||
|
|
||||||
json_object *json_site_question = json_object_new_object();
|
json_object *json_site_question = json_object_new_object();
|
||||||
json_object_object_add( json_site_questions, question->keyword, json_site_question );
|
json_object_object_add( json_site_questions, question->keyword, json_site_question );
|
||||||
json_object_object_add( json_site_question, "type", json_object_new_int( (int32_t)question->type ) );
|
json_object_object_add( json_site_question, "type", json_object_new_int( (int32_t)question->type ) );
|
||||||
|
|
||||||
if (!user->redacted) {
|
if (!user->redacted) {
|
||||||
// Clear Text
|
// Clear Text
|
||||||
const char *answerContent = mpw_siteResult( masterKey, site->name, MPCounterValueInitial,
|
const char *answerContent = mpw_siteResult( masterKey, site->name, MPCounterValueInitial,
|
||||||
MPKeyPurposeRecovery, question->keyword, question->type, question->content, site->algorithm );
|
MPKeyPurposeRecovery, question->keyword, question->type, question->content, site->algorithm );
|
||||||
json_object_object_add( json_site_question, "answer", json_object_new_string( answerContent ) );
|
json_object_object_add( json_site_question, "answer", json_object_new_string( answerContent ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Redacted
|
// Redacted
|
||||||
if (site->type & MPSiteFeatureExportContent && question->content && strlen( question->content ))
|
if (site->type & MPSiteFeatureExportContent && question->content && strlen( question->content ))
|
||||||
json_object_object_add( json_site_question, "answer", json_object_new_string( question->content ) );
|
json_object_object_add( json_site_question, "answer", json_object_new_string( question->content ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,23 +799,25 @@ static MPMarshalledUser *mpw_marshal_read_json(
|
|||||||
site->loginContent = mpw_strdup( siteLoginName );
|
site->loginContent = mpw_strdup( siteLoginName );
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object_iter json_site_question;
|
|
||||||
json_object *json_site_questions = mpw_get_json_section( json_site.val, "questions" );
|
json_object *json_site_questions = mpw_get_json_section( json_site.val, "questions" );
|
||||||
json_object_object_foreachC( json_site_questions, json_site_question ) {
|
if (json_site_questions) {
|
||||||
MPMarshalledQuestion *question = mpw_marshal_question( site, json_site_question.key );
|
json_object_iter json_site_question;
|
||||||
const char *answerContent = mpw_get_json_string( json_site_question.val, "answer", NULL );
|
json_object_object_foreachC( json_site_questions, json_site_question ) {
|
||||||
question->type = (MPResultType)mpw_get_json_int( json_site_question.val, "type", MPResultTypeTemplatePhrase );
|
MPMarshalledQuestion *question = mpw_marshal_question( site, json_site_question.key );
|
||||||
|
const char *answerContent = mpw_get_json_string( json_site_question.val, "answer", NULL );
|
||||||
|
question->type = (MPResultType)mpw_get_json_int( json_site_question.val, "type", MPResultTypeTemplatePhrase );
|
||||||
|
|
||||||
if (!user->redacted) {
|
if (!user->redacted) {
|
||||||
// Clear Text
|
// Clear Text
|
||||||
if (answerContent && strlen( answerContent ))
|
if (answerContent && strlen( answerContent ))
|
||||||
question->content = mpw_siteState( masterKey, site->name, MPCounterValueInitial,
|
question->content = mpw_siteState( masterKey, site->name, MPCounterValueInitial,
|
||||||
MPKeyPurposeRecovery, question->keyword, question->type, answerContent, site->algorithm );
|
MPKeyPurposeRecovery, question->keyword, question->type, answerContent, site->algorithm );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Redacted
|
// Redacted
|
||||||
if (answerContent && strlen( answerContent ))
|
if (answerContent && strlen( answerContent ))
|
||||||
question->content = mpw_strdup( answerContent );
|
question->content = mpw_strdup( answerContent );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user