int main(void) { LinkedList* list = LinkedList_new(); char* elem1 = "cat"; LinkedList_add(list, &elem1); char* elem2 = "rat"; LinkedList_add(list, &elem2); char* elem3 = "dog"; LinkedList_add(list, &elem3); char* elem4 = "sheep"; LinkedList_add(list, &elem4); char* elem5 = "goat"; LinkedList_add(list, &elem5); char* elem6 = "kebab"; LinkedList_add(list, &elem6); char* elem7 = "pig"; LinkedList_add(list, &elem7); char* elem8 = "cow"; LinkedList_add(list, &elem8); char* elem9 = "chicken"; LinkedList_add(list, &elem9); char* elem10 = "duck"; LinkedList_add(list, &elem10); char* elem11 = "fox"; LinkedList_add(list, &elem11); char* elem12 = "rabbit"; LinkedList_add(list, &elem12); char* elem13 = "mouse"; LinkedList_add(list, &elem13); char* elem14 = "hedgehog"; LinkedList_add(list, &elem14); printf("list before: \n"); for (int i = 0; i < LinkedList_size(list); i++) { if (LinkedList_get(list, i) != NULL) { printf("%d: %s \n", i, *(char**)LinkedList_get(list, i)); } } printf("\nremoving element 5, %s\n", *(char**)LinkedList_get(list, 5)); LinkedList_remove(list, 5); printf("\nlist after: \n"); for (int i = 0; i < LinkedList_size(list); i++) { if (LinkedList_get(list, i) != NULL) { printf("%d: %s \n", i, *(char**)LinkedList_get(list, i)); } } LinkedList_destroy(list); free(list); }
END_TEST START_TEST(test_SizeOfLinkedListIsOneAfterAddingAnElement) { LinkedList* list = LinkedList_new(); int elem = 1337; LinkedList_add(list, &elem); ck_assert_int_eq(LinkedList_size(list), 1); }
END_TEST START_TEST(test_StoringEvenMoreElementsToListWorks) { int i; for (i = 0; i < 10; i++) { LinkedList* list = LinkedList_new(); int elem1 = 1337; LinkedList_add(list, &elem1); char* elem2 = "theeta"; LinkedList_add(list, &elem2); int elem3 = 74; LinkedList_add(list, &elem3); char elem4 = 'a'; LinkedList_add(list, &elem4); int elem5 = 55; LinkedList_add(list, &elem5); int elem6 = 66; LinkedList_add(list, &elem6); int elem7 = 77; LinkedList_add(list, &elem7); int elem8 = 88; LinkedList_add(list, &elem8); int elem9 = 99; LinkedList_add(list, &elem9); int elem10 = 110; LinkedList_add(list, &elem10); int elem11 = 111; LinkedList_add(list, &elem11); int elem12 = 1212; LinkedList_add(list, &elem12); int elem13 = 1313; LinkedList_add(list, &elem13); int elem14 = 1414; LinkedList_add(list, &elem14); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 1337); ck_assert_str_eq(*(char**) LinkedList_get(list, 1), "theeta"); ck_assert_int_eq(*(int*) LinkedList_get(list, 2), 74); ck_assert_int_eq(*(char*) LinkedList_get(list, 3), 'a'); ck_assert_int_eq(*(int*) LinkedList_get(list, 9), 110); ck_assert_int_eq(*(int*) LinkedList_get(list, 10), 111); ck_assert_int_eq(*(int*) LinkedList_get(list, 11), 1212); ck_assert_int_eq(*(int*) LinkedList_get(list, 12), 1313); ck_assert_int_eq(*(int*) LinkedList_get(list, 13), 1414); ck_assert_int_eq(LinkedList_size(list), 14); } }
void MmsServer_sendInformationReportVarList(MmsServer self, char* domainId, char* itemId, LinkedList values) { int i; LinkedList value; AccessResult_t** accessResultList; int variableCount; InformationReport_t* report; MmsPdu_t* mmsPdu = calloc(1, sizeof(MmsPdu_t)); mmsPdu->present = MmsPdu_PR_unconfirmedPDU; mmsPdu->choice.unconfirmedPDU.unconfirmedService.present = UnconfirmedService_PR_informationReport; report = &(mmsPdu->choice.unconfirmedPDU.unconfirmedService.choice.informationReport); report->variableAccessSpecification.present = VariableAccessSpecification_PR_variableListName; if (domainId != NULL) { report->variableAccessSpecification.choice.variableListName.present = ObjectName_PR_domainspecific; report->variableAccessSpecification.choice.variableListName.choice.domainspecific.domainId.size = strlen(domainId); report->variableAccessSpecification.choice.variableListName.choice.domainspecific.domainId.buf = domainId; report->variableAccessSpecification.choice.variableListName.choice.domainspecific.itemId.size = strlen(itemId); report->variableAccessSpecification.choice.variableListName.choice.domainspecific.itemId.buf = itemId; } else { report->variableAccessSpecification.choice.variableListName.present = ObjectName_PR_vmdspecific; report->variableAccessSpecification.choice.variableListName.choice.vmdspecific.size = strlen(itemId); report->variableAccessSpecification.choice.variableListName.choice.vmdspecific.buf = itemId; } variableCount = LinkedList_size(values); accessResultList = mmsMsg_createAccessResultsList(mmsPdu, variableCount); /* iterate values list and add values to the accessResultList */ value = LinkedList_getNext(values); for (i = 0; i < variableCount; i++) { AccessResult_t* accessResult = accessResultList[i]; mmsMsg_addResultToResultList(accessResult, (MmsValue*) value->data); value = LinkedList_getNext(value); } report->listOfAccessResult.list.array = accessResultList; report->listOfAccessResult.list.size = variableCount; report->listOfAccessResult.list.count = variableCount; }
/** * Request multiple values of a single domain */ int mmsClient_createReadRequestMultipleValues(char* domainId, LinkedList items, ByteBuffer* writeBuffer) { MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(1); ReadRequest_t* readRequest = createReadRequest(mmsPdu); readRequest->specificationWithResult = NULL; int valuesCount = LinkedList_size(items); ListOfVariableSeq_t** listOfVars = createListOfVariables(readRequest, valuesCount); LinkedList item = items; char* itemId; int i = 0; while ((item = LinkedList_getNext(item)) != NULL) { itemId = (char*) (item->data); listOfVars[i] = createVariableIdentifier(domainId, itemId); i++; } asn_enc_rval_t rval; rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, mmsClient_write_out, (void*) writeBuffer); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); for (i = 0; i < valuesCount; i++) { free(listOfVars[i]); } free(listOfVars); readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0; readRequest->variableAccessSpecification.choice.listOfVariable.list.size = 0; readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL; asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return rval.encoded; }
void * LinkedList_remove_last(LinkedList ** self) { if (self == NULL) { return NULL; } int i; LinkedList * current; void * result = NULL; for (current = *self, i = 0; current != NULL && i < LinkedList_size(*self); current = current->next, i++) { result = current->val; } if (result != NULL) { *((*self)->size) -= 1; free(current); } return result; }
/** * Request multiple values of a single domain */ int mmsClient_createReadRequestMultipleValues(uint32_t invokeId, const char* domainId, LinkedList items, ByteBuffer* writeBuffer) { MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); ReadRequest_t* readRequest = createReadRequest(mmsPdu); readRequest->specificationWithResult = NULL; int valuesCount = LinkedList_size(items); ListOfVariableSeq_t** listOfVars = createListOfVariables(readRequest, valuesCount); LinkedList item = items; int i = 0; while ((item = LinkedList_getNext(item)) != NULL) { listOfVars[i] = createVariableIdentifier(domainId, (char*) (item->data)); i++; } asn_enc_rval_t rval; rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, (asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); for (i = 0; i < valuesCount; i++) { GLOBAL_FREEMEM(listOfVars[i]); } GLOBAL_FREEMEM(listOfVars); readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0; readRequest->variableAccessSpecification.choice.listOfVariable.list.size = 0; readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL; asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return rval.encoded; }
END_TEST START_TEST(test_StoringMultipleElementsToListWorks) { LinkedList* list = LinkedList_new(); int elem1 = 1337; LinkedList_add(list, &elem1); char* elem2 = "theeta"; LinkedList_add(list, &elem2); int elem3 = 74; LinkedList_add(list, &elem3); char elem4 = 'a'; LinkedList_add(list, &elem4); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 1337); ck_assert_str_eq(*(char**) LinkedList_get(list, 1), "theeta"); ck_assert_int_eq(*(int*) LinkedList_get(list, 2), 74); ck_assert_int_eq(*(char*) LinkedList_get(list, 3), 'a'); ck_assert_int_eq(LinkedList_size(list), 4); }
static void createNamedVariableListResponse(MmsServerConnection* connection, MmsNamedVariableList namedList, int invokeId, ByteBuffer* response, ReadRequest_t* read, VarAccessSpec* accessSpec) { LinkedList /*<MmsValue>*/ values = LinkedList_create(); LinkedList variables = MmsNamedVariableList_getVariableList(namedList); int variableCount = LinkedList_size(variables); MmsServer_lockModel(connection->server); int i; LinkedList variable = LinkedList_getNext(variables); for (i = 0; i < variableCount; i++) { MmsNamedVariableListEntry variableListEntry = (MmsNamedVariableListEntry) variable->data; MmsDomain* variableDomain = MmsNamedVariableListEntry_getDomain(variableListEntry); char* variableName = MmsNamedVariableListEntry_getVariableName(variableListEntry); MmsTypeSpecification* namedVariable = MmsDomain_getNamedVariable(variableDomain, variableName); addNamedVariableToResultList(namedVariable, variableDomain, variableName, values, connection, NULL); variable = LinkedList_getNext(variable); } if (isSpecWithResult(read)) /* add specification to result */ encodeReadResponse(connection, invokeId, response, values, accessSpec); else encodeReadResponse(connection, invokeId, response, values, NULL); MmsServer_unlockModel(connection->server); deleteValueList(values); }
END_TEST START_TEST(test_RemovingElementFromListWorks) { LinkedList* list = LinkedList_new(); int elem1 = 1337; LinkedList_add(list, &elem1); char* elem2 = "theeta"; LinkedList_add(list, &elem2); int elem3 = 74; LinkedList_add(list, &elem3); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 1337); ck_assert_str_eq(*(char**) LinkedList_get(list, 1), "theeta"); ck_assert_int_eq(*(int*) LinkedList_get(list, 2), 74); LinkedList_remove(list, 1); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 1337); ck_assert_int_eq(*(int*) LinkedList_get(list, 1), 74); ck_assert_int_eq(LinkedList_size(list), 2); }
int LinkedList_destroy_all_items(LinkedList ** list, destroy_f_ptr f_ptr) { if (*list == NULL || f_ptr == NULL) { return CDS_ILLEGAL_ARGUEMENT_EXCEPTION; } void * current = NULL; int size = LinkedList_size(*list); int i = 0; /* to prevent memory fragmentation remove last first. */ for (i = 1; i <= size; i++) { current = NULL; current = LinkedList_remove_last(list); if (current != NULL) { f_ptr(current); } } return CDS_OK; }
int mmsClient_createWriteMultipleItemsRequest(uint32_t invokeId, char* domainId, LinkedList itemIds, LinkedList values, ByteBuffer* writeBuffer) { MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = ConfirmedServiceRequest_PR_write; WriteRequest_t* request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.write); int numberOfItems = LinkedList_size(itemIds); /* Create list of variable specifications */ request->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable; request->variableAccessSpecification.choice.listOfVariable.list.count = numberOfItems; request->variableAccessSpecification.choice.listOfVariable.list.size = numberOfItems; request->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**) calloc(numberOfItems, sizeof(ListOfVariableSeq_t*)); /* Create list of data values */ request->listOfData.list.count = numberOfItems; request->listOfData.list.size = numberOfItems; request->listOfData.list.array = (Data_t**) calloc(numberOfItems, sizeof(struct Data*)); int i; LinkedList item = LinkedList_getNext(itemIds); LinkedList valueElement = LinkedList_getNext(values); for (i = 0; i < numberOfItems; i++) { if (item == NULL) return -1; if (valueElement == NULL) return -1; char* itemId = (char*) item->data; MmsValue* value = (MmsValue*) valueElement->data; request->variableAccessSpecification.choice.listOfVariable.list.array[i] = (ListOfVariableSeq_t*) createNewDomainVariableSpecification(domainId, itemId); request->listOfData.list.array[i] = mmsMsg_createBasicDataElement(value); item = LinkedList_getNext(item); } asn_enc_rval_t rval; rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, (asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); /* Free ASN structure */ request->variableAccessSpecification.choice.listOfVariable.list.count = 0; for (i = 0; i < numberOfItems; i++) { free(request->variableAccessSpecification.choice.listOfVariable.list.array[i]); deleteDataElement(request->listOfData.list.array[i]); } free(request->variableAccessSpecification.choice.listOfVariable.list.array); request->variableAccessSpecification.choice.listOfVariable.list.array = 0; request->listOfData.list.count = 0; free(request->listOfData.list.array); request->listOfData.list.array = 0; asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return rval.encoded; }
static void encodeReadResponse(MmsServerConnection* connection, uint32_t invokeId, ByteBuffer* response, LinkedList values, VarAccessSpec* accessSpec) { int i; int variableCount = LinkedList_size(values); int varAccessSpecSize = 0; if (accessSpec != NULL) { varAccessSpecSize = encodeVariableAccessSpecification(accessSpec, NULL, 0, false); } /* determine BER encoded message sizes */ int accessResultSize = 0; /* iterate values list to determine encoded size */ LinkedList value = LinkedList_getNext(values); for (i = 0; i < variableCount; i++) { MmsValue* data = (MmsValue*) value->data; accessResultSize += mmsServer_encodeAccessResult(data, NULL, 0, false); value = LinkedList_getNext(value); } int listOfAccessResultsLength = 1 + BerEncoder_determineLengthSize(accessResultSize) + accessResultSize; int confirmedServiceResponseContentLength = listOfAccessResultsLength + varAccessSpecSize; int confirmedServiceResponseLength = 1 + BerEncoder_determineLengthSize(confirmedServiceResponseContentLength) + confirmedServiceResponseContentLength; int invokeIdSize = BerEncoder_UInt32determineEncodedSize(invokeId) + 2; int confirmedResponseContentSize = confirmedServiceResponseLength + invokeIdSize; int mmsPduSize = 1 + BerEncoder_determineLengthSize(confirmedResponseContentSize) + confirmedResponseContentSize; /* Check if message would fit in the MMS PDU */ if (mmsPduSize > connection->maxPduSize) { if (DEBUG) printf("MMS read: message to large! send error PDU!\n"); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_TYPE_RESPONSE_EXCEEDS_MAX_PDU_SIZE); return; } /* encode message */ uint8_t* buffer = response->buffer; int bufPos = 0; /* confirmed response PDU */ bufPos = BerEncoder_encodeTL(0xa1, confirmedResponseContentSize, buffer, bufPos); /* invoke id */ bufPos = BerEncoder_encodeTL(0x02, invokeIdSize - 2, buffer, bufPos); bufPos = BerEncoder_encodeUInt32(invokeId, buffer, bufPos); /* confirmed-service-response read */ bufPos = BerEncoder_encodeTL(0xa4, confirmedServiceResponseContentLength, buffer, bufPos); /* encode variable access specification */ if (accessSpec != NULL) bufPos = encodeVariableAccessSpecification(accessSpec, buffer, bufPos, true); /* encode list of access results */ bufPos = BerEncoder_encodeTL(0xa1, accessResultSize, buffer, bufPos); /* encode access results */ value = LinkedList_getNext(values); for (i = 0; i < variableCount; i++) { MmsValue* data = (MmsValue*) value->data; bufPos = mmsServer_encodeAccessResult(data, buffer, bufPos, true); value = LinkedList_getNext(value); } response->size = bufPos; if (DEBUG) printf("MMS read: sent message for request with id %u (size = %i)\n", invokeId, bufPos); }
static void createGetNamedVariableListAttributesResponse(int invokeId, ByteBuffer* response, MmsNamedVariableList variableList, char* domainName) { char* variableDomainName; asn_enc_rval_t rval; int i; int variableCount; LinkedList variable; LinkedList variables; GetNamedVariableListAttributesResponse_t* varListResponse; MmsPdu_t* mmsPdu = mmsServer_createConfirmedResponse(invokeId); BOOLEAN_t moreFollows = 0; mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present = ConfirmedServiceResponse_PR_getNamedVariableListAttributes; varListResponse = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse. choice.getNamedVariableListAttributes); varListResponse->mmsDeletable = MmsNamedVariableList_isDeletable(variableList); variables = MmsNamedVariableList_getVariableList(variableList); variableCount = LinkedList_size(variables); varListResponse->listOfVariable.list.count = variableCount; varListResponse->listOfVariable.list.size = variableCount; varListResponse->listOfVariable.list.array = calloc(variableCount, sizeof(void*)); variable = LinkedList_getNext(variables); for (i = 0; i < variableCount; i++) { MmsNamedVariableListEntry variableEntry = (MmsNamedVariableListEntry) variable->data; varListResponse->listOfVariable.list.array[i] = calloc(1, sizeof(struct GetNamedVariableListAttributesResponse__listOfVariable__Member)); varListResponse->listOfVariable.list.array[i]->variableSpecification.present = VariableSpecification_PR_name; varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.present = ObjectName_PR_domainspecific; variableDomainName = MmsDomain_getName(variableEntry->domain); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.domainId.buf = copyString(variableDomainName); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.domainId.size = strlen(variableDomainName); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.itemId.buf = copyString(variableEntry->variableName); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.itemId.size = strlen(variableEntry->variableName); variable = LinkedList_getNext(variable); } rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, mmsServer_write_out, (void*) response); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); }
static void createGetNamedVariableListAttributesResponse(int invokeId, ByteBuffer* response, MmsNamedVariableList variableList) { MmsPdu_t* mmsPdu = mmsServer_createConfirmedResponse(invokeId); mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present = ConfirmedServiceResponse_PR_getNamedVariableListAttributes; GetNamedVariableListAttributesResponse_t* varListResponse = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse. choice.getNamedVariableListAttributes); varListResponse->mmsDeletable = MmsNamedVariableList_isDeletable(variableList); LinkedList variables = MmsNamedVariableList_getVariableList(variableList); int variableCount = LinkedList_size(variables); varListResponse->listOfVariable.list.count = variableCount; varListResponse->listOfVariable.list.size = variableCount; varListResponse->listOfVariable.list.array = (struct GetNamedVariableListAttributesResponse__listOfVariable__Member**) GLOBAL_CALLOC(variableCount, sizeof(void*)); LinkedList variable = LinkedList_getNext(variables); int i; for (i = 0; i < variableCount; i++) { MmsNamedVariableListEntry variableEntry = (MmsNamedVariableListEntry) variable->data; varListResponse->listOfVariable.list.array[i] = (struct GetNamedVariableListAttributesResponse__listOfVariable__Member*) GLOBAL_CALLOC(1, sizeof(struct GetNamedVariableListAttributesResponse__listOfVariable__Member)); varListResponse->listOfVariable.list.array[i]->variableSpecification.present = VariableSpecification_PR_name; varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.present = ObjectName_PR_domainspecific; char* variableDomainName = MmsDomain_getName(variableEntry->domain); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.domainId.buf = (uint8_t*) copyString(variableDomainName); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.domainId.size = strlen(variableDomainName); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.itemId.buf = (uint8_t*) copyString(variableEntry->variableName); varListResponse->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. domainspecific.itemId.size = strlen(variableEntry->variableName); variable = LinkedList_getNext(variable); } der_encode(&asn_DEF_MmsPdu, mmsPdu, mmsServer_write_out, (void*) response); asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); }
void mmsServer_handleDefineNamedVariableListRequest( MmsServerConnection connection, uint8_t* buffer, int bufPos, int maxBufPos, uint32_t invokeId, ByteBuffer* response) { DefineNamedVariableListRequest_t* request = 0; MmsPdu_t* mmsPdu = 0; asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu, (void**) &mmsPdu, buffer, maxBufPos); if (rval.code != RC_OK) { mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); goto exit_function; } request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.defineNamedVariableList); MmsDevice* device = MmsServer_getDevice(connection->server); if (request->variableListName.present == ObjectName_PR_domainspecific) { char domainName[65]; if (request->variableListName.choice.domainspecific.domainId.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } StringUtils_createStringFromBufferInBuffer(domainName, request->variableListName.choice.domainspecific.domainId.buf, request->variableListName.choice.domainspecific.domainId.size); MmsDomain* domain = MmsDevice_getDomain(device, domainName); if (domain == NULL) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } if (LinkedList_size(domain->namedVariableLists) < CONFIG_MMS_MAX_NUMBER_OF_DOMAIN_SPECIFIC_DATA_SETS) { char variableListName[65]; if (request->variableListName.choice.domainspecific.itemId.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } StringUtils_createStringFromBufferInBuffer(variableListName, request->variableListName.choice.domainspecific.itemId.buf, request->variableListName.choice.domainspecific.itemId.size); if (MmsDomain_getNamedVariableList(domain, variableListName) != NULL) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); } else { MmsError mmsError; MmsNamedVariableList namedVariableList = createNamedVariableList(domain, device, request, variableListName, &mmsError); if (namedVariableList != NULL) { mmsError = mmsServer_callVariableListChangedHandler(true, MMS_DOMAIN_SPECIFIC, domain, variableListName, connection); if (mmsError == MMS_ERROR_NONE) { MmsDomain_addNamedVariableList(domain, namedVariableList); createDefineNamedVariableListResponse(invokeId, response); } else { MmsNamedVariableList_destroy(namedVariableList); mmsServer_createConfirmedErrorPdu(invokeId, response, mmsError); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, mmsError); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_CAPABILITY_UNAVAILABLE); } else if (request->variableListName.present == ObjectName_PR_aaspecific) { if (LinkedList_size(connection->namedVariableLists) < CONFIG_MMS_MAX_NUMBER_OF_ASSOCIATION_SPECIFIC_DATA_SETS) { char variableListName[65]; if (request->variableListName.choice.aaspecific.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } StringUtils_createStringFromBufferInBuffer(variableListName, request->variableListName.choice.aaspecific.buf, request->variableListName.choice.aaspecific.size); if (MmsServerConnection_getNamedVariableList(connection, variableListName) != NULL) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); } else { MmsError mmsError; MmsNamedVariableList namedVariableList = createNamedVariableList(NULL, device, request, variableListName, &mmsError); if (namedVariableList != NULL) { if (mmsServer_callVariableListChangedHandler(true, MMS_ASSOCIATION_SPECIFIC, NULL, variableListName, connection) == MMS_ERROR_NONE) { MmsServerConnection_addNamedVariableList(connection, namedVariableList); createDefineNamedVariableListResponse(invokeId, response); } else { MmsNamedVariableList_destroy(namedVariableList); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_DENIED); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, mmsError); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_CAPABILITY_UNAVAILABLE); } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_TYPE_UNSUPPORTED); exit_free_struct: asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); exit_function: return; }
int Map_size(Map map) { return LinkedList_size(map->entries); }