SHARE
TWEET

code.c

zhemant Apr 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include "ServiceCollectionAPI.h"
  5.  
  6.  
  7. #define MAX_BUFFER_LENGTH 4096
  8. #define intToStr(dst, src) \
  9.     do {\
  10.     char dst[256];\
  11.     snprintf(dst, 256, "%ld", (long int)(src));\
  12. }while(0)
  13.  
  14. // Create service
  15. //
  16. service_data_t*
  17. ServiceCollectionAPI_postService(apiClient_t *apiClient, service_create_data_t* jsonData, FILE* binaryData, service_create_data_t* service_create_data) {
  18.     list_t    *localVarQueryParameters = NULL;
  19.     list_t    *localVarHeaderParameters = NULL;
  20.     list_t    *localVarFormParameters = list_create();
  21.     list_t *localVarHeaderType = list_create();
  22.     list_t *localVarContentType = list_create();
  23.     char      *localVarBodyParameters = NULL;
  24.  
  25.     // create the path
  26.     long sizeOfPath = strlen("/service")+1;
  27.     char *localVarPath = malloc(sizeOfPath);
  28.     snprintf(localVarPath, sizeOfPath, "/service");
  29.  
  30.  
  31.     // form parameters
  32.     char *keyForm_jsonData;
  33.     service_create_data valueForm_jsonData;
  34.     keyValuePair_t *keyPairForm_jsonData = 0;
  35.     if (jsonData)
  36.     {
  37.         keyForm_jsonData = strdup("jsonData");
  38.         valueForm_jsonData = jsonData;
  39.         keyPairForm_jsonData = keyValuePair_create(keyForm_jsonData,&valueForm_jsonData);
  40.         list_addElement(localVarFormParameters,keyPairForm_jsonData); // not String
  41.     }
  42.  
  43.     // form parameters
  44.  
  45.     char *keyForm_binaryData;
  46.     FileStruct *fileVar_binaryData;
  47.     keyValuePair_t *keyPairForm_binaryData = 0;
  48.     if (binaryData != NULL)
  49.     {
  50.         fseek(binaryData, 0, SEEK_END);
  51.         long f_size = ftell(binaryData);
  52.         fseek(binaryData, 0, SEEK_SET);
  53.         fileVar_binaryData = malloc(sizeof(FileStruct));
  54.         keyForm_binaryData = strdup("binaryData");
  55.         fileVar_binaryData->fileData = malloc((f_size)* sizeof(char*));
  56.  
  57.         fread(fileVar_binaryData->fileData, f_size, 1, file);
  58.         fileVar_binaryData->fileData[f_size] = '\0';
  59.  
  60.         fileVar_binaryData->fileSize = f_size;
  61.         char valueFile_binaryData[sizeof(fileVar_binaryData)];
  62.  
  63.         memcpy(valueFile_binaryData,&fileVar_binaryData, sizeof(fileVar_binaryData));
  64.  
  65.         keyPairForm_binaryData = keyValuePair_create(keyForm_binaryData,valueFile_binaryData);
  66.         list_addElement(localVarFormParameters,keyPairForm_binaryData); //file adding
  67.     }
  68.  
  69.     // Body Param
  70.     cJSON *localVarSingleItemJSON_service_create_data;
  71.     if (service_create_data != NULL) {
  72.         //string
  73.         localVarSingleItemJSON_service_create_data = service_create_data_convertToJSON(service_create_data);
  74.         localVarBodyParameters = cJSON_Print(localVarSingleItemJSON_service_create_data);
  75.     }
  76.     list_addElement(localVarHeaderType,"application/json"); //produces
  77.     list_addElement(localVarHeaderType,"multipart/related"); //produces
  78.     list_addElement(localVarContentType,"application/json"); //consumes
  79.     list_addElement(localVarContentType,"multipart/related"); //consumes
  80.     apiClient_invoke(apiClient,
  81.                     localVarPath,
  82.                     localVarQueryParameters,
  83.                     localVarHeaderParameters,
  84.                     localVarFormParameters,
  85.                     localVarHeaderType,
  86.                     localVarContentType,
  87.                     localVarBodyParameters,
  88.                     "POST");
  89.  
  90.     if (apiClient->response_code == 201) {
  91.         printf("%s\n","successful creation of an service");
  92.     }
  93.     //nonprimitive not container
  94.     service_data_t *elementToReturn = service_data_parseFromJSON(apiClient->dataReceived);
  95.     if(elementToReturn == NULL) {
  96.         // return 0;
  97.     }
  98.  
  99.     //return type
  100.     if (apiClient->dataReceived) {
  101.         free(apiClient->dataReceived);
  102.     }
  103.    
  104.    
  105.     list_free(localVarFormParameters);
  106.     list_free(localVarHeaderType);
  107.     list_free(localVarContentType);
  108.     free(localVarPath);
  109.     cJSON_Delete(localVarSingleItemJSON_service_create_data);
  110.     free(localVarBodyParameters);
  111.     free(keyForm_jsonData);
  112.     free(keyPairForm_jsonData);
  113.     free(keyForm_binaryData);
  114.     free(fileVar_binaryData->fileData);
  115.     free(fileVar_binaryData);
  116.     free(keyPairForm_binaryData);
  117.     return elementToReturn;
  118. end:
  119.     return NULL;
  120.  
  121. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top