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

Commit 0251114

Browse files
committed
Refactor initialize functions
1 parent 61da8e6 commit 0251114

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

unix/src/parse.c

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ ParseClient parseInitializeWithServerURL(
136136
client->applicationId= strdup(applicationId);
137137
if (clientKey != NULL)
138138
client->clientKey = strdup(clientKey);
139+
139140
if (serverURL != NULL)
140141
client->serverURL = strdup(serverURL);
142+
else if (serverURL == NULL)
143+
client->serverURL = strdup(PARSE_DEFAULT_SERVER_URL);
141144

142145
char version[256];
143146
parseOsGetVersion(version, sizeof(version));
@@ -168,41 +171,7 @@ ParseClient parseInitialize(
168171
const char *applicationId,
169172
const char *clientKey)
170173
{
171-
parseSetLogLevel(PARSE_LOG_WARN);
172-
173-
ParseClientInternal *client = calloc(1, sizeof(ParseClientInternal));
174-
if (client == NULL) {
175-
parseLog(PARSE_LOG_ERROR, "%s:%s generated out of memory.\n", __FUNCTION__, __LINE__);
176-
return NULL;
177-
}
178-
if (applicationId != NULL)
179-
client->applicationId= strdup(applicationId);
180-
if (clientKey != NULL)
181-
client->clientKey = strdup(clientKey);
182-
183-
char version[256];
184-
parseOsGetVersion(version, sizeof(version));
185-
client->osVersion = strdup(version);
186-
187-
char temp[40];
188-
parseOsLoadKey(client->applicationId, PARSE_INSTALLATION_ID, temp, sizeof(temp));
189-
if (temp[0] != '\0') {
190-
parseSetInstallationId((ParseClient)client, temp);
191-
}
192-
193-
parseOsLoadKey(client->applicationId, PARSE_SESSION_TOKEN, temp, sizeof(temp));
194-
if (temp[0] != '\0') {
195-
parseSetSessionToken((ParseClient)client, temp);
196-
}
197-
198-
parseOsLoadKey(client->applicationId, PARSE_LAST_PUSH_TIME, temp, sizeof(temp));
199-
if (temp[0] != '\0') {
200-
client->lastPushTime = strdup(temp);
201-
}
202-
203-
curl_global_init(CURL_GLOBAL_ALL);
204-
205-
return (ParseClient)client;
174+
return parseInitializeWithServerURL(applicationId, clientKey, NULL);
206175
}
207176

208177
static void setInstallationCallback(ParseClient client, int error, int httpStatus, const char* httpResponseBody)
@@ -585,13 +554,7 @@ static void parseSendRequestInternal(
585554
}
586555
}
587556

588-
int urlSize = 0;
589-
if(clientInternal->serverURL != NULL){
590-
urlSize = strlen(clientInternal->serverURL);
591-
}
592-
else {
593-
urlSize = strlen(PARSE_DEFAULT_SERVER_URL);
594-
}
557+
int urlSize = strlen(clientInternal->serverURL);
595558
urlSize += strlen(httpPath) + 1;
596559
char* getEncodedBody = NULL;
597560
if (getRequestBody) {

0 commit comments

Comments
 (0)