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
4748typedef 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,6 +120,50 @@ static size_t curlDataCallback(void *contents, size_t size, size_t nmemb, void *
118120 return size * nmemb ;
119121}
120122
123+ ParseClient parseInitializeWithServerURL (
124+ const char * applicationId ,
125+ const char * clientKey ,
126+ const char * serverURL )
127+ {
128+ parseSetLogLevel (PARSE_LOG_WARN );
129+
130+ ParseClientInternal * client = calloc (1 , sizeof (ParseClientInternal ));
131+ if (client == NULL ) {
132+ parseLog (PARSE_LOG_ERROR , "%s:%s generated out of memory.\n" , __FUNCTION__ , __LINE__ );
133+ return NULL ;
134+ }
135+ if (applicationId != NULL )
136+ client -> applicationId = strdup (applicationId );
137+ if (clientKey != NULL )
138+ client -> clientKey = strdup (clientKey );
139+ if (serverURL != NULL )
140+ client -> serverURL = strdup (serverURL );
141+
142+ char version [256 ];
143+ parseOsGetVersion (version , sizeof (version ));
144+ client -> osVersion = strdup (version );
145+
146+ char temp [40 ];
147+ parseOsLoadKey (client -> applicationId , PARSE_INSTALLATION_ID , temp , sizeof (temp ));
148+ if (temp [0 ] != '\0' ) {
149+ parseSetInstallationId ((ParseClient )client , temp );
150+ }
151+
152+ parseOsLoadKey (client -> applicationId , PARSE_SESSION_TOKEN , temp , sizeof (temp ));
153+ if (temp [0 ] != '\0' ) {
154+ parseSetSessionToken ((ParseClient )client , temp );
155+ }
156+
157+ parseOsLoadKey (client -> applicationId , PARSE_LAST_PUSH_TIME , temp , sizeof (temp ));
158+ if (temp [0 ] != '\0' ) {
159+ client -> lastPushTime = strdup (temp );
160+ }
161+
162+ curl_global_init (CURL_GLOBAL_ALL );
163+
164+ return (ParseClient )client ;
165+ }
166+
121167ParseClient parseInitialize (
122168 const char * applicationId ,
123169 const char * clientKey )
@@ -539,7 +585,13 @@ static void parseSendRequestInternal(
539585 }
540586 }
541587
542- int urlSize = strlen ("https://api.parse.com" );
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+ }
543595 urlSize += strlen (httpPath ) + 1 ;
544596 char * getEncodedBody = NULL ;
545597 if (getRequestBody ) {
@@ -551,7 +603,15 @@ static void parseSendRequestInternal(
551603 if (callback != NULL ) callback (client , ENOMEM , 0 , NULL );
552604 return ;
553605 }
554- strncat (fullUrl , "https://api.parse.com" , urlSize );
606+
607+ if (clientInternal -> serverURL != NULL ){
608+ strncat (fullUrl , clientInternal -> serverURL , urlSize );
609+ }
610+ else {
611+ strncat (fullUrl , PARSE_DEFAULT_SERVER_URL , urlSize );
612+ }
613+
614+
555615 strncat (fullUrl , httpPath , urlSize - strlen (fullUrl ));
556616 if (getRequestBody ) {
557617 strncat (fullUrl , "?" , urlSize - strlen (fullUrl ));
0 commit comments