📄 mfieldp.c
字号:
if (tmpHeaderPos != NULL)
{
bufSize -= (UINT32)(tmpHeaderPos - headerStart);
}
headerStart = tmpHeaderPos;
}
}
}
return headerStart;
}
static unsigned char *parseContentIdLocation(unsigned char *headerStart,
UINT32 bufSize, MmsEntryHeader *entryHeader)
{
UINT32 valueSize = 0;
UINT32 useSize = 0;
memset( entryHeader, 0, sizeof(MmsEntryHeader));
if ((SKIP_HIGH_BIT(*headerStart) == MMS_WELL_KNOWN_CONTENT_ID) ||
(SKIP_HIGH_BIT(*headerStart) == MMS_WELL_KNOWN_CONTENT_LOCATION))
{
entryHeader->headerType = (MmsEntryHeaderValueType)SKIP_HIGH_BIT(*headerStart);
++headerStart;
--bufSize;
valueSize = cmnStrnlen((char *)headerStart, bufSize);
if (valueSize >= bufSize)
{
MMS_LOG_I(("%s(%d): Error parsing Content-ID or Content-Location. "
"(%d, %d)\n", __FILE__, __LINE__, valueSize, bufSize));
headerStart = NULL;
}
else
{
if (valueSize <= MAX_MMS_ENTRY_HEADER_VALUE_LEN)
{
useSize = valueSize;
}
else
{
#if MMS_USE_MAX_ENTRY_HEADER
useSize = MAX_MMS_ENTRY_HEADER_VALUE_LEN;
#else
MMS_LOG_I(("%s(%d): Content-ID or Content-Location larger "
"than MAX (%d, %d)\n", __FILE__, __LINE__,
valueSize, bufSize));
return NULL;
#endif
}
entryHeader->value.wellKnownFieldName = M_CALLOC(useSize + 1);
if (entryHeader->headerType == MMS_WELL_KNOWN_CONTENT_ID)
{
copyString( entryHeader->value.wellKnownFieldName,
headerStart, useSize);
}
else
{
strncpy((char *)entryHeader->value.wellKnownFieldName,
(char *)headerStart, useSize);
}
headerStart += valueSize + 1;
bufSize -= valueSize + 1;
}
}
return headerStart;
}
unsigned char *parseContentType( MmsContentType **contType,
const unsigned char *contentTypeData, UINT32 length)
{
unsigned char *cPtr;
unsigned char value = 0;
MmsContentType *cType;
INT32 paramLen;
UINT32 cLen;
UINT32 tempLen = 0;
cPtr = (unsigned char *)contentTypeData;
paramLen = 0;
*contType = NULL;
if (cPtr == NULL)
{
MMS_LOG_I(("%s(%d): illegal indata\n", __FILE__, __LINE__));
return NULL;
}
*contType = M_CALLOC( sizeof(MmsContentType));
cType = *contType;
if (IS_SHORT_INTEGER(*cPtr))
{
value = SKIP_HIGH_BIT( *cPtr);
cPtr++;
cType->knownValue = convertToMmsKnownMediaType( (UINT32)value);
cType->strValue = NULL;
cType->params = NULL;
}
else if (IS_EXTENSION_MEDIA(*cPtr))
{
cType->knownValue = MMS_VALUE_AS_STRING;
tempLen = strlen( (const char *)cPtr) + 1;
cType->strValue = M_ALLOC( tempLen);
strcpy( (char *)cType->strValue, (char *)cPtr);
cType->params = NULL;
cPtr += strlen( (const char *)cPtr) + 1;
}
else if (IS_VALUE_LENGTH(*cPtr))
{
cPtr = (unsigned char *)cnvValueLengthToUint32( (void *)cPtr, &cLen, length);
if (cPtr == NULL || cPtr > contentTypeData + length)
{
MMS_LOG_I(("%s(%d): Unable to convert size\n", __FILE__, __LINE__));
freeMmsContentType( *contType);
M_FREE( *contType);
*contType = NULL;
return NULL;
}
else if (IS_SHORT_INTEGER(*cPtr))
{
value = SKIP_HIGH_BIT(*cPtr);
cPtr++;
cType->knownValue = convertToMmsKnownMediaType( (UINT32)value);
cType->strValue = NULL;
paramLen = (INT32)cLen - 1;
}
else
{
UINT32 len = strlen( (const char *)cPtr) + 1;
cType->knownValue = MMS_VALUE_AS_STRING;
cType->strValue = M_CALLOC(len);
memcpy( cType->strValue, cPtr, len);
cPtr += len;
paramLen = (INT32)(cLen - len);
}
if (paramLen > 0)
{
if ( parseParams( cPtr, (UINT32)paramLen, &cType->params) == NULL)
{
MMS_LOG_I(("%s(%d): Unable to parse ContentType params",
__FILE__, __LINE__));
freeMmsContentType( *contType);
M_FREE( *contType);
*contType = NULL;
cPtr = NULL;
}
else
{
cPtr += paramLen;
}
}
}
return cPtr;
}
MmsElementDescriptor *parseElementDescriptor(unsigned char *startBuf, INT32 size)
{
UINT32 len = 0;
UINT32 strLen = 0;
unsigned char *buf = startBuf;
MmsElementDescriptor *ed = NULL;
buf = (unsigned char *)cnvValueLengthToUint32( buf, &len, (UINT32)size);
if (buf == NULL || len == 0)
{
MMS_LOG_I(("%s(%d): Illegal ElementDescriptor, len=%lu, buf=%d\n",
__FILE__, __LINE__, len, buf));
return NULL;
}
size -= (INT32)(buf - startBuf);
if (size < 0 || (UINT32)size < len)
{
MMS_LOG_I(("%s(%d): Illegal ElementDescriptor, len=%lu, size=%ld\n",
__FILE__, __LINE__, len, size));
return NULL;
}
strLen = cmnStrnlen( (char *)buf, len) + 1;
if (strLen > len || buf[strLen - 1] != EOS)
{
MMS_LOG_I(("%s(%d): Incorrect Content-reference-value, len=%lu, strLen=%lu\n",
__FILE__, __LINE__, len, strLen));
return NULL;
}
ed = M_ALLOC(sizeof(MmsElementDescriptor));
ed->contentReference = M_CALLOC(strLen);
strcpy( ed->contentReference, (char *)buf);
buf += strLen;
len -= strLen;
if (len > 0)
{
if ( parseParamsEnc( buf, len, &ed->params) == NULL)
{
MMS_LOG_I(("%s(%d): Unable to parse X-Mms-Element-Descriptor params",
__FILE__, __LINE__));
freeMmsParamsEnc(ed->params);
M_FREE(ed);
ed = NULL;
}
}
return ed;
}
void parseEncodedStringValue( unsigned char *buf, UINT32 size,
UINT32 *lengthOfString, MmsEncodedText *eText)
{
unsigned char *tmpPtr;
UINT32 length = 0;
UINT32 charset;
MmsEncodedText *tmpText;
*lengthOfString = 0;
eText->charset = CMN_CHARSET_UNKNOWN;
eText->text = NULL;
if (buf == NULL || *buf > TEXT_QUOTE)
{
MMS_LOG_I(("%s(%d): Illegal EncodedStringValue %d\n",
__FILE__, __LINE__, buf == NULL ? 0 : *buf));
return;
}
if (IS_TEXT_STRING(*buf))
{
length = cmnStrnlen((const char *)buf, size) + 1;
if (length > 0 && IS_TEXT_QUOTE(*buf))
{
++buf;
--length;
}
eText->charset = CMN_CHARSET_UTF_8;
eText->text = (char *)M_CALLOC(length);
memcpy( eText->text, (const char *)buf, length - 1);
*lengthOfString = length;
}
else
{
buf = (unsigned char *)cnvValueLengthToUint32( (void *)buf, &length, size);
if (buf == NULL || length == 0 || length > size)
{
MMS_LOG_I(("%s(%d): Illegal EncodedStringValue, length=%d, buf=%d\n",
__FILE__, __LINE__, length, buf));
return;
}
if (IS_SHORT_INTEGER(*buf))
{
charset = (UINT32)*buf++;
--length;
eText->charset = (CmnCharset)SKIP_HIGH_BIT( (unsigned char)charset);
}
else
{
tmpPtr = cnvLongIntegerToUint32( (void *)buf, &charset, size);
if (tmpPtr == NULL)
{
MMS_LOG_I(("%s(%d): Error converting charset as Long-integer\n",
__FILE__, __LINE__));
eText->charset = (CmnCharset)0;
length = 0;
}
else
{
eText->charset = (CmnCharset)charset;
length -= (UINT32)(tmpPtr - buf);
buf = tmpPtr;
}
}
if (length > 0 && IS_TEXT_QUOTE(buf[0]))
{
++buf;
--length;
}
if (length > 0)
{
eText->text = M_CALLOC((unsigned int)length + 2);
memcpy( eText->text, buf, (unsigned int)length);
if ((tmpText = charsetCvtEncodedString( eText, length)) != NULL)
{
M_FREE( eText->text);
eText->text = tmpText->text;
eText->charset = tmpText->charset;
M_FREE( tmpText);
length = strlen( eText->text);
}
}
*lengthOfString = length;
}
return;
}
unsigned char *parseEntryHeader(unsigned char *headerStart, UINT32 bufSize,
MmsBodyInfoList *entryHeaderList)
{
unsigned char *headerPos = headerStart;
unsigned char *tmpHeaderPos;
UINT32 valueSize = 0;
UINT32 remainingSize;
MmsEntryHeader *current = NULL;
MmsEntryHeader *previous = NULL;
if (headerStart == NULL || entryHeaderList == NULL)
{
return NULL;
}
entryHeaderList->entryHeader = NULL;
remainingSize = bufSize;
while (headerPos != NULL && remainingSize > 0 && remainingSize <= bufSize)
{
if (entryHeaderList->entryHeader == NULL)
{
entryHeaderList->entryHeader = M_CALLOC( sizeof(MmsEntryHeader));
current = entryHeaderList->entryHeader;
}
else if (current != NULL)
{
current->next = M_CALLOC(sizeof(MmsEntryHeader));
previous = current;
current = current->next;
}
else
{
MMS_LOG_I(("%s(%d): Pointer lost its value? %d \n",
__FILE__, __LINE__, current));
return NULL;
}
current->next = NULL;
current->value.applicationHeader.value = NULL;
if (IS_SHIFT_DELIMITER(*headerPos))
{
current->headerType = MMS_SHORT_CUT_SHIFT_DELIMITER;
current->value.shortCutShiftDelimiter = *headerPos;
++headerPos;
--remainingSize;
}
else if (IS_APPLICATION_HEADER(*headerPos))
{
current->headerType = MMS_APPLICATION_HEADER;
valueSize = cmnStrnlen( (char *)headerPos, remainingSize);
if (valueSize < remainingSize &&
valueSize <= MAX_MMS_ENTRY_HEADER_VALUE_LEN)
{
current->value.applicationHeader.name = M_CALLOC(valueSize + 1);
strncpy((char *)current->value.applicationHeader.name,
(char *)headerPos, valueSize);
headerPos += valueSize + 1;
remainingSize -= valueSize + 1;
}
else
{
current->value.applicationHeader.name = NULL;
return NULL;
}
valueSize = cmnStrnlen( (char *)headerPos, remainingSize);
if (valueSize < remainingSize &&
valueSize <= MAX_MMS_ENTRY_HEADER_VALUE_LEN)
{
current->value.applicationHeader.value = M_CALLOC(valueSize + 1);
strncpy((char *)current->value.applicationHeader.value,
(char *)headerPos, valueSize);
headerPos += valueSize + 1;
remainingSize -= valueSize + 1;
}
else
{
current->value.applicationHeader.value = NULL;
return NULL;
}
}
else if (IS_SHIFT_DELIMITER(*headerPos))
{
current->headerType = MMS_SHIFT_DELIMITER;
++headerPos;
--remainingSize;
current->value.shiftDelimiter = *headerPos;
++headerPos;
--remainingSize;
}
else if ((SKIP_HIGH_BIT(*headerPos) == MMS_WELL_KNOWN_CONTENT_ID) ||
(SKIP_HIGH_BIT(*headerPos) == MMS_WELL_KNOWN_CONTENT_LOCATION))
{
tmpHeaderPos = parseContentIdLocation( headerPos, remainingSize, current);
if (tmpHeaderPos != NULL)
{
remainingSize -= (UINT32)(tmpHeaderPos - headerPos);
}
headerPos = tmpHeaderPos;
}
else if (SKIP_HIGH_BIT(*headerPos) == MMS_WELL_KNOWN_CONTENT_DISPOSITION)
{
tmpHeaderPos = parseContentDisposition( headerPos, remainingSize, current);
if (tmpHeaderPos != NULL)
{
remainingSize -= (UINT32)(tmpHeaderPos - headerPos);
}
headerPos = tmpHeaderPos;
}
else
{
MMS_LOG_I(("%s(%d): INFO: Unsupported well-known field name found.\n",
__FILE__, __LINE__));
if (previous == NULL)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -