2
0

Persist unknown JSON properties, expose to API, safety improvements.

This commit is contained in:
Maarten Billemont
2019-07-27 09:24:39 -04:00
parent fc1e86f0ca
commit ddb786c332
7 changed files with 317 additions and 133 deletions

View File

@@ -489,7 +489,7 @@ void cli_user(Arguments *args, Operation *operation) {
mpw_free_string( &operation->sitesPath );
mpw_marshal_free( &operation->file );
operation->file = mpw_marshal_file( mpw_marshal_user(
operation->fullName, cli_masterKeyProvider_op( operation ), MPAlgorithmVersionCurrent ) );
operation->fullName, cli_masterKeyProvider_op( operation ), MPAlgorithmVersionCurrent ), NULL );
}
else {
@@ -550,7 +550,7 @@ void cli_site(Arguments *args, Operation *operation) {
// Load the site object from mpsites.
MPMarshalledUser *user = operation->file->user;
for (size_t s = 0; !operation->site && s < user->sites_count; ++s)
if (strcmp( operation->siteName, (&user->sites[s])->siteName ) == 0)
if (strcmp( operation->siteName, (&user->sites[s])->siteName ) == OK)
operation->site = &user->sites[s];
// If no site from mpsites, create a new one.
@@ -571,8 +571,11 @@ void cli_question(Arguments *args, Operation *operation) {
break;
case MPKeyPurposeRecovery:
for (size_t q = 0; !operation->question && q < operation->site->questions_count; ++q)
if ((!operation->keyContext && !strlen( (&operation->site->questions[q])->keyword )) ||
(operation->keyContext && strcmp( (&operation->site->questions[q])->keyword, operation->keyContext ) == 0))
if (operation->keyContext == (&operation->site->questions[q])->keyword ||
(!operation->keyContext && !strlen( (&operation->site->questions[q])->keyword )) ||
(!(&operation->site->questions[q])->keyword && !strlen( operation->keyContext )) ||
((operation->keyContext && (&operation->site->questions[q])->keyword) &&
strcmp( (&operation->site->questions[q])->keyword, operation->keyContext ) == OK))
operation->question = &operation->site->questions[q];
// If no question from mpsites, create a new one.
@@ -700,7 +703,7 @@ void cli_algorithmVersion(Arguments *args, Operation *operation) {
void cli_sitesRedacted(Arguments *args, Operation *operation) {
if (args->sitesRedacted)
operation->file->user->redacted = strcmp( args->sitesRedacted, "1" ) == 0;
operation->file->user->redacted = strcmp( args->sitesRedacted, "1" ) == OK;
else if (!operation->file->user->redacted)
wrn( "Sites configuration is not redacted. Use -R 1 to change this." );

View File

@@ -45,18 +45,21 @@ static xmlChar const *mpw_xmlPath(xmlNodePtr context) {
xmlNodePtr mpw_xmlTestCaseNode(xmlNodePtr testCaseNode, const char *nodeName) {
if (!nodeName)
return NULL;
// Try to find an attribute node.
for (xmlAttrPtr child = testCaseNode->properties; child; child = child->next)
if (xmlStrcmp( child->name, BAD_CAST nodeName ) == 0)
if (xmlStrcmp( child->name, BAD_CAST nodeName ) == OK)
return (xmlNodePtr)child;
// Try to find an element node.
for (xmlNodePtr child = testCaseNode->children; child; child = child->next)
if (xmlStrcmp( child->name, BAD_CAST nodeName ) == 0)
if (xmlStrcmp( child->name, BAD_CAST nodeName ) == OK)
return child;
// Missing content, try to find parent case.
if (strcmp( nodeName, "parent" ) == 0)
if (strcmp( nodeName, "parent" ) == OK)
// Was just searching for testCaseNode's parent, none found.
return NULL;
xmlChar *parentId = mpw_xmlTestCaseString( testCaseNode, "parent" );
@@ -66,7 +69,7 @@ xmlNodePtr mpw_xmlTestCaseNode(xmlNodePtr testCaseNode, const char *nodeName) {
for (xmlNodePtr otherTestCaseNode = testCaseNode->parent->children; otherTestCaseNode; otherTestCaseNode = otherTestCaseNode->next) {
xmlChar *id = mpw_xmlTestCaseString( otherTestCaseNode, "id" );
int foundParent = id && xmlStrcmp( id, parentId ) == 0;
int foundParent = id && xmlStrcmp( id, parentId ) == OK;
xmlFree( id );
if (foundParent) {
@@ -81,12 +84,18 @@ xmlNodePtr mpw_xmlTestCaseNode(xmlNodePtr testCaseNode, const char *nodeName) {
xmlChar *mpw_xmlTestCaseString(xmlNodePtr context, const char *nodeName) {
if (!nodeName)
return NULL;
xmlNodePtr child = mpw_xmlTestCaseNode( context, nodeName );
return child? xmlNodeGetContent( child ): NULL;
}
uint32_t mpw_xmlTestCaseInteger(xmlNodePtr context, const char *nodeName) {
if (!nodeName)
return 0;
xmlChar *string = mpw_xmlTestCaseString( context, nodeName );
uint32_t integer = string? (uint32_t)atol( (char *)string ): 0;
xmlFree( string );