Skip to content
This repository was archived by the owner on Sep 13, 2020. It is now read-only.

Commit 8c2b9a7

Browse files
committed
Merge pull request #67 from evileye2000/parseserver_embedded
Issue #63, patch for part of unix
2 parents bda0f3e + 0251114 commit 8c2b9a7

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

include/parse.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ extern "C"
5050
*/
5151
#define CLIENT_KEY_MAX_LEN 40
5252

53+
/*! \def SERVER_URL_MAX_LEN
54+
* \brief The length of server url
55+
*/
56+
#define SERVER_URL_MAX_LEN 256
57+
5358
/*! \def OBJECT_ID_MAX_LEN
5459
* \brief The length of object id
5560
*/
@@ -142,6 +147,25 @@ typedef void (*parsePushCallback)(ParseClient client, int error, const char* dat
142147
*/
143148
ParseClient parseInitialize(const char *applicationId, const char *clientKey);
144149

150+
/*! \fn ParseClient parseInitializeWithURL(const char *applicationId, const char *clientKey, const char *serverURL)
151+
* \brief Initialize the Parse client and user session with parse server URL
152+
*
153+
* This method only initializes the Parse client, used for subsequent API requests with parse-server URL. It does
154+
* not start the push service, and does not create or load the installation object for the client.
155+
*
156+
* \param[in] applicationId The application id for the Parse application. (required)
157+
* \param[in] clientKey The client API key for the Parse application. (required)
158+
* \param[in] serverURL The server URL for the Parse-server connection . (required)
159+
*
160+
* \result The client handle to use with the SDK.
161+
*
162+
* The caller retains ownership of the applicationId and clientKey buffers, and is responsible for
163+
* freeing them and reclaiming the memory after this call.
164+
* The SDK will make copies of the buffers.
165+
*/
166+
ParseClient parseInitializeWithServerURL(const char *applicationId, const char *clientKey, const char *serverURL);
167+
168+
145169
/*! \fn void parseSetInstallationId(ParseClient client, const char *installationId)
146170
* \brief Set the installation object id for this client.
147171
*

unix/src/parse.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define PARSE_INSTALLATION_ID "installationID"
4444
#define PARSE_SESSION_TOKEN "sessionToken"
4545
#define PARSE_LAST_PUSH_TIME "lastPushTime"
46+
#define PARSE_DEFAULT_SERVER_URL "https://api.parse.com"
4647

4748
typedef struct _ParseClientInternal {
4849
const char *applicationId;
@@ -52,6 +53,7 @@ typedef struct _ParseClientInternal {
5253
char *sessionToken;
5354
char *osVersion;
5455
char *lastPushTime;
56+
char *serverURL;
5557
parsePushCallback pushCallback;
5658
CURL *pushCurlHandle;
5759
unsigned long long lastHearbeat;
@@ -118,9 +120,10 @@ static size_t curlDataCallback(void *contents, size_t size, size_t nmemb, void *
118120
return size * nmemb;
119121
}
120122

121-
ParseClient parseInitialize(
123+
ParseClient parseInitializeWithServerURL(
122124
const char *applicationId,
123-
const char *clientKey)
125+
const char *clientKey,
126+
const char *serverURL)
124127
{
125128
parseSetLogLevel(PARSE_LOG_WARN);
126129

@@ -134,6 +137,11 @@ ParseClient parseInitialize(
134137
if (clientKey != NULL)
135138
client->clientKey = strdup(clientKey);
136139

140+
if (serverURL != NULL)
141+
client->serverURL = strdup(serverURL);
142+
else if (serverURL == NULL)
143+
client->serverURL = strdup(PARSE_DEFAULT_SERVER_URL);
144+
137145
char version[256];
138146
parseOsGetVersion(version, sizeof(version));
139147
client->osVersion = strdup(version);
@@ -159,6 +167,13 @@ ParseClient parseInitialize(
159167
return (ParseClient)client;
160168
}
161169

170+
ParseClient parseInitialize(
171+
const char *applicationId,
172+
const char *clientKey)
173+
{
174+
return parseInitializeWithServerURL(applicationId, clientKey, NULL);
175+
}
176+
162177
static void setInstallationCallback(ParseClient client, int error, int httpStatus, const char* httpResponseBody)
163178
{
164179
if (error != 0) {
@@ -539,7 +554,7 @@ static void parseSendRequestInternal(
539554
}
540555
}
541556

542-
int urlSize = strlen("https://api.parse.com");
557+
int urlSize = strlen(clientInternal->serverURL);
543558
urlSize += strlen(httpPath) + 1;
544559
char* getEncodedBody = NULL;
545560
if (getRequestBody) {
@@ -551,7 +566,15 @@ static void parseSendRequestInternal(
551566
if (callback != NULL) callback(client, ENOMEM, 0, NULL);
552567
return;
553568
}
554-
strncat(fullUrl, "https://api.parse.com", urlSize);
569+
570+
if(clientInternal->serverURL != NULL){
571+
strncat(fullUrl, clientInternal->serverURL, urlSize);
572+
}
573+
else {
574+
strncat(fullUrl, PARSE_DEFAULT_SERVER_URL, urlSize);
575+
}
576+
577+
555578
strncat(fullUrl, httpPath, urlSize - strlen(fullUrl));
556579
if (getRequestBody) {
557580
strncat(fullUrl, "?", urlSize - strlen(fullUrl));

0 commit comments

Comments
 (0)