static void appendErrorToResultList(LinkedList values, uint32_t errorCode) { MmsValue* value = MmsValue_newDataAccessError(errorCode); MmsValue_setDeletable(value); appendValueToResultList(value, values); }
MmsIndication mmsClient_parseWriteMultipleItemsResponse(ByteBuffer* message, int itemCount, LinkedList* accessResults) { MmsPdu_t* mmsPdu = 0; MmsIndication retVal = MMS_OK; asn_dec_rval_t rval; rval = ber_decode(NULL, &asn_DEF_MmsPdu, (void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message)); if (rval.code != RC_OK) { retVal = MMS_ERROR; goto cleanUp; } if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_write) { WriteResponse_t* response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.write); if (response->list.count == itemCount) { int i; *accessResults = LinkedList_create(); for (i = 0; i < itemCount; i++) { MmsValue* value; if (response->list.array[i]->present == WriteResponse__Member_PR_success) { MmsDataAccessError error; value = MmsValue_newDataAccessError(DATA_ACCESS_ERROR_SUCCESS); } else { long errorCode; asn_INTEGER2long(&response->list.array[i]->choice.failure, &errorCode); value = MmsValue_newDataAccessError((MmsDataAccessError) errorCode); } LinkedList_add(*accessResults, (void*) value); } } else retVal = MMS_ERROR; } else { retVal = MMS_ERROR; } } else { retVal = MMS_ERROR; } cleanUp: asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return retVal; }
MmsValue* mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSize, bool createArray) { MmsValue* valueList = NULL; MmsValue* value = NULL; int elementCount = listSize; if ((elementCount > 1) || createArray) valueList = MmsValue_createEmptyArray(elementCount); int i = 0; for (i = 0; i < elementCount; i++) { AccessResult_PR presentType = accessResultList[i]->present; if (presentType == AccessResult_PR_failure) { if (DEBUG_MMS_CLIENT) printf("access error!\n"); if (accessResultList[i]->choice.failure.size > 0) { int errorCode = (int) accessResultList[i]->choice.failure.buf[0]; MmsDataAccessError dataAccessError = DATA_ACCESS_ERROR_UNKNOWN; if ((errorCode >= 0) && (errorCode < 12)) dataAccessError = (MmsDataAccessError) errorCode; value = MmsValue_newDataAccessError(dataAccessError); } else value = MmsValue_newDataAccessError(DATA_ACCESS_ERROR_UNKNOWN); } else if (presentType == AccessResult_PR_array) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_ARRAY; int arrayElementCount = accessResultList[i]->choice.array.list.count; value->value.structure.size = arrayElementCount; value->value.structure.components = (MmsValue**) GLOBAL_CALLOC(arrayElementCount, sizeof(MmsValue*)); int j; for (j = 0; j < arrayElementCount; j++) { value->value.structure.components[j] = mmsMsg_parseDataElement( accessResultList[i]->choice.array.list.array[j]); } } else if (presentType == AccessResult_PR_structure) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_STRUCTURE; int componentCount = accessResultList[i]->choice.structure.list.count; value->value.structure.size = componentCount; value->value.structure.components = (MmsValue**) GLOBAL_CALLOC(componentCount, sizeof(MmsValue*)); int j; for (j = 0; j < componentCount; j++) { value->value.structure.components[j] = mmsMsg_parseDataElement( accessResultList[i]->choice.structure.list.array[j]); } } else if (presentType == AccessResult_PR_bitstring) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_BIT_STRING; int size = accessResultList[i]->choice.bitstring.size; value->value.bitString.size = (size * 8) - accessResultList[i]->choice.bitstring.bits_unused; value->value.bitString.buf = (uint8_t*) GLOBAL_MALLOC(size); memcpy(value->value.bitString.buf, accessResultList[i]->choice.bitstring.buf, size); } else if (presentType == AccessResult_PR_integer) { Asn1PrimitiveValue* berInteger = BerInteger_createFromBuffer(accessResultList[i]->choice.integer.buf, accessResultList[i]->choice.integer.size); value = MmsValue_newIntegerFromBerInteger(berInteger); } else if (presentType == AccessResult_PR_unsigned) { Asn1PrimitiveValue* berInteger = BerInteger_createFromBuffer(accessResultList[i]->choice.Unsigned.buf, accessResultList[i]->choice.Unsigned.size); value = MmsValue_newUnsignedFromBerInteger(berInteger); } else if (presentType == AccessResult_PR_floatingpoint) { int size = accessResultList[i]->choice.floatingpoint.size; value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_FLOAT; if (size == 5) { /* FLOAT32 */ value->value.floatingPoint.formatWidth = 32; value->value.floatingPoint.exponentWidth = accessResultList[i]->choice.floatingpoint.buf[0]; uint8_t* floatBuf = (accessResultList[i]->choice.floatingpoint.buf + 1); value->value.floatingPoint.buf = (uint8_t*) GLOBAL_MALLOC(4); #if (ORDER_LITTLE_ENDIAN == 1) memcpyReverseByteOrder(value->value.floatingPoint.buf, floatBuf, 4); #else memcpy(value->value.floatingPoint.buf, floatBuf, 4); #endif } if (size == 9) { /* FLOAT64 */ value->value.floatingPoint.formatWidth = 64; value->value.floatingPoint.exponentWidth = accessResultList[i]->choice.floatingpoint.buf[0]; uint8_t* floatBuf = (accessResultList[i]->choice.floatingpoint.buf + 1); value->value.floatingPoint.buf = (uint8_t*) GLOBAL_MALLOC(8); #if (ORDER_LITTLE_ENDIAN == 1) memcpyReverseByteOrder(value->value.floatingPoint.buf, floatBuf, 8); #else memcpy(value->value.floatingPoint.buf, floatBuf, 8); #endif } } else if (presentType == AccessResult_PR_visiblestring) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_VISIBLE_STRING; int strSize = accessResultList[i]->choice.visiblestring.size; value->value.visibleString.buf = (char*) GLOBAL_MALLOC(strSize + 1); value->value.visibleString.size = strSize; memcpy(value->value.visibleString.buf, accessResultList[i]->choice.visiblestring.buf, strSize); value->value.visibleString.buf[strSize] = 0; } else if (presentType == AccessResult_PR_mMSString) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_STRING; int strSize = accessResultList[i]->choice.mMSString.size; value->value.visibleString.buf = (char*) GLOBAL_MALLOC(strSize + 1); value->value.visibleString.size = strSize; memcpy(value->value.visibleString.buf, accessResultList[i]->choice.mMSString.buf, strSize); value->value.visibleString.buf[strSize] = 0; } else if (presentType == AccessResult_PR_utctime) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_UTC_TIME; memcpy(value->value.utcTime, accessResultList[i]->choice.utctime.buf, 8); } else if (presentType == AccessResult_PR_boolean) { value = MmsValue_newBoolean(accessResultList[i]->choice.boolean); } else if (presentType == AccessResult_PR_binarytime) { int size = accessResultList[i]->choice.binarytime.size; if (size <= 6) { value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_BINARY_TIME; value->value.binaryTime.size = size; memcpy(value->value.binaryTime.buf, accessResultList[i]->choice.binarytime.buf, size); } } else if (presentType == AccessResult_PR_octetstring) { int size = accessResultList[i]->choice.octetstring.size; value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value->type = MMS_OCTET_STRING; value->value.octetString.maxSize = size; value->value.octetString.size = size; value->value.octetString.buf = (uint8_t*) GLOBAL_MALLOC(size); memcpy(value->value.octetString.buf, accessResultList[i]->choice.octetstring.buf, size); } else { printf("unknown type %i\n", presentType); value = MmsValue_newDataAccessError(DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID); } if ((elementCount > 1) || createArray) MmsValue_setElement(valueList, i, value); } if (valueList == NULL) valueList = value; return valueList; }
void mmsClient_parseWriteMultipleItemsResponse(ByteBuffer* message, int32_t bufPos, MmsError* mmsError, int itemCount, LinkedList* accessResults) { uint8_t* buf = message->buffer; int size = message->size; int length; *mmsError = MMS_ERROR_NONE; uint8_t tag = buf[bufPos++]; if (tag == 0xa5) { bufPos = BerDecoder_decodeLength(buf, &length, bufPos, size); if (bufPos == -1) { *mmsError = MMS_ERROR_PARSING_RESPONSE; return; } *accessResults = LinkedList_create(); int endPos = bufPos + length; int numberOfAccessResults = 0; while (bufPos < endPos) { tag = buf[bufPos++]; bufPos = BerDecoder_decodeLength(buf, &length, bufPos, size); if (bufPos == -1) goto exit_with_error; if (tag == 0x81) { MmsValue* value = MmsValue_newDataAccessError(DATA_ACCESS_ERROR_SUCCESS); LinkedList_add(*accessResults, (void*) value); } if (tag == 0x80) { uint32_t dataAccessErrorCode = BerDecoder_decodeUint32(buf, length, bufPos); MmsValue* value = MmsValue_newDataAccessError((MmsDataAccessError) dataAccessErrorCode); LinkedList_add(*accessResults, (void*) value); } bufPos += length; numberOfAccessResults++; } if (itemCount != numberOfAccessResults) goto exit_with_error; } else *mmsError = MMS_ERROR_PARSING_RESPONSE; return; exit_with_error: *mmsError = MMS_ERROR_PARSING_RESPONSE; LinkedList_destroyDeep(*accessResults, (LinkedListValueDeleteFunction) MmsValue_delete); }