void getInstallation(ParseClientInternal *parseClient) {
    // If we have both installation id and installation object id, don't do anything
    if ((strlen(parseClient->installationObjectId) > 0) && (strlen(parseClient->installationId) > 0)) {
        return;
    }

    char content[150];

    // We have only installation object id or installation id
    if (strlen(parseClient->installationObjectId) > 0) {
        // This is just in case, we should never get in this branch in normal scenarios
        // as the device app will always give us installation id, and never installation object id
        snprintf(content, sizeof(content)-1, "/1/installations/%s", parseClient->installationObjectId);

        parseSendRequestInternal((ParseClient)parseClient, "GET", content, NULL, getInstallationCallback, FALSE);
    } else if (strlen(parseClient->installationId) > 0) {
        snprintf(content, sizeof(content)-1, "where=%%7b%%22installationId%%22%%3a+%%22%s%%22%%7d", parseClient->installationId);

        parseSendRequestInternal((ParseClient)parseClient, "GET", "/1/installations", content, getInstallationByIdCallback, FALSE);
    }

    // Go through create new installation, to catch the case we still don't have
    // an installation object id. This will be noop if we managed to get the installation
    // already
    createInstallation(parseClient);
}
예제 #2
0
void parseSetInstallationId(ParseClient client, const char *installationId)
{
    ParseClientInternal *clientInternal = getClient(client);

    if (installationId != NULL) {
        parseOsStoreKey(clientInternal->applicationId, PARSE_INSTALLATION_ID, installationId);
        if (clientInternal->installationId != NULL) {
            free(clientInternal->installationId);
        }
        clientInternal->installationId = strdup(installationId);

        int payloadLength = strlen("{\"installationId\":\"");
        payloadLength += strlen(clientInternal->installationId);
        payloadLength += strlen("\",\"deviceType\":\"embedded\"}") + 1;

        char *payload = calloc(sizeof(char), payloadLength);
        if (payload == NULL) {
            parseLog(PARSE_LOG_ERROR, "%s:%s generated out of memory.\n", __FUNCTION__, __LINE__);
            return;
        }
        strncat(payload, "{\"installationId\":\"", payloadLength - strlen(payload));
        strncat(payload, clientInternal->installationId, payloadLength - strlen(payload));
        strncat(payload, "\",\"deviceType\":\"embedded\"}", payloadLength - strlen(payload));

        parseSendRequestInternal(client, "POST", "/1/installations/", payload, setInstallationCallback, 0);
        free(payload);
    } else {
        parseOsClearKey(clientInternal->applicationId, PARSE_INSTALLATION_ID);
        if (clientInternal->installationId != NULL) {
            free(clientInternal->installationId);
            clientInternal->installationId = NULL;
        }
    }
}
예제 #3
0
void parseSendRequest(ParseClient client, const char *httpVerb, const char *httpPath, const char *httpRequestBody, parseRequestCallback callback) {
    getInstallation(getInternalClient(client));

#ifdef REQUEST_TRACE
    DEBUG_PRINT("[Parse] Send %s request to %s \r\n", httpVerb, httpPath);
#endif /* REQUEST_TRACE */

    parseSendRequestInternal(client, httpVerb, httpPath, httpRequestBody, callback, TRUE);
}
예제 #4
0
void parseSendRequest(
        ParseClient client,
        const char *httpVerb,
        const char* httpPath,
        const char* requestBody,
        parseRequestCallback callback)
{
    ParseClientInternal *clientInternal = getClient(client);
    parseCreateInstallationIdIfNeeded(client);
    parseSendRequestInternal(client, httpVerb, httpPath, requestBody, callback, 1);
}
void createInstallation(ParseClientInternal *parseClient) {
    // If we have an installation object id, we don't need to create it again
    if (strlen(parseClient->installationObjectId) == 0) {
#ifdef CLIENT_DEBUG
        DEBUG_PRINT("[Parse] Creating new installation.\r\n");
#endif /* CLIENT_DEBUG */

        // Create new id if necessary
        if (strlen(parseClient->installationId) == 0) {
            createNewInstallationId(parseClient);
        }

        // Send installation create request and get the object id from the response.
        // If the response is a failure, set the instalaltionObjectId back to empty
        char content[120];
        snprintf(content, sizeof(content)-1, "{\"installationId\": \"%s\", \"deviceType\": \"embedded\", \"parseVersion\": \"1.0.0\"}", parseClient->installationId);

        parseSendRequestInternal((ParseClient)parseClient, "POST", "/1/installations", content, createInstallationCallback, FALSE);
    }
}