"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "minimessage/MiniMessage.c" between
muscle8.20.zip and muscle8.30.zip

About: MUSCLE (Multi User Server Client Linking Environment) is a messaging server and networking API. The included server program ("muscled") lets its clients message each other, and/or store information in its serverside hierarchical database.

MiniMessage.c  (muscle8.20):MiniMessage.c  (muscle8.30)
skipping to change at line 30 skipping to change at line 30
#endif #endif
static uint32 _allocedBytes = 0; /* for memory-leak debugging */ static uint32 _allocedBytes = 0; /* for memory-leak debugging */
uint32 MGetNumBytesAllocated() {return _allocedBytes;} uint32 MGetNumBytesAllocated() {return _allocedBytes;}
#ifdef MUSCLE_ENABLE_MEMORY_TRACKING #ifdef MUSCLE_ENABLE_MEMORY_TRACKING
void * MMalloc(uint32 numBytes) void * MMalloc(uint32 numBytes)
{ {
char * ret = (char *) malloc(numBytes+sizeof(uint32)); char * ret = (char *) malloc(sizeof(uint32)+numBytes);
if (ret) if (ret)
{ {
memcpy(ret, &numBytes, sizeof(numBytes)); memcpy(ret, &numBytes, sizeof(numBytes));
_allocedBytes += numBytes; _allocedBytes += numBytes;
/*printf("++" UINT32_FORMAT_SPEC " -> " UINT32_FORMAT_SPEC "\n", numBytes, _allo cedBytes);*/ /*printf("++" UINT32_FORMAT_SPEC " -> " UINT32_FORMAT_SPEC "\n", numBytes, _allo cedBytes);*/
return ret+sizeof(uint32); return ret+sizeof(uint32);
} }
return NULL; return NULL;
} }
void MFree(void * ptr) void MFree(void * ptr)
{ {
if (ptr) if (ptr)
{ {
char * rawPtr = ptr-sizeof(uint32); char * rawPtr = ((char *)ptr)-sizeof(uint32);
uint32 allocSize; memcpy(&allocSize, rawPtr, sizeof(allocSize)); uint32 allocSize; memcpy(&allocSize, rawPtr, sizeof(allocSize));
_allocedBytes -= allocSize; _allocedBytes -= allocSize;
/*printf("--" UINT32_FORMAT_SPEC " -> " UINT32_FORMAT_SPEC "\n", allocSize, _all ocedBytes);*/ /*printf("--" UINT32_FORMAT_SPEC " -> " UINT32_FORMAT_SPEC "\n", allocSize, _all ocedBytes);*/
free(rawPtr); free(rawPtr);
} }
} }
void * MRealloc(void * oldBuf, uint32 newSize) void * MRealloc(void * oldBuf, uint32 newSize)
{ {
uint32 oldSize; uint32 oldSize;
if (oldBuf) memcpy(&oldSize, oldBuf-sizeof(uint32), sizeof(oldSize)); if (oldBuf) memcpy(&oldSize, ((char *)oldBuf)-sizeof(uint32), sizeof(oldSize) );
else oldSize = 0; else oldSize = 0;
if (newSize == oldSize) return oldBuf; if (newSize == oldSize) return oldBuf;
else else
{ {
void * newBuf = (newSize > 0) ? MMalloc(newSize) : NULL; void * newBuf = (newSize > 0) ? MMalloc(newSize) : NULL;
if ((newSize > 0)&&(newBuf == NULL)) return NULL; // out-of-memory error! Avoid side effects if ((newSize > 0)&&(newBuf == NULL)) return NULL; // out-of-memory error! Avoid side effects
if ((newBuf)&&(oldBuf)) memcpy(newBuf, oldBuf, (newSize<oldSize)?newSize:o ldSize); if ((newBuf)&&(oldBuf)) memcpy(newBuf, oldBuf, (newSize<oldSize)?newSize:o ldSize);
if (oldBuf) MFree(oldBuf); if (oldBuf) MFree(oldBuf);
skipping to change at line 648 skipping to change at line 648
/* Write entry data length */ /* Write entry data length */
{ {
const uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(GetMMessageFieldFl attenedSize(f, MFalse)); const uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(GetMMessageFieldFl attenedSize(f, MFalse));
WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByteOrder )); WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByteOrder ));
} }
/* Write entry data */ /* Write entry data */
if (IsTypeCodeVariableSize(f->typeCode)) if (IsTypeCodeVariableSize(f->typeCode))
{ {
const uint32 numItems = f->numItems; const uint32 numItems = f->numItems;
uint32 i;
if (f->typeCode == B_MESSAGE_TYPE) if (f->typeCode == B_MESSAGE_TYPE)
{ {
/* Note that NULL entries will be flattened as empty Messages, since th e protocol doesn't support them directly. */ /* Note that NULL entries will be flattened as empty Messages, since th e protocol doesn't support them directly. */
/* Note also that for this type the number-of-items-in-array field is N OT written into the buffer (sigh) */ /* Note also that for this type the number-of-items-in-array field is N OT written into the buffer (sigh) */
const MMessage ** msgs = (const MMessage **) f->data; const MMessage ** msgs = (const MMessage **) f->data;
uint32 i;
for (i=0; i<numItems; i++) for (i=0; i<numItems; i++)
{ {
const MMessage * subMsg = msgs[i]; const MMessage * subMsg = msgs[i];
const uint32 msgSize = subMsg ? MMGetFlattenedSize(subMsg) : (3*s izeof(uint32)); const uint32 msgSize = subMsg ? MMGetFlattenedSize(subMsg) : (3*s izeof(uint32));
uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(msgSize); uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(msgSize);
WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByt eOrder)); WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByt eOrder));
if (subMsg) if (subMsg)
{ {
MMFlattenMessage(subMsg, &buffer[writeOffset]); writeOffset += ms gSize; MMFlattenMessage(subMsg, &buffer[writeOffset]); writeOffset += ms gSize;
} }
skipping to change at line 689 skipping to change at line 689
/* Write number of entries (zero) */ /* Write number of entries (zero) */
networkByteOrder = B_HOST_TO_LENDIAN_INT32(0); networkByteOrder = B_HOST_TO_LENDIAN_INT32(0);
WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(network ByteOrder)); WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(network ByteOrder));
} }
} }
} }
else else
{ {
const MByteBuffer ** bufs = (const MByteBuffer **) f->data; const MByteBuffer ** bufs = (const MByteBuffer **) f->data;
int i;
/* Write the number of items in the array */ /* Write the number of items in the array */
{ {
const uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(numItems); const uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(numItems);
WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByt eOrder)); WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByt eOrder));
} }
uint32 i;
for (i=0; i<numItems; i++) for (i=0; i<numItems; i++)
{ {
const uint32 bufSize = bufs[i] ? bufs[i]->numBytes : 0; const uint32 bufSize = bufs[i] ? bufs[i]->numBytes : 0;
const uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(bufSize); const uint32 networkByteOrder = B_HOST_TO_LENDIAN_INT32(bufSize);
WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByt eOrder)); WriteData(buffer, &writeOffset, &networkByteOrder, sizeof(networkByt eOrder));
memcpy(&buffer[writeOffset], &bufs[i]->bytes, bufSize); writeOffset += bufSize; memcpy(&buffer[writeOffset], &bufs[i]->bytes, bufSize); writeOffset += bufSize;
} }
} }
} }
else else
skipping to change at line 813 skipping to change at line 813
{ {
if (BYTE_ORDER != LITTLE_ENDIAN) SwapCopy(field->data, dataPtr, numItems*( itemSize/swapSize), swapSize); if (BYTE_ORDER != LITTLE_ENDIAN) SwapCopy(field->data, dataPtr, numItems*( itemSize/swapSize), swapSize);
else memcpy(field->data, dataPtr, numItems*i temSize); else memcpy(field->data, dataPtr, numItems*i temSize);
return field; return field;
} }
return NULL; return NULL;
} }
c_status_t MMUnflattenMessage(MMessage * msg, const void * inBuf, uint32 inputBu fferBytes) c_status_t MMUnflattenMessage(MMessage * msg, const void * inBuf, uint32 inputBu fferBytes)
{ {
uint32 i, readOffset = 0; uint32 readOffset = 0;
const uint8 * buffer = (const uint8 *) inBuf; const uint8 * buffer = (const uint8 *) inBuf;
/* Read and check protocol version number */ /* Read and check protocol version number */
uint32 networkByteOrder, numEntries; uint32 networkByteOrder, numEntries;
{ {
uint32 messageProtocolVersion; uint32 messageProtocolVersion;
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != CB_NO_ERROR) return CB_ERROR; if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != CB_NO_ERROR) return CB_ERROR;
messageProtocolVersion = B_LENDIAN_TO_HOST_INT32(networkByteOrder); messageProtocolVersion = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
if ((messageProtocolVersion < OLDEST_SUPPORTED_PROTOCOL_VERSION)||(message ProtocolVersion > CURRENT_PROTOCOL_VERSION)) return CB_ERROR; if ((messageProtocolVersion < OLDEST_SUPPORTED_PROTOCOL_VERSION)||(message ProtocolVersion > CURRENT_PROTOCOL_VERSION)) return CB_ERROR;
skipping to change at line 837 skipping to change at line 837
msg->what = B_LENDIAN_TO_HOST_INT32(networkByteOrder); msg->what = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
/* Read number of entries */ /* Read number of entries */
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != CB_NO_ERROR) return CB_ERROR; if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != CB_NO_ERROR) return CB_ERROR;
numEntries = B_LENDIAN_TO_HOST_INT32(networkByteOrder); numEntries = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
} }
MMClearMessage(msg); MMClearMessage(msg);
/* Read entries */ /* Read entries */
uint32 i;
for (i=0; i<numEntries; i++) for (i=0; i<numEntries; i++)
{ {
const char * fieldName; const char * fieldName;
uint32 nameLength, tc, eLength; uint32 nameLength, tc, eLength;
MMessageField * newField = NULL; MMessageField * newField = NULL;
MBool doAddField = MTrue; MBool doAddField = MTrue;
const uint8 * dataPtr; const uint8 * dataPtr;
/* Read entry name length */ /* Read entry name length */
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != CB_NO_ERROR) return CB_ERROR; if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != CB_NO_ERROR) return CB_ERROR;
skipping to change at line 920 skipping to change at line 921
else MMFreeMessage(newMsg); else MMFreeMessage(newMsg);
} }
} }
} }
} }
if (ret == CB_NO_ERROR) if (ret == CB_NO_ERROR)
{ {
MMessage ** newMsgField = MMPutMessageField(msg, MFalse, fieldNam e, listLength); MMessage ** newMsgField = MMPutMessageField(msg, MFalse, fieldNam e, listLength);
if (newMsgField) if (newMsgField)
{ {
uint32 i; uint32 j;
for (i=0; i<listLength; i++) for (j=0; j<listLength; j++)
{ {
newMsgField[i] = head; newMsgField[j] = head;
head = head->scratch; head = head->scratch;
} }
doAddField = MFalse; doAddField = MFalse;
} }
else ret = CB_ERROR; else ret = CB_ERROR;
} }
if (ret != CB_NO_ERROR) if (ret != CB_NO_ERROR)
{ {
/* Clean up on error */ /* Clean up on error */
while(head) while(head)
skipping to change at line 965 skipping to change at line 966
uint32 numItems; uint32 numItems;
uint32 eOffset = readOffset; uint32 eOffset = readOffset;
if (ReadData(buffer, inputBufferBytes, &eOffset, &numItems, sizeof(n umItems)) == CB_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &eOffset, &numItems, sizeof(n umItems)) == CB_NO_ERROR)
{ {
MByteBuffer ** bufs; MByteBuffer ** bufs;
numItems = B_LENDIAN_TO_HOST_INT32(numItems); numItems = B_LENDIAN_TO_HOST_INT32(numItems);
bufs = PutMMVariableFieldAux(msg, MFalse, tc, fieldName, numItems ); bufs = PutMMVariableFieldAux(msg, MFalse, tc, fieldName, numItems );
if (bufs) if (bufs)
{ {
uint32 eLeft = eLength; uint32 eLeft = eLength;
uint32 i;
doAddField = MFalse; doAddField = MFalse;
for (i=0; i<numItems; i++) uint32 j=0;
for (j=0; j<numItems; j++)
{ {
uint32 itemSize; uint32 itemSize;
MBool ok = MFalse; MBool ok = MFalse;
if (ReadData(buffer, inputBufferBytes, &eOffset, &itemSize, sizeof(itemSize)) == CB_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &eOffset, &itemSize, sizeof(itemSize)) == CB_NO_ERROR)
{ {
itemSize = B_LENDIAN_TO_HOST_INT32(itemSize); itemSize = B_LENDIAN_TO_HOST_INT32(itemSize);
if ((itemSize+sizeof(uint32) <= eLeft)&&((bufs[i] = MBAl locByteBuffer(itemSize, MFalse)) != NULL)) if ((itemSize+sizeof(uint32) <= eLeft)&&((bufs[j] = MBAl locByteBuffer(itemSize, MFalse)) != NULL))
{ {
eLeft -= (itemSize + sizeof(uint32)); eLeft -= (itemSize + sizeof(uint32));
memcpy(&bufs[i]->bytes, &buffer[eOffset], itemSize); memcpy(&bufs[j]->bytes, &buffer[eOffset], itemSize);
eOffset += itemSize; eOffset += itemSize;
ok = true; ok = true;
} }
} }
if (ok == MFalse) if (ok == MFalse)
{ {
MMRemoveField(msg, fieldName); MMRemoveField(msg, fieldName);
return CB_ERROR; return CB_ERROR;
} }
} }
 End of changes. 15 change blocks. 
13 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)