SmlPcdataPtr_t convert_to_meta(char * format, char * type) { SmlPcdataPtr_t metaP = NULL; SmlMetInfMetInfPtr_t metInfP; if (format == NULL && type == NULL) { return NULL; } metInfP = smlAllocMetInfMetInf(); if (!metInfP) return NULL; if (type) metInfP->type = smlString2Pcdata(type); if (format) metInfP->format = smlString2Pcdata(format); metaP = smlAllocPcdata(); if (!metaP) { smlFreeMetinfMetinf(metInfP); return NULL; } metaP->contentType = SML_PCDATA_EXTENSION; metaP->extension = SML_EXT_METINF; metaP->length = 0; metaP->content = metInfP; return metaP; }
/** * FUNCTION: smlFreePcdata * * frees the Memory of an allocated Pcdata memory object * * IN: SmlPcdataPtr_t * A Pointer to a PcData structure, which should be freed * * RETURN: --- * */ SML_API void smlFreePcdata(SmlPcdataPtr_t pPcdata) { if (! pPcdata) return; if (pPcdata->contentType == SML_PCDATA_EXTENSION) { switch ((int)pPcdata->extension) { #ifdef __USE_METINF__ case SML_EXT_METINF: smlFreeMetinfMetinf(pPcdata->content); smlLibFree(pPcdata); break; #endif #ifdef __USE_DEVINF__ case SML_EXT_DEVINF: smlFreeDevInfDevInf(pPcdata->content); smlLibFree(pPcdata); break; #endif } return; } if (pPcdata->content) smlLibFree(pPcdata->content); smlLibFree(pPcdata); }
SmlPcdataPtr_t create_chal_meta(dmclt_authType_t type, buffer_t * nonceP) { SmlMetInfMetInfPtr_t metInfP; SmlPcdataPtr_t metaP; metInfP = smlAllocMetInfMetInf(); if (!metInfP) return NULL; metInfP->type = smlString2Pcdata(auth_type_as_string(type)); metInfP->format = smlString2Pcdata("b64"); if (nonceP) { char * tmp = encode_b64(*nonceP); metInfP->nextnonce = smlString2Pcdata(tmp); free(tmp); } metaP = smlAllocPcdata(); if (!metaP) { smlFreeMetinfMetinf(metInfP); return NULL; } metaP->contentType = SML_PCDATA_EXTENSION; metaP->extension = SML_EXT_METINF; metaP->length = 0; metaP->content = metInfP; return metaP; }
Ret_t buildMetInfMetInfCmd(XltDecoderPtr_t pDecoder, VoidPtr_t *ppElem) { XltDecScannerPtr_t pScanner; SmlMetInfMetInfPtr_t pMeta; Ret_t rc; int foundWrapper = 0; pScanner = pDecoder->scanner; if (*ppElem != NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC; if ((pMeta = (SmlMetInfMetInfPtr_t)smlLibMalloc(sizeof(SmlMetInfMetInf_t))) == NULL) return SML_ERR_NOT_ENOUGH_SPACE; smlLibMemset(pMeta, 0, sizeof(SmlMetInfMetInf_t)); if (IS_EMPTY(pScanner->curtok)) { *ppElem = pMeta; return SML_ERR_OK; } if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) { smlFreeMetinfMetinf(pMeta); //smlLibFree(pMeta); return rc; } while (pScanner->curtok->type != TOK_TAG_END) { switch (pScanner->curtok->tagid) { case TN_METINF_METINF: /* ignore - it's just the wrapper tag */ foundWrapper = 1; break; case TN_METINF_FORMAT: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->format); break; case TN_METINF_TYPE: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->type); break; case TN_METINF_MARK: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->mark); break; case TN_METINF_SIZE: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->size); break; case TN_METINF_VERSION: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->version); break; case TN_METINF_NEXTNONCE: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->nextnonce); break; case TN_METINF_ANCHOR: rc = buildMetInfAnchorCmd(pDecoder, (VoidPtr_t)&pMeta->anchor); break; case TN_METINF_MAXMSGSIZE: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->maxmsgsize); break; /* SCTSTK - 18/03/2002 S.H. 2002-04-05: SyncML 1.1 */ case TN_METINF_MAXOBJSIZE: rc = buildPCData(pDecoder, (VoidPtr_t)&pMeta->maxobjsize); break; case TN_METINF_MEM: rc = buildMetInfMemCmd(pDecoder, (VoidPtr_t)&pMeta->mem); break; case TN_METINF_EMI: rc = buildPCDataList(pDecoder, (VoidPtr_t)&pMeta->emi); break; /* SyncML DS 1.2, Synthesis/luz 2005-08-24 */ case TN_METINF_FIELDLEVEL: pMeta->flags |= SmlMetInfFieldLevel_f; rc = buildEmptyTag(pDecoder); // allow for <tag></tag> instead of <tag/> break; default: rc = SML_ERR_XLT_INVAL_SYNCML_DOC; } if (rc != SML_ERR_OK) { smlFreeMetinfMetinf(pMeta); //smlLibFree(pMeta); return rc; } if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) { smlFreeMetinfMetinf(pMeta); //smlLibFree(pMeta); return rc; } } if (foundWrapper) { /* Optional Metinf root tag was used in this message. * The actual token is the closing root tag. * It is required that the scanner points to the first tag _after_ * <MetInf>...</MetInf>, so we just skip to the next token and continue. */ if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) { smlFreeMetinfMetinf(pMeta); //smlLibFree(pMeta); return rc; } } *ppElem = pMeta; return SML_ERR_OK; }