Example #1
0
Ret_t getTagString(XltTagID_t tagID, String_t tagString, SmlPcdataExtension_t ext)
{
  // %%% luz 2005-11-11 : added retry loop to try MetInf as a fallback (workaround for ill-formed xml like in sync4j pda clients)
  do {
    int i = 0;
    TagPtr_t pTags = getTagTable(ext);
    if (pTags == NULL) {
      tagString[0] = '\0';
      return SML_ERR_NOT_ENOUGH_SPACE;
    }
    while (((pTags+i)->id) != TN_UNDEF) {
      if (((pTags+i)->id) == tagID) {
        String_t _tmp = (pTags+i)->xml;
        smlLibStrcpy(tagString, _tmp);
        return SML_ERR_OK;
      }
      i++;
    }
    // tag not found
    if (ext==SML_EXT_METINF) break; // already tried with implicit or explicit metinf
    // try metinf implicitly for ill-formed xml like sync4j clients
    ext=SML_EXT_METINF;
  } while(TRUE);

  tagString[0] = '\0';
  return SML_ERR_XLT_INVAL_PROTO_ELEM;
}
Example #2
0
// %%% luz:2003-04-24: added syncmlvers parameter
// %%% luz:2003-07-31: changed to vers enum
Ret_t getExtName(SmlPcdataExtension_t ext, String_t *name, SmlVersion_t vers) {
  DtdPtr_t dtdhead = getDtdTable();
  DtdPtr_t dtd = dtdhead;
  const char *dtdname;
  if (!dtdhead) return -1;
  for (;dtd->ext != SML_EXT_LAST; dtd++) {
    if (!dtd->name) continue; /* skip empty names (should not appear but better be on the safe side) */
    if (dtd->ext == ext) {
      String_t _tmp;
      // this is the default
      dtdname=dtd->name;
      // %%% luz:2003-04-24: added dynamic generation of namespace according to SyncML version
      if (ext==SML_EXT_UNDEFINED && vers!=SML_VERS_UNDEF) {
        // this requests SyncML namespace
        dtdname=SyncMLNamespaces[vers];
      }
      _tmp = smlLibMalloc(smlLibStrlen(dtdname)+1);
      if (!_tmp) {
        freeDtdTable(dtdhead);
        return SML_ERR_NOT_ENOUGH_SPACE;
      }
      smlLibStrcpy(_tmp, dtdname);
      freeDtdTable(dtdhead);
      *name = _tmp;
      return SML_ERR_OK;
    }
  }
  freeDtdTable(dtdhead);
  return -1;
}
Example #3
0
/**
 * FUNCTION: smlLibStrdup
 *
 * Duplicates the String "constStringP".
 * Returns a pointer to the new copy of "constStringP". 
 *
 * IN:              String_t   constStringP     string, which is duplicated
 * RETURN:          String_t   pointer to the new copy,
 *                             null, if no copy could be allocated
 */
