Exemplo n.º 1
0
Ret_t buildDevInfExtCmd(XltDecoderPtr_t pDecoder, VoidPtr_t *ppElem) {
    XltDecScannerPtr_t pScanner;
    SmlDevInfExtPtr_t pElem;
    Ret_t rc;

    pScanner = pDecoder->scanner;

    if (*ppElem != NULL)
        return SML_ERR_XLT_INVAL_SYNCML_DOC;

    if ((pElem = (SmlDevInfExtPtr_t)smlLibMalloc(sizeof(SmlDevInfExt_t))) == NULL)
        return SML_ERR_NOT_ENOUGH_SPACE;
    smlLibMemset(pElem, 0, sizeof(SmlDevInfExt_t));

    if (IS_EMPTY(pScanner->curtok)) {
        *ppElem = pElem;
        return SML_ERR_OK;
    }

    if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
        smlLibFree(pElem);
        return rc;
    }

    while (pScanner->curtok->type != TOK_TAG_END) {
        switch (pScanner->curtok->tagid) {
            case TN_DEVINF_XNAM:
                rc = buildPCData(pDecoder, (VoidPtr_t)&pElem->xnam);
                break;
            case TN_DEVINF_XVAL:
                rc = buildPCDataList(pDecoder, (VoidPtr_t)&pElem->xval);
                break;
            default:
                rc = SML_ERR_XLT_INVAL_SYNCML_DOC;
        }
        if (rc != SML_ERR_OK) {
            smlLibFree(pElem);
            return rc;
        }
        if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
            smlLibFree(pElem);
            return rc;
        }
    }
    *ppElem = pElem;

    return SML_ERR_OK;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
