9830db6ff896b5829239b84621cd8df6b0bca89b
[platform/core/location/maps-plugin-mapzen.git] / src / mapzen / mapzen_jsonparser.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <maps_coordinates.h>
18
19 #include <stdlib.h>
20
21 #include "mapzen_jsonparser.hpp"
22 #include "rapidjson/document.h"
23
24 extern "C" {
25 #include "mapzen_queue.h"
26 #include "mapzen_debug.h"
27 #include "mapzen_util.h"
28 }
29
30 #include <string>
31 #include <vector>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #define ROUTE_UNIT_CONVERSION_MILE_TO_M(x)      (1609.34 * (x))
38 #define ROUTE_UNIT_CONVERSION_MILE_TO_KM(x)     (1.60934 * (x))
39 #define ROUTE_UNIT_CONVERSION_MILE_TO_FT(x)     (5280 * (x))
40 #define ROUTE_UNIT_CONVERSION_MILE_TO_YD(x)     (1760 * (x))
41
42 static route_unit __route_unit = UNIT_M;
43 static int __maneuver_index = 0;
44 static coords_s __destination_point;
45 constexpr double kPolylinePrecision = 1E6;
46 constexpr double kInvPolylinePrecision = 1.0 / kPolylinePrecision;
47
48
49 //TODO: port this to c? or port the whole project to c++ or add all the proper externs
50 void decode_shape(const std::string& encoded,
51                          std::vector<maps_coordinates_s>& output)
52 {
53         // what byte are we looking at
54         size_t i = 0;
55
56         // Handy lambda to turn a few bytes of an encoded string into an integer
57         auto deserialize = [&encoded, &i](const int previous) {
58                 // Grab each 5 bits and mask it in where it belongs using the shift
59                 int byte, shift = 0, result = 0;
60                 do {
61                         byte = static_cast<int>(encoded[i++]) - 63;
62                         result |= (byte & 0x1f) << shift;
63                         shift += 5;
64                 } while (byte >= 0x20);
65
66                 // Undo the left shift from above or the bit flipping and add
67                 // to previous since its an offset
68                 return previous + (result & 1 ? ~(result >> 1) : (result >> 1));
69         };
70
71         // Iterate over all characters of the encoded shape string
72         int last_lon = 0, last_lat = 0;
73         while (i < encoded.length())
74         {
75                 // Decode the coordinates, lat first
76                 int lat = deserialize(last_lat);
77                 int lon = deserialize(last_lon);
78
79                 // Shift the decimal point 5 places to the left and add to the output
80                 maps_coordinates_s ll;
81                 ll.latitude  = static_cast<double>(lat) * kInvPolylinePrecision;
82                 ll.longitude = static_cast<double>(lon) * kInvPolylinePrecision;
83                 output.emplace_back(std::move(ll));
84
85                 // Remember the last one we encountered
86                 last_lat = lat;
87                 last_lon = lon;
88         }
89 }
90
91
92 static mapzen_error_e __convert_status(int status)
93 {
94         mapzen_error_e error = MAPZEN_ERROR_UNKNOWN;
95         switch (status) {
96         case 0:
97                 {
98                         /* Successful Geocode call */
99                         error = MAPZEN_ERROR_NONE;
100                         break;
101                 }
102         case 400:
103                 {
104                         /* Error with input - Illegal argument from request */
105                         error = MAPZEN_ERROR_INVALID_PARAMETER;
106                         break;
107                 }
108         case 403:
109                 {
110                         /* Key related error - Invalid key */
111                         error = MAPZEN_ERROR_KEY_NOT_AVAILABLE;
112                         break;
113                 }
114         case 500:
115                 {
116                         /* Unknown error */
117                         error = MAPZEN_ERROR_UNKNOWN;
118                         break;
119                 }
120         case -1:
121                 {
122                         /* Network error */
123                         error = MAPZEN_ERROR_NETWORK_UNREACHABLE;
124                         break;
125                 }
126         }
127
128         return error;
129 }
130
131 bool __get_string(const rapidjson::Value& obj, const char* key, char** value)
132 {
133         //if we have the key and its not an empty value
134         rapidjson::Value::ConstMemberIterator itr = obj.FindMember(key);
135         if(itr != obj.MemberEnd() && itr->value.GetStringLength()){
136                 (*value) = (gchar *)g_malloc(itr->value.GetStringLength() + sizeof(rapidjson::Document::Ch));
137                 strncpy((*value), itr->value.GetString(), itr->value.GetStringLength());
138                 memset((*value) + itr->value.GetStringLength(), 0, sizeof(rapidjson::Document::Ch));
139         //we had nothing
140         } else {
141                 (*value) = NULL;
142         }
143         //is this something
144         return *value != NULL;
145 }
146
147 /************ GEOCODE ***************/
148
149
150 static void __parse_geocode_response(char *response, int size, int *status, GList **coordsList)
151 {
152         MAP_DEBUG("Inside __parse_geocode_response..");
153
154
155         if (!response || !status || !coordsList) return;
156
157         //so far we have nothing
158         *coordsList = NULL;
159         *status = 500;
160
161         //crack open that json
162         rapidjson::Document document;
163         document.Parse(std::string(response, size).c_str());
164         rapidjson::Value::ConstMemberIterator features = document.FindMember("features");
165         if(features != document.MemberEnd() && features->value.IsArray()) {
166                 //for each feature
167                 for (rapidjson::Value::ConstValueIterator f = features->value.Begin(); f != features->value.End(); ++f) {
168                         //it has to have geometry
169                         rapidjson::Value::ConstMemberIterator geom = f->FindMember("geometry");
170                         if(geom != f->MemberEnd()) {
171                                 //skip non-points
172                                 rapidjson::Value::ConstMemberIterator type = geom->value.FindMember("type");
173                                 if(type == geom->value.MemberEnd() || strcmp(type->value.GetString(), "Point"))
174                                         continue;
175                                 //get actual points
176                                 rapidjson::Value::ConstMemberIterator coords = geom->value.FindMember("coordinates");
177                                 if(coords == geom->value.MemberEnd() || !coords->value.IsArray() || coords->value.Size() != 2)
178                                         continue;
179
180                                 coords_s *coord = (coords_s *)g_malloc0(sizeof(coords_s));
181                                 if (coord != NULL) {
182                                         coord->longitude = coords->value[0].GetDouble();
183                                         coord->latitude = coords->value[1].GetDouble();
184                                 }
185
186                                 if (*coordsList == NULL)
187                                         *coordsList = g_list_append(*coordsList, coord);
188                                 else
189                                         *coordsList = g_list_insert_before(*coordsList, NULL, coord);
190                         }
191                 }
192         }
193         *status = 0;
194 }
195
196 /****************** REVERSE GEOCODE *********************/
197
198 static void __parse_revgeocode_response(char *response, int size, int *status, mapzen_address_resp_s **respAddr)
199 {
200         if (!response || !status || !respAddr) return;
201
202         //so far we have nothing
203         *respAddr = NULL;
204         *status = 500;
205
206         //crack open that json
207         rapidjson::Document document;
208         document.Parse(std::string(response, size).c_str());
209         rapidjson::Value::ConstMemberIterator features = document.FindMember("features");
210         if(features != document.MemberEnd() && features->value.IsArray()) {
211                 //for each feature
212                 for (rapidjson::Value::ConstValueIterator f = features->value.Begin(); f != features->value.End(); ++f) {
213                         //it has to have geometry
214                         rapidjson::Value::ConstMemberIterator geom = f->FindMember("geometry");
215                         if(geom != f->MemberEnd()) {
216                                 //skip non-points
217                                 rapidjson::Value::ConstMemberIterator type = geom->value.FindMember("type");
218                                 if(type == geom->value.MemberEnd() || strcmp(type->value.GetString(), "Point"))
219                                         continue;
220                                 //get actual points
221                                 rapidjson::Value::ConstMemberIterator coords = geom->value.FindMember("coordinates");
222                                 if(coords == geom->value.MemberEnd() || !coords->value.IsArray() || coords->value.Size() != 2)
223                                         continue;
224
225                                 //NOTE: it seems as though the tizen maps plugin api assumes that reverse geocode results will
226                                 //actually be at the coordinates where you requested the reverse geocode. the mapzen api can return
227                                 //POIS which are some distance away from the location and currently this is not accounted for :o(
228
229                                 //get out the address information
230                                 rapidjson::Value::ConstMemberIterator properties = f->FindMember("properties");
231                                 if(properties != f->MemberEnd()) {
232                                         //fill this out as we go
233                                         *respAddr = (mapzen_address_resp_s *)g_malloc(sizeof(mapzen_address_resp_s));
234                                         bool something = false;
235                                         something = __get_string(properties->value, "street", &(*respAddr)->street) || something;
236                                         something = __get_string(properties->value, "neighbourhood", &(*respAddr)->neighbourhood) || something;
237                                         something = __get_string(properties->value, "housenumber", &(*respAddr)->housenumber) || something;
238                                         something = __get_string(properties->value, "localadmin", &(*respAddr)->localadmin) || something;
239                                         something = __get_string(properties->value, "county", &(*respAddr)->county) || something;
240                                         something = __get_string(properties->value, "region", &(*respAddr)->region) || something;
241                                         something = __get_string(properties->value, "country", &(*respAddr)->country) || something;
242                                         something = __get_string(properties->value, "country_a", &(*respAddr)->country_a) || something;
243                                         something = __get_string(properties->value, "postalcode", &(*respAddr)->postalcode) || something;
244                                         //if everything was null thats pretty much unusable
245                                         //TODO: these are pretty weak criteria..
246                                         if(!something) {
247                                                 g_free(*respAddr);
248                                                 (*respAddr) = NULL;
249                                         //forget the rest, we have one with something in it
250                                         } else {
251                                                 break;
252                                         }
253                                 }
254                         }
255                 }
256         }
257         *status = 0;
258 }
259
260 /****************  PLACE SEARCH ********************/
261
262 static void __parse_place_response(char *response, int size, GList **placeList)
263 {
264         MAP_DEBUG("Inside __parse_place_response.");
265
266         if (!response || !placeList) return;
267
268         *placeList = NULL;
269
270         //crack open that json
271         rapidjson::Document document;
272         document.Parse(std::string(response, size).c_str());
273         rapidjson::Value::ConstMemberIterator features = document.FindMember("features");
274         if(features != document.MemberEnd() && features->value.IsArray()) {
275                 //for each feature
276                 for (rapidjson::Value::ConstValueIterator f = features->value.Begin(); f != features->value.End(); ++f) {
277                         //it has to have geometry
278                         rapidjson::Value::ConstMemberIterator geom = f->FindMember("geometry");
279                         if(geom != f->MemberEnd()) {
280                                 //skip non-points
281                                 rapidjson::Value::ConstMemberIterator type = geom->value.FindMember("type");
282                                 if(type == geom->value.MemberEnd() || strcmp(type->value.GetString(), "Point"))
283                                         continue;
284                                 //get actual points
285                                 rapidjson::Value::ConstMemberIterator coords = geom->value.FindMember("coordinates");
286                                 if(coords == geom->value.MemberEnd() || !coords->value.IsArray() || coords->value.Size() != 2)
287                                         continue;
288
289                                 coords_s coordinate;
290                                 coordinate.longitude = coords->value[0].GetDouble();
291                                 coordinate.latitude = coords->value[1].GetDouble();
292
293                                 //get out the address information
294                                 rapidjson::Value::ConstMemberIterator properties = f->FindMember("properties");
295                                 if(properties != f->MemberEnd()) {
296                                         //fill this out as we go
297                                         mapzen_place_resp_s *respPlaces = (mapzen_place_resp_s *)g_malloc0(sizeof(mapzen_place_resp_s));
298
299                                         respPlaces->place_id = NULL;
300                                         respPlaces->categories = NULL;
301                                         respPlaces->display_name = NULL;
302                                         respPlaces->address = NULL;
303
304                                         bool something = false;
305                                         something = __get_string(properties->value, "gid", &respPlaces->place_id) || something;
306                                         something = __get_string(properties->value, "name", &respPlaces->display_name) || something;
307
308                                         respPlaces->address = (mapzen_address_resp_s *)g_malloc(sizeof(mapzen_address_resp_s));
309
310                                         something = __get_string(properties->value, "housenumber", &respPlaces->address->housenumber) || something;
311                                         something = __get_string(properties->value, "street", &respPlaces->address->street) || something;
312                                         something = __get_string(properties->value, "neighbourhood", &respPlaces->address->neighbourhood) || something;
313                                         something = __get_string(properties->value, "county", &respPlaces->address->county) || something;
314                                         something = __get_string(properties->value, "region", &respPlaces->address->region) || something;
315                                         something = __get_string(properties->value, "country", &respPlaces->address->country) || something;
316                                         something = __get_string(properties->value, "country_a", &respPlaces->address->country_a) || something;
317                                         something = __get_string(properties->value, "locality", &respPlaces->address->localadmin) || something;
318                                         something = __get_string(properties->value, "postalcode", &respPlaces->address->postalcode) || something;
319
320                                         respPlaces->coordinates = coordinate;
321
322                                         respPlaces->categories = NULL;
323                                         rapidjson::Value::ConstMemberIterator categories = properties->value.FindMember("category");
324                                         if (categories != geom->value.MemberEnd() && categories->value.IsArray()) {
325                                                 for (rapidjson::SizeType i = 0; i < categories->value.Size(); i++) {
326                                                         if (respPlaces->categories == NULL)
327                                                                 respPlaces->categories = g_list_append(respPlaces->categories, g_strdup(categories->value[i].GetString()));
328                                                         else
329                                                                 respPlaces->categories = g_list_insert_before(respPlaces->categories, NULL, g_strdup(categories->value[i].GetString()));
330                                                 }
331                                         }
332
333                                         if(!something) {
334                                                 g_free(respPlaces);
335                                                 respPlaces = NULL;
336                                         } else {
337                                                 if (*placeList == NULL)
338                                                         *placeList = g_list_append(*placeList, respPlaces);
339                                                 else
340                                                         *placeList = g_list_insert_before(*placeList, NULL, respPlaces);
341                                         }
342                                 }
343                         }
344                 }
345         }
346 }
347
348 /********************* ROUTE RESPONSE ***********************/
349
350 static void __parse_route_response(char *response, int size, int *status, mapzen_route_resp_s **routeResp)
351 {
352         if (!response || !status || !routeResp) return;
353
354         *routeResp = NULL;
355 }
356
357 void post_curl_response(char *response, int size, mapzen_resp_type type, void *user_data)
358 {
359         if (!response) return;
360
361         if (!user_data) {
362                 MAP_DEBUG("Response data is NULL");
363                 return;
364         }
365
366         MAP_DEBUG("Response received from Curl. [Size=%d]", size);
367         switch (type) {
368         case RESP_TYPE_GEOCODE:
369                 {
370                         MAP_DEBUG("Inside Geocode JSON Parsing..");
371                         int status = -1;
372                         MapzenGeocodeQueryData *queryData = (MapzenGeocodeQueryData *)user_data;
373                         MapzenGeocodeResponseData *responseData = (MapzenGeocodeResponseData *)g_malloc(sizeof(MapzenGeocodeResponseData));
374
375                         if (responseData) {
376                                 responseData->requestId = queryData->requestId;
377                                 responseData->geocode_cb = queryData->geocode_cb;
378                                 responseData->user_data = queryData->user_data;
379
380                                 if (response && (size > 0)) {
381                                         GList *coordsList = NULL;
382                                         __parse_geocode_response(response, size, &status, &coordsList);
383
384                                         if (coordsList != NULL) {
385                                                 /* Put the response in queue */
386                                                 responseData->error = __convert_status(status);
387                                                 responseData->coords = coordsList;
388                                         } else {
389                                                 /* Response parsing failure */
390                                                 responseData->error = __convert_status(status);
391                                                 responseData->coords = NULL;
392                                         }
393                                 } else {
394                                         responseData->error = __convert_status(status);
395                                         responseData->coords = NULL;
396                                 }
397
398                                 mapzen_push_to_queue(type, (gpointer)responseData);
399                         }
400
401                         if (queryData) {
402                                 g_free(queryData);
403                                 queryData = NULL;
404                         }
405                         break;
406                 }
407         case RESP_TYPE_REVGEOCODE:
408                 {
409                         MAP_DEBUG("Inside Rev Geocode JSON Parsing..");
410                         int status = -1;
411                         MapzenRevGeocodeQueryData *queryData = (MapzenRevGeocodeQueryData *)user_data;
412                         MapzenRevGeocodeResponseData *responseData = (MapzenRevGeocodeResponseData *)g_malloc(sizeof(MapzenRevGeocodeResponseData));
413
414                         if (responseData) {
415                                 responseData->requestId = queryData->requestId;
416                                 responseData->reverse_geocode_cb = queryData->reverse_geocode_cb;
417                                 responseData->user_data = queryData->user_data;
418
419                                 if (response && (size > 0)) {
420                                         /* Coords Result GList */
421                                         mapzen_address_resp_s *addrResponse = NULL;
422
423                                         MAP_DEBUG("Rev Geocode :- Parsing json Response");
424                                         __parse_revgeocode_response(response, size, &status, &addrResponse);
425
426                                         if (addrResponse != NULL) {
427                                                 /* Put the response in queue */
428                                                 responseData->error = __convert_status(status);
429                                                 responseData->addressDetails = addrResponse;
430                                         } else {
431                                                 /* REPSONSE PARSING FAILURE */
432                                                 MAP_DEBUG("addr Response is NULL");
433                                                 responseData->error = __convert_status(status);
434                                                 responseData->addressDetails = NULL;
435                                         }
436                                 } else {
437                                         MAP_DEBUG("JSON Response is NULL..");
438                                         responseData->error = __convert_status(status);
439                                         responseData->addressDetails = NULL;
440                                 }
441                                 mapzen_push_to_queue(type, (gpointer)responseData);
442                         }
443
444                         if (queryData) {
445                                 g_free(queryData);
446                                 queryData = NULL;
447                         }
448                         break;
449                 }
450         case RESP_TYPE_PLACES:
451                 {
452                         MAP_DEBUG("Inside Places JSON Parsing..");
453                         MapzenPlaceQueryData *queryData = (MapzenPlaceQueryData *)user_data;
454                         MapzenPlaceResponseData *responseData = (MapzenPlaceResponseData *)g_malloc(sizeof(MapzenPlaceResponseData));
455
456                         if (responseData) {
457                                 responseData->requestId = queryData->requestId;
458                                 responseData->place_search_cb = queryData->place_search_cb;
459                                 responseData->user_data = queryData->user_data;
460
461                                 if (response && (size > 0)) {
462                                         /* Coords Result GList */
463                                         GList *placeList = NULL;
464
465                                         MAP_DEBUG("Search Places :- Parsing Json Response");
466                                         __parse_place_response(response, size, &placeList);
467
468                                         if (placeList != NULL) {
469                                                 /* Put the response in queue */
470                                                 responseData->error = MAPZEN_ERROR_NONE;
471                                                 responseData->places = placeList;
472                                         } else {
473                                                 /* REPSONSE PARSING FAILURE */
474                                                 MAP_DEBUG("addr Response is NULL");
475                                                 responseData->error = MAPZEN_ERROR_UNKNOWN;
476                                                 responseData->places = NULL;
477                                         }
478                                 } else {
479                                         responseData->error = MAPZEN_ERROR_UNKNOWN;
480                                         responseData->places = NULL;
481                                 }
482
483                                 mapzen_push_to_queue(type, (gpointer)responseData);
484                         }
485
486                         if (queryData) {
487                                 g_free(queryData);
488                                 queryData = NULL;
489                         }
490
491                         break;
492                 }
493         case RESP_TYPE_PLACES_DETAILS:
494                 {
495                         MAP_DEBUG("Inside Places Details JSON Parsing..");
496                         MapzenPlaceDetailsQueryData *queryData = (MapzenPlaceDetailsQueryData *)user_data;
497                         MapzenPlaceDetailsResponseData *responseData = (MapzenPlaceDetailsResponseData *)g_malloc(sizeof(MapzenPlaceDetailsResponseData));
498
499                         if (responseData) {
500                                 responseData->requestId = queryData->requestId;
501                                 responseData->get_place_details_cb = queryData->get_place_details_cb;
502                                 responseData->user_data = queryData->user_data;
503
504                                 if (response && (size > 0)) {
505                                         /* Coords Result GList */
506                                         GList *placeList = NULL;
507
508                                         MAP_DEBUG("Search Places Details :- Parsing Json Response");
509                                         __parse_place_response(response, size, &placeList);
510
511                                         if (placeList != NULL) {
512                                                 /* Put the response in queue */
513                                                 responseData->error = MAPZEN_ERROR_NONE;
514                                                 responseData->places = placeList;
515                                         } else {
516                                                 /* REPSONSE PARSING FAILURE */
517                                                 MAP_DEBUG("addr Response is NULL");
518                                                 responseData->error = MAPZEN_ERROR_UNKNOWN;
519                                                 responseData->places = NULL;
520                                         }
521                                 } else {
522                                         responseData->error = MAPZEN_ERROR_UNKNOWN;
523                                         responseData->places = NULL;
524                                 }
525
526                                 mapzen_push_to_queue(type, (gpointer)responseData);
527                         }
528
529                         if (queryData) {
530                                 g_free(queryData);
531                                 queryData = NULL;
532                         }
533
534                         break;
535                 }
536         case RESP_TYPE_PLACES_LIST:
537                 {
538                         MAP_DEBUG("Inside Places List JSON Parsing..");
539                         MapzenPlaceListQueryData *queryData = (MapzenPlaceListQueryData *)user_data;
540                         MapzenPlaceListResponseData *responseData = (MapzenPlaceListResponseData *)g_malloc(sizeof(MapzenPlaceListResponseData));
541
542                         if (responseData) {
543                                 responseData->requestId = queryData->requestId;
544                                 responseData->place_list_search_cb = queryData->place_list_search_cb;
545                                 responseData->user_data = queryData->user_data;
546
547                                 if (response && (size > 0)) {
548                                         /* Coords Result GList */
549                                         GList *placeList = NULL;
550
551                                         MAP_DEBUG("Search Places :- Parsing Json Response");
552                                         __parse_place_response(response, size, &placeList);
553
554                                         if (placeList != NULL) {
555                                                 /* Put the response in queue */
556                                                 responseData->error = MAPZEN_ERROR_NONE;
557                                                 responseData->places = placeList;
558                                         } else {
559                                                 /* REPSONSE PARSING FAILURE */
560                                                 MAP_DEBUG("addr Response is NULL");
561                                                 responseData->error = MAPZEN_ERROR_UNKNOWN;
562                                                 responseData->places = NULL;
563                                         }
564                                 } else {
565                                         responseData->error = MAPZEN_ERROR_UNKNOWN;
566                                         responseData->places = NULL;
567                                 }
568
569                                 mapzen_push_to_queue(type, (gpointer)responseData);
570                         }
571
572                         if (queryData) {
573                                 g_free(queryData);
574                                 queryData = NULL;
575                         }
576
577                         break;
578                 }
579         case RESP_TYPE_ROUTE:
580                 {
581                         MAP_DEBUG("Inside Route JSON Parsing..");
582                         int status = -1;
583                         MapzenRouteQueryData *queryData = (MapzenRouteQueryData *)user_data;
584                         __route_unit = queryData->unit;
585                         __maneuver_index = 0;
586                         __destination_point = queryData->destination;
587
588                         MapzenRouteResponseData *responseData = (MapzenRouteResponseData *)g_malloc(sizeof(MapzenRouteResponseData));
589
590                         if (responseData) {
591                                 responseData->requestId = queryData->requestId;
592                                 responseData->route_cb = queryData->route_cb;
593                                 responseData->user_data = queryData->user_data;
594
595                                 if (response && (size > 0)) {
596                                         /* Coords Result GList */
597                                         mapzen_route_resp_s *routeResponse = NULL;
598
599                                         MAP_DEBUG("Route :- Parsing Response");
600                                         __parse_route_response(response, size, &status, &routeResponse);
601
602                                         if (routeResponse != NULL) {
603                                                 /* Put the response in queue */
604                                                 responseData->error = __convert_status(status);
605                                                 responseData->routeResponse = routeResponse;
606                                         } else {
607                                                 /* REPSONSE PARSING FAILURE */
608                                                 MAP_DEBUG("route Response is NULL");
609                                                 responseData->error = __convert_status(status);
610                                                 responseData->routeResponse = NULL;
611                                         }
612                                 } else {
613                                         responseData->error = __convert_status(status);
614                                         responseData->routeResponse = NULL;
615                                 }
616
617                                 mapzen_push_to_queue(type, (gpointer)responseData);
618                         }
619
620                         if (queryData) {
621                                 g_free(queryData);
622                                 queryData = NULL;
623                         }
624
625                         break;
626                 }
627         default:
628                 {
629                         MAP_DEBUG("Inside default JSON Parsing..");
630                         break;
631                 }
632         }
633 }
634
635 #ifdef __cplusplus
636 }
637 #endif