SML_API String_t smlLibStrdup (const char *constStringP)
{
	String_t _new_str;

	// allocate memory for new copy
	_new_str = (String_t)smlLibMalloc(smlLibStrlen(constStringP) + 1);
	
	// Copy the string into the new memory
	if (_new_str != NULL)
		smlLibStrcpy(_new_str, constStringP);
	   
	return _new_str;
}
Example #4
0
Ret_t getTagString(XltTagID_t tagID, String_t tagString, SmlPcdataExtension_t ext)
{
  int i = 0;
  TagPtr_t pTags = getTagTable(ext);
  if (pTags == NULL) {
    tagString[0] = '\0';
    return SML_ERR_NOT_ENOUGH_SPACE;
  }
  while (((pTags+i)->id) != TN_UNDEF) {
    if ((((pTags+i)->id) == tagID)) {
      String_t _tmp = (pTags+i)->xml;
      smlLibStrcpy(tagString, _tmp); 
      return SML_ERR_OK;
    }    
    i++;
  }        
  //smlLibStrcpy(tagString, '\0'); 
  tagString[0] = '\0';
  return SML_ERR_XLT_INVAL_PROTO_ELEM;
}
Example #5
0
/* decoder callbacks */
Ret_t buildDmTndFormatCmd(XltDecoderPtr_t pDecoder, VoidPtr_t *ppElem)
{
    XltDecScannerPtr_t pScanner;
    SmlDmTndFormatPtr_t pDmTndFormat;
    Ret_t rc;

    pScanner = pDecoder->scanner;

    if (*ppElem != NULL)
        return SML_ERR_XLT_INVAL_SYNCML_DOC;

    if ((pDmTndFormat = (SmlDmTndFormatPtr_t)smlLibMalloc(sizeof(SmlDmTndFormat_t))) == NULL)
        return SML_ERR_NOT_ENOUGH_SPACE;
    smlLibMemset(pDmTndFormat, 0, sizeof(SmlDmTndFormat_t));

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

    if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
        smlFreeDmTndFormat(pDmTndFormat);
        return rc;
    }

    while (pScanner->curtok->type != TOK_TAG_END) {
        VoidPtr_t pContent = smlLibMalloc(6);
        if ( pContent == NULL )
        {
            smlFreeDmTndFormat(pDmTndFormat);
            return SML_ERR_NOT_ENOUGH_SPACE;
        }
        smlLibMemset(pContent, 0, 6);

        switch (pScanner->curtok->tagid) {
          case TN_DMTND_b64:
             smlLibStrcpy(pContent, "b64");
             break;
          case TN_DMTND_bin:
             smlLibStrcpy(pContent, "bin");
             break;
          case TN_DMTND_bool:
             smlLibStrcpy(pContent, "bool");
             break;
          case TN_DMTND_chr:
             smlLibStrcpy(pContent, "chr");
             break;
          case TN_DMTND_int:
             smlLibStrcpy(pContent, "int");
             break;
          case TN_DMTND_node:
             smlLibStrcpy(pContent, "node");
             break;
          case TN_DMTND_null:
             smlLibStrcpy(pContent, "null");
             break;
          case TN_DMTND_xml:
             smlLibStrcpy(pContent, "xml");
             break;
          case TN_DMTND_date:
             smlLibStrcpy(pContent, "date");
             break;
          case TN_DMTND_time:
             smlLibStrcpy(pContent, "time");
             break;
          case TN_DMTND_float:
             smlLibStrcpy(pContent, "float");
            break;
          default:
              KCDBG(">>>>>  Unkown token: %d <<<<<\n", pScanner->curtok->tagid);
              rc = SML_ERR_XLT_INVAL_SYNCML_DOC;
        }

        if (rc != SML_ERR_OK) {
            smlLibFree(pContent);
            smlFreeDmTndFormat(pDmTndFormat);
            return rc;
        }

        rc = buildPCData(pDecoder, (VoidPtr_t)&pDmTndFormat->value);
        if (rc != SML_ERR_OK) {
            smlLibFree(pContent);
            smlFreeDmTndFormat(pDmTndFormat);
            return rc;
        }
        pDmTndFormat->value->content = pContent;
        pDmTndFormat->value->length = smlLibStrlen(pContent);

        if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
            smlLibFree(pContent);
            smlFreeDmTndFormat(pDmTndFormat);
            return rc;
        }
        if (pScanner->curtok->type != TOK_TAG_END) {
            smlLibFree(pContent);
            smlFreeDmTndFormat(pDmTndFormat);
            return SML_ERR_XLT_INVAL_SYNCML_DOC;
        }
    }

    *ppElem = pDmTndFormat;

    return SML_ERR_OK;
}
Example #6
0
/* decoder callbacks */
Ret_t buildDmTndDFElementCmd(XltDecoderPtr_t pDecoder, VoidPtr_t *ppElem)
{
    XltDecScannerPtr_t pScanner;
    SmlDmTndDFElementPtr_t pDmTndDFElement;
    Ret_t rc;

    pScanner = pDecoder->scanner;

    if (*ppElem != NULL)
        return SML_ERR_XLT_INVAL_SYNCML_DOC;

    if ((pDmTndDFElement = (SmlDmTndDFElementPtr_t)smlLibMalloc(sizeof(SmlDmTndDFElement_t))) == NULL)
        return SML_ERR_NOT_ENOUGH_SPACE;
    smlLibMemset(pDmTndDFElement, 0, sizeof(SmlDmTndDFElement_t));

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

    if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
        smlFreeDmTndDFElement(pDmTndDFElement);
        return rc;
    }

    while (pScanner->curtok->type != TOK_TAG_END) {
        VoidPtr_t pContent = smlLibMalloc(10);
        if ( pContent == NULL )
        {
            smlFreeDmTndDFElement(pDmTndDFElement);
            return SML_ERR_NOT_ENOUGH_SPACE;
        }
        smlLibMemset(pContent, 0, 10);

        switch (pScanner->curtok->tagid) {
          /* AccessType Elements */
          case TN_DMTND_Add:
             smlLibStrcpy(pContent, "Add");
             break;
          case TN_DMTND_Copy:
             smlLibStrcpy(pContent, "Copy");
             break;
          case TN_DMTND_Delete:
             smlLibStrcpy(pContent, "Delete");
             break;
          case TN_DMTND_Exec:
             smlLibStrcpy(pContent, "Exec");
             break;
          case TN_DMTND_Get:
             smlLibStrcpy(pContent, "Get");
             break;
          case TN_DMTND_Replace:
             smlLibStrcpy(pContent, "Replace");
             break;
          /* Occurrence Elements */
          case TN_DMTND_One:
             smlLibStrcpy(pContent, "One");
             break;
          case TN_DMTND_ZeroOrOne:
             smlLibStrcpy(pContent, "ZeroOrOne");
             break;
          case TN_DMTND_ZeroOrMore:
             smlLibStrcpy(pContent, "ZeroOrMore");
             break;
          case TN_DMTND_OneOrMore:
             smlLibStrcpy(pContent, "OneOrMore");
             break;
          case TN_DMTND_ZeroOrN:
             smlLibStrcpy(pContent, "ZeroOrN");
             break;
          case TN_DMTND_OneOrN:
             smlLibStrcpy(pContent, "OneOrN");
             break;
          /* Scope Elements */
          case TN_DMTND_Permanent:
             smlLibStrcpy(pContent, "Permanent");
             break;
          case TN_DMTND_Dynamic:
             smlLibStrcpy(pContent, "Dynamic");
             break;
          /* CaseSense Elements */
          case TN_DMTND_CS:
             smlLibStrcpy(pContent, "CS");
             break;
          case TN_DMTND_CIS:
             smlLibStrcpy(pContent, "CIS");
             break;
          default:
              KCDBG(">>>>> buildDmTndDFElementCmd: Unkown token: %d <<<<<\n", pScanner->curtok->tagid);
              rc = SML_ERR_XLT_INVAL_SYNCML_DOC;
        }
        if (rc != SML_ERR_OK) {
            smlFreeDmTndDFElement(pDmTndDFElement);
            return rc;
        }
        if (((rc = nextToken(pDecoder)) != SML_ERR_OK)) {
            smlFreeDmTndDFElement(pDmTndDFElement);
            return rc;
        }
        if (pScanner->curtok->type != TOK_TAG_END) {
            smlFreeDmTndDFElement(pDmTndDFElement);
            return SML_ERR_XLT_INVAL_SYNCML_DOC;
        }
    }

    *ppElem = pDmTndDFElement;

    return SML_ERR_OK;
}