/**
 * REST API to accept terms and conditions
 *
 * @param user_id specifies the user ID
 * @param accept 'true' to accept, 'false' to decline
 * @return returns the result received from server, otherwise NULL
 */
char *acceptTermsAndConditions(char *userId, bool accept) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MIN];
    KeyValueParams *urlParams = NULL;
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "acceptTermsAndConditions::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    urlParams = (KeyValueParams *)malloc(sizeof(KeyValueParams));
    urlParams->name = "user_id";
    if(userId) {
        urlParams->value = strdup(userId);
    } else {
        urlParams->value = strdup(configurations.user_account_id);
    }
    urlParams->next = NULL;

    if(prepareUrl(&url, configurations.base_url, configurations.accept_terms_and_conditions, urlParams)) {

        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        strcpy(body, "{\"id\":\"");
        if(userId) {
            strcat(body, userId);
        } else {
            strcat(body, configurations.user_account_id);
        }
        strcat(body, "\",\"termsAndConditions\":");

        if(accept == true) {
            strcat(body, "true");
        } else {
            strcat(body, "false");
        }
        strcat(body, "}");

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPut(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
/**
 * REST API to change an user password
 *
 * @param emailAddress specifies the username of the user
 * @param current_password specifies the current password
 * @param new_password specifies the new password
 * @return returns the result received from server, otherwise NULL
 */
char *changePassword(char *emailAddress, char *current_password, char *new_password) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MIN];
    KeyValueParams *urlParams = NULL;
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "changePassword::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    urlParams = (KeyValueParams *)malloc(sizeof(KeyValueParams));
    urlParams->name = "email_id";
    urlParams->value = strdup(emailAddress);
    urlParams->next = NULL;

    if(!emailAddress || !current_password || !new_password) {
        fprintf(stderr, "changePassword::Mandatory parameters cannot be NULL");
        return NULL;
    }

    if(prepareUrl(&url, configurations.base_url, configurations.change_password, urlParams)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        sprintf(body, "{\"currentpwd\":\"%s\",\"password\":\"%s\"}", current_password, new_password);

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPut(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
/**
 * REST API to update forgot password
 *
 * @param token specifies the token received by email to reset password
 * @param new_password specifies the new password
 * @return returns the result received from server, otherwise NULL
 */
char *updateForgotPassword(char *token, char *new_password) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MIN];
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "updateForgotPassword::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(!token || !new_password) {
        fprintf(stderr, "updateForgotPassword::Mandatory parameters cannot be NULL");
        return NULL;
    }

    if(prepareUrl(&url, configurations.base_url, configurations.request_change_password, NULL)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        sprintf(body, "{\"token\":\"%s\",\"password\":\"%s\"}", token, new_password);

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPut(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
/**
 * REST API to initiate request for a change of password process
 *
 * @param emailAddress specifies the username of the user
 * @return returns the result received from server, otherwise NULL
 */
char *requestChangePassword(char *emailAddress) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MIN];
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "requestChangePassword::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(!emailAddress) {
        fprintf(stderr, "requestChangePassword::Parameter email address cannot be NULL");
        return false;
    }

    if(prepareUrl(&url, configurations.base_url, configurations.request_change_password, NULL)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        sprintf(body, "{\"email\":\"%s\"}", emailAddress);

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPost(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
Beispiel #5
0
   INT32 restAdaptor::_setResponseType( pmdRestSession *pSession )
   {
      INT32 rc = SDB_OK ;
      SDB_ASSERT ( pSession, "pSession is NULL" ) ;
      httpConnection *pHttpCon = pSession->getRestConn() ;
      const CHAR *pFileType = NULL ;

      if( COM_GETFILE == pHttpCon->_common )
      {
         switch( pHttpCon->_fileType )
         {
         case HTTP_FILE_PNG:
            pFileType = REST_STRING_TEXT_PNG ;
            break ;
         case HTTP_FILE_BMP:
            pFileType = REST_STRING_TEXT_BMP ;
            break ;
         case HTTP_FILE_JPG:
            pFileType = REST_STRING_TEXT_JPG ;
            break ;
         case HTTP_FILE_GIF:
            pFileType = REST_STRING_TEXT_GIF ;
            break ;
         case HTTP_FILE_JS:
            pFileType = REST_STRING_TEXT_JS ;
            break ;
         case HTTP_FILE_CSS:
            pFileType = REST_STRING_TEXT_CSS ;
            break ;
         case HTTP_FILE_HTML:
         case HTTP_FILE_DEFAULT:
         case HTTP_FILE_UNKNOW:
         default:
            pFileType = REST_STRING_TEXT_HTML ;
            break ;
         }
         rc = appendHttpHeader( pSession, REST_STRING_CONTENT_TYPE,
                                pFileType ) ;
         if( rc )
         {
            PD_LOG ( PDERROR, "Failed to call append http header, rc=%d",
                     rc ) ;
            goto error ;
         }
      }
   done:
      return rc ;
   error:
      goto done ;
   }
/**
 * REST API to delete a user
 *
 * @param user_id specifies the user ID
 * @return returns the result received from server, otherwise NULL
 */
char *deleteAUser(char *userId) {
    struct curl_slist *headers = NULL;
    char *url;
    KeyValueParams *urlParams = NULL;
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "deleteAUser::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    urlParams = (KeyValueParams *)malloc(sizeof(KeyValueParams));
    urlParams->name = "user_id";
    if(userId) {
        urlParams->value = strdup(userId);
    } else {
        urlParams->value = strdup(configurations.user_account_id);
    }
    urlParams->next = NULL;

    if(prepareUrl(&url, configurations.base_url, configurations.delete_a_user, urlParams)) {

        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        doHttpDelete(url, headers, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
Beispiel #7
0
 INT32 restAdaptor::setChunkModal( pmdRestSession *pSession )
 {
    INT32 rc = SDB_OK ;
    SDB_ASSERT ( pSession, "pSession is NULL" ) ;
    rc = appendHttpHeader( pSession,
                           REST_STRING_TRANSFER,
                           REST_STRING_CHUNKED ) ;
    if( rc )
    {
       PD_LOG ( PDERROR, "Failed to set chunk modal, rc=%d", rc ) ;
       goto error ;
    }
 done:
    return rc ;
 error:
    goto done ;
 }
/**
 * REST API to create an user
 *
 * @param emailAddress specifies the username (email address) for the user
 * @param password specifies the password for the user
 * @param acceptTermsAndConditions specifies acceptance for terms and conditions
 * @return returns the result received from server, otherwise NULL
 */
char *createAnUser(char *emailAddress, char *password, bool acceptTermsAndConditions) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MIN];
    HttpResponse *response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(!emailAddress || !password) {
        fprintf(stderr, "createAnUser::Mandatory parameters cannot be NULL");
        return NULL;
    }

    if(prepareUrl(&url, configurations.base_url, configurations.create_a_user, NULL)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);

        sprintf(body, "{\"email\":\"%s\",\"password\":\"%s\",", emailAddress, password);

        if(acceptTermsAndConditions) {
            strcat(body, "\"termsAndConditions\": true");
        } else {
            strcat(body, "\"termsAndConditions\": false");
        }

        strcat(body, "}");

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPost(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
/**
 * REST API to update user attributes
 *
 * @param user_id specifies the user ID
 * @param attributes specifies the user attributes
 * @return returns the result received from server, otherwise NULL
 */
char *updateUserAttributes(char *userId, KeyValueParams *attributes) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MED];
    KeyValueParams *urlParams = NULL;
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "updateUserAttributes::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(!attributes) {
        fprintf(stderr, "updateUserAttributes::Parameter attribute list cannot be NULL");
        return NULL;
    }

    urlParams = (KeyValueParams *)malloc(sizeof(KeyValueParams));
    urlParams->name = "user_id";
    if(userId) {
        urlParams->value = strdup(userId);
    } else {
        urlParams->value = strdup(configurations.user_account_id);
    }
    urlParams->next = NULL;

    if(prepareUrl(&url, configurations.base_url, configurations.update_user_attributes, urlParams)) {
        KeyValueParams *traverse = attributes;

        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        strcpy(body, "{\"id\":\"");
        if(userId) {
            strcat(body, userId);
        } else {
            strcat(body, configurations.user_account_id);
        }
        strcat(body, "\",\"attributes\":{");
        while(traverse != NULL) {
            strcat(body, "\"");
            strcat(body, traverse->name);
            strcat(body, "\":\"");
            strcat(body, traverse->value);
            strcat(body, "\"");

            traverse = traverse->next;

            if(traverse) {
                strcat(body, ",");
            }
        }
        strcat(body, "}}");

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPut(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
Beispiel #10
0
/**
 * REST API to submit data along with sensor location
 *
 * @param cname specifies the component name
 * @param value specifies the value
 * @param latitide specifies the geo location - latitude of the measurement
 * @param longitude specifies the geo location - longitude of the measurement
 * @param height specifies the physical height of the component during the measurement
 * @return returns the result received from server, otherwise NULL
 */
char *submitDataWithLoc(char *cname, char *value, char *latitude, char *longitude, char *height) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MED];
    char *cid = NULL;
    char currentTimeInMills[BODY_SIZE_MED];
    char *deviceAuthorizationHeader = (char *)getDeviceAuthorizationToken();
    HttpResponse *response = NULL;

    if(deviceAuthorizationHeader == NULL) {
        fprintf(stderr, "submitData::Device Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(!cname) {
        fprintf(stderr, "submitData::Component Name cannot be NULL\n");
        return NULL;
    }

    cid = getSensorComponentId(cname);
    if(!cid) {
        fprintf(stderr, "submitData::Component is not registered\n");
        return NULL;
    }

    if(!value) {
        fprintf(stderr, "submitData::Value cannot be NULL\n");
        return NULL;
    }

    if(!configurations.data_account_id) {
        fprintf(stderr, "submitData::Account is NULL. Device appears to be unactivated\n");
        return NULL;
    }

    if(prepareUrl(&url, configurations.base_url, configurations.submit_data, NULL)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, deviceAuthorizationHeader);

        sprintf(currentTimeInMills, "%lld", (long long) getCurrentTimeInSeconds() * 1000L);

        strcpy(body, "{");
        strcat(body, "\"on\":");
        strcat(body, currentTimeInMills);
        strcat(body, ",\"accountId\":\"");
        strcat(body, configurations.data_account_id);
        strcat(body, "\",\"data\":[{\"componentId\":\"");
        strcat(body, cid);
        strcat(body, "\",\"on\":");
        strcat(body, currentTimeInMills);

        if(latitude != NULL && longitude != NULL) {
            strcat(body, ",\"loc\":[");

            strcat(body, latitude);
            strcat(body, ",");
            strcat(body, longitude);

            if(height) {
                strcat(body, ",");
                strcat(body, height);
            }
            strcat(body, "]");
        }

        strcat(body, ",\"value\":\"");
        strcat(body, value);
        strcat(body, "\"}]}");

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPost(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
Beispiel #11
0
/**
 * REST API to retrieve data using device token instead of authorization token.
 * This is helpful when a device is activated directly using activation code from portal.
 *
 * @param retrieveObj the object created using createRetrieveDataObject()
 * @return returns the result received from server, otherwise NULL
 */
char *retrieveData2(RetrieveData *retrieveObj) {
    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MED];
    char fromTimeInMillis[BODY_SIZE_MIN];
    char toTimeInMillis[BODY_SIZE_MIN];
    StringList *traverse = NULL;
    char *deviceAuthorizationHeader = (char *)getDeviceAuthorizationToken();
    HttpResponse *response = NULL;

    if(deviceAuthorizationHeader == NULL) {
        fprintf(stderr, "retrieveData::Device Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(!retrieveObj->deviceList) {
        fprintf(stderr, "retrieveData::Device ID cannot be NULL");
        return NULL;
    }

    if(!retrieveObj->componentId) {
        fprintf(stderr, "retrieveData::Component ID cannot be NULL");
        return NULL;
    }

    if(prepareUrl(&url, configurations.base_url, configurations.retrieve_data, NULL)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, deviceAuthorizationHeader);

        sprintf(fromTimeInMillis, "%lld", (long long) retrieveObj->fromMillis * 1000L);
        sprintf(toTimeInMillis, "%lld", (long long) retrieveObj->toMillis * 1000L);

        strcpy(body, "{");
        strcat(body, "\"from\":");
        strcat(body, fromTimeInMillis);
        strcat(body, ",\"to\":");
        strcat(body, toTimeInMillis);
        strcat(body, ",\"targetFilter\":{\"deviceList\":[");

        traverse = retrieveObj->deviceList;
        while(traverse != NULL) {
            strcat(body, "\"");
            strcat(body, traverse->data);
            strcat(body, "\"");

            traverse = traverse->next;

            if(traverse) {
                strcat(body, ",");
            }
        }

        strcat(body, "]}");

        strcat(body, ",\"metrics\":[");

        traverse = retrieveObj->componentId;
        while(traverse != NULL) {
            strcat(body, "{\"id\":\"");
            strcat(body, traverse->data);
            strcat(body, "\",\"op\":\"none\"}");

            traverse = traverse->next;

            if(traverse) {
                strcat(body, ",");
            }
        }

        strcat(body, "]}");

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPost(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}
Beispiel #12
0
   INT32 restAdaptor::sendResponse( pmdRestSession *pSession,
                                    HTTP_RESPONSE_CODE rspCode )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( SDB__RESTADP_SENDRE ) ;
      SDB_ASSERT ( pSession, "pSession is NULL" ) ;
      CHAR httpBodySize[256] = { 0 } ;
      httpConnection *pHttpCon = pSession->getRestConn() ;
      std::vector<httpResponse>::iterator it ;
      httpResponse httpRe ;

      if( TRUE == pHttpCon->_isChunk )
      {
         rc = pSession->sendData( REST_STRING_CHUNKED_END,
                                  REST_STRING_CHUNKED_END_SIZE,
                                  _timeout ) ;
         if ( rc )
         {
            PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ;
            goto error ;
         }
      }
      else
      {
         if( HTTP_OK == rspCode )
         {
            ossSnprintf( httpBodySize, 255, "%d",
                         pHttpCon->_firstRecordSize + pHttpCon->_responseSize );
            rc = appendHttpHeader( pSession, REST_STRING_CONLEN, httpBodySize );
            if ( rc )
            {
               PD_LOG ( PDERROR, "Failed to call append http header, rc=%d",
                        rc ) ;
               goto error ;
            }
            rc = _setResponseType( pSession ) ;
            if( rc )
            {
               PD_LOG ( PDERROR, "Failed to set respone type, rc=%d",
                        rc ) ;
               goto error ;
            }
         }
         else
         {
            ossSnprintf( httpBodySize, 255, "0" ) ;
            rc = appendHttpHeader( pSession, REST_STRING_CONLEN, httpBodySize );
            if ( rc )
            {
               PD_LOG ( PDERROR, "Failed to call append http header, rc=%d",
                        rc ) ;
               goto error ;
            }
         }
         rc = _sendHttpHeader( pSession, rspCode ) ;
         if ( rc )
         {
            PD_LOG ( PDERROR, "Failed to send http header, rc=%d", rc ) ;
            goto error ;
         }

         if( HTTP_OK == rspCode )
         {
            for( it = pHttpCon->_responseBody.begin();
                 it != pHttpCon->_responseBody.end(); ++it )
            {
               httpRe = (*(it)) ;
               rc = pSession->sendData( httpRe.pBuffer, httpRe.len,
                                        _timeout ) ;
               if ( rc )
               {
                  PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ;
                  goto error ;
               }
            }
         }
      }
   done:
      PD_TRACE_EXITRC( SDB__RESTADP_SENDRE, rc ) ;
      return rc ;
   error:
      goto done ;
   }
/**
 * REST API for advanced data inquiry
 *
 * @param advancedDataInquiryObject object created using createAdvancedDataInquiryObject"()"
 * @return returns the result received from server, otherwise NULL
 */
char *advancedDataInquiry(AdvancedDataInquiry *advancedDataInquiryObject) {

    struct curl_slist *headers = NULL;
    char *url;
    char body[BODY_SIZE_MED];
    StringList *traverse = NULL;
    char *authorizationHeader = (char *)getConfigAuthorizationToken();
    HttpResponse *response = NULL;

    if(authorizationHeader == NULL) {
        fprintf(stderr, "advancedDataInquiry::Authorization Token not available\n");
        return NULL;
    }

    response = (HttpResponse *)malloc(sizeof(HttpResponse));
    response->code = 0;
    response->data = NULL;

    if(prepareUrl(&url, configurations.base_url, configurations.advanced_data_inquiry, NULL)) {
        appendHttpHeader(&headers, HEADER_CONTENT_TYPE_NAME, HEADER_CONTENT_TYPE_JSON);
        appendHttpHeader(&headers, HEADER_AUTHORIZATION, authorizationHeader);

        strcpy(body, "{");

        if(advancedDataInquiryObject->gatewayIds) {
            strcat(body, "\"gatewayIds\":[");

            traverse = advancedDataInquiryObject->gatewayIds;
            while (traverse != NULL) {
                strcat(body, "\"");
                strcat(body, traverse->data);
                strcat(body, "\"");
                traverse = traverse->next;

                if(traverse) {
                    strcat(body, ",");
                }
            }
            strcat(body, "],");
        }

        if(advancedDataInquiryObject->deviceIds) {
            strcat(body, "\"deviceIds\":[");

            traverse = advancedDataInquiryObject->deviceIds;
            while (traverse != NULL) {
                strcat(body, "\"");
                strcat(body, traverse->data);
                strcat(body, "\"");
                traverse = traverse->next;

                if(traverse) {
                    strcat(body, ",");
                }
            }
            strcat(body, "],");
        }

        if(advancedDataInquiryObject->componentIds) {
            strcat(body, "\"componentIds\":[");

            traverse = advancedDataInquiryObject->componentIds;
            while (traverse != NULL) {
                strcat(body, "\"");
                strcat(body, traverse->data);
                strcat(body, "\"");
                traverse = traverse->next;

                if(traverse) {
                    strcat(body, ",");
                }
            }
            strcat(body, "],");
        }

//        if(advancedDataInquiryObject->startTimestamp > 0L)
        {
            char timeStamp[BODY_SIZE_MIN];
            sprintf(timeStamp, "%lld", advancedDataInquiryObject->startTimestamp);
            strcat(body, "\"from\":");
            strcat(body, timeStamp);
        }

//        if(advancedDataInquiryObject->endTimestamp> 0L)
        {
            char timeStamp[BODY_SIZE_MIN];
            sprintf(timeStamp, "%lld", advancedDataInquiryObject->endTimestamp);
            strcat(body, ",\"to\":");
            strcat(body, timeStamp);
        }

        if(advancedDataInquiryObject->returnedMeasureAttributes) {
            strcat(body, ",\"returnedMeasureAttributes\":[");

            traverse = advancedDataInquiryObject->returnedMeasureAttributes;
            while (traverse != NULL) {
                strcat(body, "\"");
                strcat(body, traverse->data);
                strcat(body, "\"");
                traverse = traverse->next;

                if(traverse) {
                    strcat(body, ",");
                }
            }
            strcat(body, "]");
        }

        if(advancedDataInquiryObject->showMeasureLocation) {
            strcat(body, ",\"showMeasureLocation\": true");
        }

        if(advancedDataInquiryObject->componentRowLimit) {
            char rowLimit[BODY_SIZE_MIN];
            sprintf(rowLimit, "%d", advancedDataInquiryObject->componentRowLimit);
            strcat(body, ",\"componentRowLimit\":");
            strcat(body, rowLimit);
        }

        if(advancedDataInquiryObject->sort) {
            KeyValueParams *traverseKeyValues = advancedDataInquiryObject->sort;
            strcat(body, ",\"sort\":[");

            while(traverseKeyValues != NULL) {

                strcat(body, "{\"");
                strcat(body, traverseKeyValues->name);
                strcat(body, "\":\"");
                strcat(body, traverseKeyValues->value);
                strcat(body, "\"}");

                traverseKeyValues = traverseKeyValues->next;

                if(traverseKeyValues) {
                    strcat(body, ",");
                }
            }
            strcat(body, "]");
        }

        if(advancedDataInquiryObject->countOnly) {
            strcat(body, ",\"countOnly\": true");
        }

        if(advancedDataInquiryObject->devCompAttributeFilter) {
            AttributeFilterList *attributesList = advancedDataInquiryObject->devCompAttributeFilter;
            strcat(body, ",\"devCompAttributeFilter\":{");

            while(attributesList) {
                AttributeFilter *attributes = attributesList->filterData;
                #if DEBUG
                    printf("Attributes filter is %d\n", attributesList->filterData);
                #endif

                while(attributes) {
                    #if DEBUG
                        printf("Attributes filter Name is %s\n", attributes->filterName);
                    #endif
                    strcat(body, "\"");
                    strcat(body, attributes->filterName);
                    strcat(body, "\":[");
                    traverse = attributes->filterValues;
                    while (traverse != NULL) {
                        strcat(body, "\"");
                        strcat(body, traverse->data);
                        strcat(body, "\"");
                        traverse = traverse->next;
                        if(traverse) {
                            strcat(body, ",");
                        }
                    }
                    strcat(body, "]");

                    attributes = attributes->next;
                    if(attributes) {
                        strcat(body, ",");
                    }
                }
                attributesList = attributesList->next;
                if(attributesList) {
                    strcat(body, ",");
                }
            }

            strcat(body, "}");
        }

        if(advancedDataInquiryObject->measurementAttributeFilter) {
            AttributeFilterList *attributesList = advancedDataInquiryObject->measurementAttributeFilter;

            strcat(body, ",\"measurementAttributeFilter\":{");

            while(attributesList) {
                AttributeFilter *attributes = attributesList->filterData;

                while(attributes) {
                    strcat(body, "\"");
                    strcat(body, attributes->filterName);
                    strcat(body, "\":[");

                    traverse = attributes->filterValues;
                    while (traverse != NULL) {
                        strcat(body, "\"");
                        strcat(body, traverse->data);
                        strcat(body, "\"");
                        traverse = traverse->next;

                        if(traverse) {
                            strcat(body, ",");
                        }
                    }
                    strcat(body, "]");

                    attributes = attributes->next;

                    if(attributes) {
                        strcat(body, ",");
                    }
                }

                attributesList = attributesList->next;
                if(attributesList) {
                    strcat(body, ",");
                }
            }

            strcat(body, "}");
        }

        if(advancedDataInquiryObject->valueFilter) {
            strcat(body, ",\"valueFilter\":{\"");
            strcat(body, advancedDataInquiryObject->valueFilter->filterName);
            strcat(body, "\":[");

            traverse = advancedDataInquiryObject->valueFilter->filterValues;
            while (traverse != NULL) {
                strcat(body, "\"");
                strcat(body, traverse->data);
                strcat(body, "\"");
                traverse = traverse->next;

                if(traverse) {
                    strcat(body, ",");
                }
            }
            strcat(body, "]}");
        }

        strcat(body, "}");

        #if DEBUG
            printf("Prepared BODY is %s\n", body);
        #endif

        doHttpPost(url, headers, body, response);

        return createHttpResponseJson(response);
    }

    return NULL;
}