Ret_t buildDevInfCtcap(XltDecoderPtr_t pDecoder, VoidPtr_t *ppElem) {
    SmlDevInfCtcapListPtr_t       pCtcap        = NULL, pPrev = NULL;
    SmlDevInfCTDataPropListPtr_t  pOldProp      = NULL, pProp = NULL;
    SmlDevInfCTDataListPtr_t      pOldParam     = NULL, pParam = NULL;
    SmlDevInfCtcapListPtr_t       pElem         = NULL;
    XltDecScannerPtr_t            pScanner;
    Ret_t rc;

    pElem = (SmlDevInfCtcapListPtr_t) *ppElem;
    pScanner = pDecoder->scanner;

    if (IS_EMPTY(pScanner->curtok)) {
        *ppElem = pElem;
        return SML_ERR_OK;
    }

    if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
        smlLibFree(pElem);
        return rc;
    }

    while (pScanner->curtok->type != TOK_TAG_END) {
        switch (pScanner->curtok->tagid) {
        case TN_DEVINF_CTTYPE:        
            pCtcap = (SmlDevInfCtcapListPtr_t) *ppElem;
            /* advance to the end of the list, and create ther an empty list element */
            while (pCtcap != NULL) {
	            pPrev = pCtcap;
	            pCtcap = pPrev->next;
            }
            if ((pCtcap = (SmlDevInfCtcapListPtr_t)smlLibMalloc(sizeof(SmlDevInfCtcapList_t))) == NULL)
                return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pCtcap, 0, sizeof(SmlDevInfCtcapList_t));
            if (pPrev != NULL) /* we already had some entries in the list */
	            pPrev->next = pCtcap;
            else /* nope we created a new list */
	            *ppElem = pCtcap;
            pCtcap->data = (SmlDevInfCTCapPtr_t)smlLibMalloc(sizeof(SmlDevInfCTCap_t));
            if (pCtcap->data == NULL) return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pCtcap->data, 0, sizeof(SmlDevInfCTCap_t));
            rc = buildPCData(pDecoder, (VoidPtr_t)&pCtcap->data->cttype);
            break;
        case TN_DEVINF_PROPNAME:
            pCtcap = (SmlDevInfCtcapListPtr_t) *ppElem;
            if (pCtcap == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            while (pCtcap->next != NULL) {
                pPrev = pCtcap;
                pCtcap = pCtcap->next;
            }
            /* here we are at the latest defined DevInfCTCapPtr_t */
            /* now we need to create a new DevInfCTDataPtr_t element, tostore the properties name */
            pOldProp = NULL;
            pProp    = pCtcap->data->prop;
            while (pProp != NULL) {
                pOldProp = pProp;
                pProp = pProp->next;
            }
            pProp = (SmlDevInfCTDataPropListPtr_t) smlLibMalloc(sizeof(SmlDevInfCTDataPropList_t));
            if (pProp == NULL) return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pProp, 0, sizeof(SmlDevInfCTDataPropList_t));
            if (pOldProp != NULL)
                pOldProp->next = pProp;
            else 
                pCtcap->data->prop = pProp;
            pProp->data = (SmlDevInfCTDataPropPtr_t)smlLibMalloc(sizeof(SmlDevInfCTDataProp_t));
            if (pProp->data == NULL) return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pProp->data, 0, sizeof(SmlDevInfCTDataProp_t));
            pProp->data->prop = (SmlDevInfCTDataPtr_t)smlLibMalloc(sizeof(SmlDevInfCTData_t));
            if (pProp->data->prop == NULL) return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pProp->data->prop, 0, sizeof(SmlDevInfCTData_t));
            rc = buildPCData(pDecoder, (VoidPtr_t)&pProp->data->prop->name);
            break;
        case TN_DEVINF_PARAMNAME:
            pCtcap = (SmlDevInfCtcapListPtr_t) *ppElem;
            if (pCtcap == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            while (pCtcap->next != NULL) {
                pPrev = pCtcap;
                pCtcap = pCtcap->next;
            }
            /* here we are at the latest defined DevInfCTCapPtr_t */
            pProp    = pCtcap->data->prop;
            if (pProp == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            while (pProp->next != NULL) {
                pProp = pProp->next;
            }
            /* here we are at the latest defined PropList Element in the latest defined CTCap element */
            /* now lets insert a new Param element into this property */
            pOldParam = NULL;
            pParam = pProp->data->param;
            while (pParam != NULL) {
                pOldParam = pParam;
                pParam    = pParam->next;
            }
            pParam = (SmlDevInfCTDataListPtr_t)smlLibMalloc(sizeof(SmlDevInfCTDataList_t));
            if (pParam == NULL) return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pParam, 0, sizeof(SmlDevInfCTDataList_t));
            if (pOldParam != NULL)
                pOldParam->next = pParam;
            else
                pProp->data->param = pParam;
            pParam->data = (SmlDevInfCTDataPtr_t)smlLibMalloc(sizeof(SmlDevInfCTData_t));
            if (pParam->data == NULL) return SML_ERR_NOT_ENOUGH_SPACE;
            smlLibMemset(pParam->data, 0, sizeof(SmlDevInfCTData_t));
            rc = buildPCData(pDecoder, (VoidPtr_t)&pParam->data->name);
            break;
        case TN_DEVINF_DISPLAYNAME:
        case TN_DEVINF_VALENUM:
        case TN_DEVINF_DATATYPE:
        case TN_DEVINF_SIZE:
            /* The code for the above 4 is basically the same.
             * The hardpart is finding the right SmlDevInfCTDataPtr_t
             * struct, as it can be either within a Property or an Parameter.
             */
            pCtcap = (SmlDevInfCtcapListPtr_t) *ppElem;
            if (pCtcap == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            while (pCtcap->next != NULL) {
                pCtcap = pCtcap->next;
            }
            /* here we are at the latest defined DevInfCTCapPtr_t */
            pProp    = pCtcap->data->prop;
            if (pProp == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            while (pProp->next != NULL) {
                pProp = pProp->next;
            }

            if (pProp->data == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            if (pProp->data->prop == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
            if (pProp->data->param == NULL) {
                /* No Param's yet so we have Property fields to fill */
                switch(pScanner->curtok->tagid) {
                case TN_DEVINF_DISPLAYNAME:
                    rc = buildPCData(pDecoder, (VoidPtr_t)&pProp->data->prop->dname);
                    break;
                case TN_DEVINF_VALENUM:
                    rc = buildPCDataList(pDecoder, (VoidPtr_t)&pProp->data->prop->valenum);
                    break;
                case TN_DEVINF_DATATYPE:
                    rc = buildPCData(pDecoder, (VoidPtr_t)&pProp->data->prop->datatype);
                    break;
                case TN_DEVINF_SIZE:
                    rc = buildPCData(pDecoder, (VoidPtr_t)&pProp->data->prop->size);
                    break;
                default:
                    break;
                }
            } else {
                pParam = pProp->data->param;
                while (pParam->next != NULL) {
                    pParam = pParam->next;
                }
                if (pParam->data == NULL) return SML_ERR_XLT_INVAL_SYNCML_DOC;
                switch(pScanner->curtok->tagid) {
                case TN_DEVINF_DISPLAYNAME:
                    rc = buildPCData(pDecoder, (VoidPtr_t)&pParam->data->dname);
                    break;
                case TN_DEVINF_VALENUM:
                    rc = buildPCDataList(pDecoder, (VoidPtr_t)&pParam->data->valenum);
                    break;
                case TN_DEVINF_DATATYPE:
                    rc = buildPCData(pDecoder, (VoidPtr_t)&pParam->data->datatype);
                    break;
                case TN_DEVINF_SIZE:
                    rc = buildPCData(pDecoder, (VoidPtr_t)&pParam->data->size);
                    break;
                default:
                    break;
                }
            }
            break;
        default:
            rc = SML_ERR_XLT_INVAL_SYNCML_DOC;
        }
        if (rc != SML_ERR_OK) {
            smlLibFree(pElem);
            return rc;
        }
        if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
            smlLibFree(pElem);
            return rc;
        }
    } /* eof while */
    pElem = *ppElem;
    return SML_ERR_OK;
}