const char* roadmap_tripserver_response(int status, int NumParams, const char* pData){ int num_handlers; int i; char ResponseName[128]; int iBufferSize; iBufferSize = 128; if (status != 200){ if (NumParams){ pData = ExtractNetworkString( pData, // [in] Source string ResponseName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",\r\n", // [in] Array of chars to terminate the copy operation TRIM_ALL_CHARS); // [in] Remove additional termination chars if (status != 500) roadmap_log( ROADMAP_ERROR, "roadmap_tripserver_response- Command failed (status= %d,%s )",status,ResponseName ); for( i=0; i<NumParams -1; i++){ iBufferSize = 128; ResponseName[0] = 0; pData = ExtractNetworkString( pData, // [in] Source string ResponseName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",\r\n", // [in] Array of chars to terminate the copy operation TRIM_ALL_CHARS); // [in] Remove additional termination chars } } return pData; } if (NumParams){ pData = ExtractNetworkString( pData, // [in] Source string ResponseName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",\r\n", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars num_handlers = sizeof(tripserver_handlers)/sizeof(TripServeHandlers); for( i=0; i<num_handlers; i++){ if (!strcmp(ResponseName, tripserver_handlers[i].Response)){ return (*tripserver_handlers[i].handler)(NumParams-1, pData); } } } return pData; }
static const char* on_single_search_address_candidate( /* IN */ const char* data, /* IN */ void* context, /* OUT */ BOOL* more_data_needed, /* OUT */ roadmap_result* rc) { address_candidate ac; int size; char temp[100]; address_candidate_init( &ac); // Default error for early exit: (*rc) = err_parser_unexpected_data; // Expected data: // <provider><longtitude>,<latitude>,[state],[county],<city>,<street>,<house number>\n size = 100; data = ExtractNetworkString( data, // [in] Source string &temp[0], // [out,opt]Output buffer &size, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !data) { roadmap_log( ROADMAP_ERROR, "single_search::on_single_search_option() - Failed to read 'provider'"); return NULL; } if (!strcmp("waze", temp)){ return on_address_option(data, context, more_data_needed, rc); } else{ return on_local_option(data, context, more_data_needed, rc); } }
static const char* parse_search_results(roadmap_result* rc, int NumParams, const char* pData) { //Expected data: // VenueList,<id>,<name>,<address>,<crossstreet>,<city>,<state>,<zip>,<geolat>,<geolong>,<phone>,<distance>[,<id>,.....] FoursquareVenue venue; int i; char CommandName[128]; int iBufferSize; double dValue; int count; iBufferSize = 128; if (NumParams == 0) return pData; if ((NumParams - 1) % ROADMAP_FOURSQUARE_VENUE_ENTRIES != 0) { (*rc) = err_parser_unexpected_data; return NULL; } pData = ExtractNetworkString( pData, // [in] Source string CommandName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",\r\n", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if (strcmp(CommandName, "VenueList") != 0) { roadmap_log(ROADMAP_ERROR, "Foursquare - parse_search_results(): could not find command: VenueList (received: '%s')", CommandName); (*rc) = err_parser_unexpected_data; return NULL; } count = (NumParams - 1) / ROADMAP_FOURSQUARE_VENUE_ENTRIES; if (!(*pData) || count == 0) { roadmap_log(ROADMAP_DEBUG, "Foursquare - received empty venues list"); ssd_dialog_hide_all(dec_close); #ifdef IPHONE_NATIVE roadmap_main_show_root(1); #endif //IPHONE_NATIVE roadmap_messagebox_timeout("Foursquare", "We can't find anything nearby.", 5); return pData; } for (i = 0; i < count; ++i){ // 1. id iBufferSize = ROADMAP_FOURSQUARE_ID_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sId, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue id=%s", venue.sId); (*rc) = err_parser_unexpected_data; return NULL; } // 2. name iBufferSize = ROADMAP_FOURSQUARE_NAME_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sName, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue name=%s", venue.sName); (*rc) = err_parser_unexpected_data; return NULL; } // 3. address iBufferSize = ROADMAP_FOURSQUARE_ADDRESS_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sAddress, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue address=%s", venue.sAddress); (*rc) = err_parser_unexpected_data; return NULL; } // 4. crossstreet iBufferSize = ROADMAP_FOURSQUARE_CROSS_STREET_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sCrossStreet, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue crossname=%s", venue.sCrossStreet); (*rc) = err_parser_unexpected_data; return NULL; } // 5. city iBufferSize = ROADMAP_FOURSQUARE_CITY_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sCity, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue city=%s", venue.sCity); (*rc) = err_parser_unexpected_data; return NULL; } // 6. state iBufferSize = ROADMAP_FOURSQUARE_STATE_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sState, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue state=%s", venue.sState); (*rc) = err_parser_unexpected_data; return NULL; } // 7. zip iBufferSize = ROADMAP_FOURSQUARE_ZIP_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sZip, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue zip=%s", venue.sZip); (*rc) = err_parser_unexpected_data; return NULL; } // 8. lat pData = ReadDoubleFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &dValue, // [out] Output value 1); // [in] TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n' venue.iLatitude = (int) (dValue * 1000000); if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue lat=%d", venue.iLatitude); (*rc) = err_parser_unexpected_data; return NULL; } // 9. lon pData = ReadDoubleFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &dValue, // [out] Output value 1); // [in] TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n' venue.iLongitude = (int) (dValue * 1000000); if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue lon=%d", venue.iLongitude); (*rc) = err_parser_unexpected_data; return NULL; } // 10. phone iBufferSize = ROADMAP_FOURSQUARE_PHONE_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sPhone, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue phone=%s", venue.sPhone); (*rc) = err_parser_unexpected_data; return NULL; } // 11. distance pData = ReadIntFromString( pData, // [in] Source string ",\r\n", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &venue.iDistance, // [out] Put it here 1); // [in] Remove additional termination CHARS if( !pData || (!(*pData) && i < count-1)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue distance=%d", venue.iDistance); (*rc) = err_parser_unexpected_data; return NULL; } if (gsVenuesCount < ROADMAP_FOURSQUARE_MAX_VENUE_COUNT) { //skip if more venues received create_description (&venue); gsVenuesList[gsVenuesCount++] = venue; } } roadmap_main_set_periodic(100,roadmap_foursquare_venues_list); return pData; }
static const char* parse_checkin_results(roadmap_result* rc, int NumParams, const char* pData) { //Expected data: // CheckinResult,<checkin_message>,<score_points> char CommandName[128]; int iBufferSize; iBufferSize = 128; if (NumParams == 0) return pData; if ((NumParams - 1) % ROADMAP_FOURSQUARE_CHECKIN_ENTRIES != 0) { (*rc) = err_parser_unexpected_data; return NULL; } pData = ExtractNetworkString( pData, // [in] Source string CommandName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if (strcmp(CommandName, "CheckinResult") != 0) { roadmap_log(ROADMAP_ERROR, "Foursquare - parse_search_results(): could not find command: CheckinResult (received: '%s')", CommandName); (*rc) = err_parser_unexpected_data; return NULL; } // 1. checkin message iBufferSize = ROADMAP_FOURSQUARE_MESSAGE_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string gsCheckInInfo.sCheckinMessage, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_checkin_results(): Failed to read checkin message=%s", gsCheckInInfo.sCheckinMessage); (*rc) = err_parser_unexpected_data; return NULL; } // 2. name iBufferSize = ROADMAP_FOURSQUARE_SCORE_PT_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string gsCheckInInfo.sScorePoints, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",\r\n", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_checkin_results(): Failed to read score points=%s", gsCheckInInfo.sScorePoints); (*rc) = err_parser_unexpected_data; return NULL; } roadmap_main_set_periodic(100, roadmap_foursquare_checkedin_dialog); return pData; }
const char* on_suggested_trips(int NumParams,const char* pData){ int i; int iBufferSize; AltRouteTrip route; int numRecords = NumParams/7; for (i = 0; i < numRecords; i++){ if ( i%7 == 0) RealtimeAltRoutes_Init_Record(&route); //ID pData = ReadIntFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &route.iTripId,// [out] Put it here 1); // [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read ID"); return NULL; } //Src name iBufferSize = sizeof(route.sSrcName); pData = ExtractNetworkString( pData, // [in] Source string route.sSrcName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read SrcName. ID=%d",route.iTripId, route.sDestinationName ); return NULL; } //Src Lon pData = ReadIntFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &route.srcPosition.longitude,// [out] Put it here 1); // [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read Src longitude. ID=%d",route.iTripId ); return NULL; } //Src Lat pData = ReadIntFromString( pData, // [in] Source string ",\r\n", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &route.srcPosition.latitude,// [out] Put it here TRIM_ALL_CHARS); // [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read Src latitude. ID=%d",route.iTripId ); return NULL; } //Dest name iBufferSize = sizeof(route.sDestinationName); pData = ExtractNetworkString( pData, // [in] Source string route.sDestinationName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read DestName. ID=%d",route.iTripId, route.sDestinationName ); return NULL; } //Dest Lon pData = ReadIntFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &route.destPosition.longitude,// [out] Put it here 1); // [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read Destination longitude. ID=%d",route.iTripId ); return NULL; } //Dest Lat pData = ReadIntFromString( pData, // [in] Source string ",\r\n", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &route.destPosition.latitude,// [out] Put it here TRIM_ALL_CHARS); // [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_suggested_trips() - Failed to read Destination latitude. ID=%d",route.iTripId ); return NULL; } RealtimeAltRoutes_Add_Route(&route); } roadmap_alternative_routes_suggested_trip(); return pData; }
const char* on_get_pois_res(int NumParams,const char* pData){ int i; int iBufferSize; int longitude; int latitude; char poiName[MAX_POI_NAME]; char *argv[ahi__count]; char temp[20]; char msg[100]; int numRecords = NumParams/3; roadmap_log( ROADMAP_WARNING, "roadmap_tripserver_response- got GetPOIsRes (Num parameters= %d )",NumParams ); if (numRecords > 0) purge_old_favorites(); for (i = 0; i < numRecords; i++){ //POI name iBufferSize = sizeof(poiName); pData = ExtractNetworkString( pData, // [in] Source string poiName, // [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_get_pois_res() - Failed to read POI name"); return NULL; } //POI Lon pData = ReadIntFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &longitude, // [out] Put it here 1); // [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_get_pois_res() - Failed to read Destination longitude. POI Name=%s",poiName ); return NULL; } //POI Lat pData = ReadIntFromString( pData, // [in] Source string ",\r\n", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &latitude, // [out] Put it here TRIM_ALL_CHARS);// [in] Remove if (!pData){ roadmap_log( ROADMAP_ERROR, "Tripserver::on_get_pois_res() - Failed to read Destination latitude. POI Name=%s",poiName ); return NULL; } argv[ahi_house_number] = ""; argv[ahi_street] = ""; argv[ahi_city] = ""; argv[ahi_state] = ""; argv[ahi_name] = (char *)poiName; sprintf(temp, "%d", latitude); argv[ahi_latitude] = strdup(temp); sprintf(temp, "%d", longitude); argv[ahi_longtitude] = strdup(temp); argv[ahi_synced] = "true"; roadmap_log( ROADMAP_WARNING, "roadmap_tripserver_response- GetPOIsRes Adding favorite (name=%s, lat=%s, lon=%s )", argv[ahi_name], argv[ahi_latitude], argv[ahi_longtitude]); roadmap_history_add (ADDRESS_FAVORITE_CATEGORY, (const char **)argv); } ssd_progress_msg_dialog_hide(); if (numRecords == 0) sprintf(msg, "%s", roadmap_lang_get("No favorite destinations were found")); else if (numRecords == 1) sprintf(msg, "%s", roadmap_lang_get("1 destination was restored to your favorites")); else sprintf(msg, "%d %s", numRecords, roadmap_lang_get("destinations were restored to your favorites")); roadmap_messagebox_timeout("Favorites", msg, 5); roadmap_history_save(); return pData; }