static errorCode ops_startElement(QName qname, void* app_data) { struct ops_AppData* o_appD = (struct ops_AppData*) app_data; if(o_appD->o_strm->context.currElem.uriId == 4) // URI == http://www.w3.org/2009/exi { o_appD->prevElementUriID = 4; switch(o_appD->o_strm->context.currElem.lnId) { case 33: // strict SET_STRICT(o_appD->parsed_ops->enumOpt); o_appD->prevElementLnID = 33; break; case 31: // schemaId o_appD->prevElementLnID = 31; o_appD->parsed_ops->schemaIDMode = SCHEMA_ID_EMPTY; break; case 7: // compression SET_COMPRESSION(o_appD->parsed_ops->enumOpt); o_appD->prevElementLnID = 7; break; case 14: // fragment SET_FRAGMENT(o_appD->parsed_ops->enumOpt); o_appD->prevElementLnID = 14; break; case 13: // dtd SET_PRESERVED(o_appD->parsed_ops->preserve, PRESERVE_DTD); o_appD->prevElementLnID = 13; break; case 29: // prefixes SET_PRESERVED(o_appD->parsed_ops->preserve, PRESERVE_PREFIXES); o_appD->prevElementLnID = 29; break; case 26: // lexicalValues SET_PRESERVED(o_appD->parsed_ops->preserve, PRESERVE_LEXVALUES); o_appD->prevElementLnID = 26; break; case 5: // comments SET_PRESERVED(o_appD->parsed_ops->preserve, PRESERVE_COMMENTS); o_appD->prevElementLnID = 5; break; case 27: // pis SET_PRESERVED(o_appD->parsed_ops->preserve, PRESERVE_PIS); o_appD->prevElementLnID = 27; break; case 4: // alignment->byte SET_ALIGNMENT(o_appD->parsed_ops->enumOpt, BYTE_ALIGNMENT); o_appD->prevElementLnID = 4; break; case 28: // alignment->pre-compress SET_ALIGNMENT(o_appD->parsed_ops->enumOpt, PRE_COMPRESSION); o_appD->prevElementLnID = 28; break; case 32: // selfContained SET_SELF_CONTAINED(o_appD->parsed_ops->enumOpt); o_appD->prevElementLnID = 32; break; case 8: // datatypeRepresentationMap o_appD->prevElementLnID = 8; break; case 36: // uncommon o_appD->prevElementLnID = 36; #if EXI_PROFILE_DEFAULT { // If the EXI Profile default behaviour is followed, then we expect // SE(*) <p/> indicating default EXI Profile parameters // If this is not the case rise an error // SE(*) has event code 5 in the uncommon grammar unsigned int tmp_bits_val; UnsignedInteger lnLen = 0; errorCode tmp_err_code = UNEXPECTED_ERROR; String lnStr; QNameID qnameId = {URI_MAX, LN_MAX}; // Next event code must be SE(*) TRY(decodeNBitUnsignedInteger(o_appD->o_strm, 3, &tmp_bits_val)); if(tmp_bits_val != 5) { DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">EXI Profile default active but <p> element missing\n")); return INVALID_EXIP_CONFIGURATION; } // The <p> element QName must be "http://www.w3.org/2009/exi:p" TRY(decodeUri(o_appD->o_strm, &qnameId.uriId)); TRY(decodeUnsignedInteger(o_appD->o_strm, &lnLen)); if(lnLen == 0) // local-name table hit -> should not be the case to have "p" in the local string table return INVALID_EXIP_CONFIGURATION; TRY(allocateStringMemoryManaged(&(lnStr.str),(Index) (lnLen - 1), &o_appD->o_strm->memList)); TRY(decodeStringOnly(o_appD->o_strm, (Index)lnLen - 1, &lnStr)); // NOTE: the "p" local name is in purpose not added to the // local name table of the http://www.w3.org/2009/exi uri, although it should be. // If there are more strings (24 or more) added there in the future // or the <p> element is encoded more than once - both are highly unlikely, // then there will be a problem with the encoding. if(qnameId.uriId != 4 || !stringEqualToAscii(lnStr, "p")) { DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">EXI Profile default active but <p> element missing\n")); return INVALID_EXIP_CONFIGURATION; } // The next event code must be EE -> 0.0 TRY(decodeNBitUnsignedInteger(o_appD->o_strm, 2, &tmp_bits_val)); if(tmp_bits_val != 0) { DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">EXI Profile default active but <p> element is not empty\n")); return INVALID_EXIP_CONFIGURATION; } } #endif break; } } else // URI != http://www.w3.org/2009/exi { // The previous element should be either uncommon or datatypeRepresentationMap otherwise it is an error // These are the only places where <any> element is allowed if(o_appD->prevElementUriID != 4 || o_appD->prevElementLnID != 36 || o_appD->prevElementLnID != 8) { DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">Wrong namespace in the EXI Options\n")); return EXIP_HANDLER_STOP; } // Handle here the user defined meta-data that follows! http://www.w3.org/TR/2011/REC-exi-20110310/#key-userMetaData } return ERR_OK; }
static void parseOpsMask(char* mask, EXIOptions* ops) { unsigned int i; char *token; for (token = strtok(mask, "=%"), i = 0; token != NULL; token = strtok(NULL, "=%"), i++) { switch(i) { case 0: if(strcmp(token, "-")) { // Preservation Options: c - comments, d - dtds, l - lexicalvalues, p - pis, x- prefixes if(strstr(token, "c") != NULL) SET_PRESERVED(ops->preserve, PRESERVE_COMMENTS); if(strstr(token, "d") != NULL) SET_PRESERVED(ops->preserve, PRESERVE_DTD); if(strstr(token, "l") != NULL) SET_PRESERVED(ops->preserve, PRESERVE_LEXVALUES); if(strstr(token, "p") != NULL) SET_PRESERVED(ops->preserve, PRESERVE_PIS); if(strstr(token, "x") != NULL) SET_PRESERVED(ops->preserve, PRESERVE_PREFIXES); } break; case 1: if(strcmp(token, "-")) { // Other options: v - strict interpretation of schema, f - fragments // r - selfContained, c - compression, p - pre-compression, a - aligned to bytes\n"); if(strstr(token, "v") != NULL) SET_STRICT(ops->enumOpt); if(strstr(token, "f") != NULL) SET_FRAGMENT(ops->enumOpt); if(strstr(token, "r") != NULL) SET_SELF_CONTAINED(ops->enumOpt); if(strstr(token, "c") != NULL) SET_COMPRESSION(ops->enumOpt); if(strstr(token, "p") != NULL) SET_ALIGNMENT(ops->enumOpt, PRE_COMPRESSION); else if(strstr(token, "a") != NULL) SET_ALIGNMENT(ops->enumOpt, BYTE_ALIGNMENT); } break; case 2: if(strcmp(token, "-")) { // valuePartitionCapacity ops->valuePartitionCapacity = (Index) strtol(token, NULL, 10); } break; case 3: if(strcmp(token, "-")) { // valueMaxLength ops->valueMaxLength = (Index) strtol(token, NULL, 10); } break; case 4: if(strcmp(token, "-")) { // blockSize ops->blockSize = (uint32_t) strtol(token, NULL, 10); } break; default: { fprintf(stderr, "Wrong options mask: %s", mask); exit(1); } } } }