示例#1
0
const char* on_create_poi_res(int NumParams,const char*  pData){
   char *argv[ahi__count];
   void * history;
   int id;

   //ID
   pData = ReadIntFromString(
                         pData,         //   [in]      Source string
                         ",\r\n",           //   [in,opt]   Value termination
                         NULL,          //   [in,opt]   Allowed padding
                         &id,    //   [out]      Put it here
                         TRIM_ALL_CHARS);            //   [in]      Remove
    if (!pData){
       roadmap_log( ROADMAP_ERROR, "Tripserver::on_create_poi_res() - Failed to read ID");
       return NULL;
    }

    if (id > MAX_REQUESTS)
       return pData;
    roadmap_log( ROADMAP_DEBUG, "on_create_poi_res - id=%d",id );
    history = g_request_cursors[id];
    if (history == NULL)
       return pData;

    roadmap_history_get (ADDRESS_FAVORITE_CATEGORY, history, argv);
    roadmap_log( ROADMAP_DEBUG, "on_create_poi_res updating favorite id=%d name=%s",id, argv[ahi_name] );
    argv[ahi_synced] = "true";
    roadmap_history_update(history, ADDRESS_FAVORITE_CATEGORY, argv);
    roadmap_history_save();
    g_request_cursors[id] = NULL;
    return pData;
}
示例#2
0
const char* on_get_num_pois_res(int NumParams,const char*  pData){
   int num_Pois;

   roadmap_log( ROADMAP_WARNING, "roadmap_tripserver_response- got  GetNumPOIsRes (Num parameters= %d )",NumParams );

   //NumPois
   pData = ReadIntFromString(
                           pData,         //   [in]      Source string
                           ",\r\n",           //   [in,opt]   Value termination
                           NULL,          //   [in,opt]   Allowed padding
                           &num_Pois,    //   [out]      Put it here
                           1);            //   [in]      Remove
   if (!pData){
      roadmap_log( ROADMAP_ERROR, "Tripserver::on_get_num_pois_res() - Failed to read num pois" );
      return NULL;
   }

   if (num_Pois > 0){
      roadmap_trip_server_restore_favorites();
   }
   return pData;
}
示例#3
0
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;
}
示例#4
0
const char *on_server_config (/* IN  */const char* data,
/* IN  */void* context,
/* OUT */BOOL* more_data_needed,
/* OUT */roadmap_result* rc) {

   int serial;
   int size;
   char category[256];
   char key[256];
   char value[256];
   RoadMapConfigDescriptor param;

   // Default error for early exit:
   (*rc) = err_parser_unexpected_data;
   // Expected data:
   // <serial> <category> <key> <value>

   // Serial
   data = ReadIntFromString (data, //   [in]      Source string
            ",", //   [in,opt]  Value termination
            NULL, //   [in,opt]  Allowed padding
            &serial, //   [out]     Output value
            1); //   [in]      TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n'

   if (!data) {
      roadmap_log (ROADMAP_ERROR,"on_serve_config() - Failed to read 'serial'" );
      return NULL;
   }

   // Category
   size = sizeof (category);
   data = ExtractString (data, category, &size, ",", 1);
   if (!data) {
      roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'category' serial = %d", serial);
      return NULL;
   }

   // Key
   size = sizeof (key);
   data = ExtractString (data, key, &size, ",", 1);
   if (!data) {
      roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'key' serial = %d", serial);
      return NULL;
   }

   // Value
   size = sizeof (value);
   data = ExtractString (data, value, &size, ",\r\n", TRIM_ALL_CHARS);
   if (!data) {
      roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'value' serial = %d", serial);
      return NULL;
   }

   (*rc) = succeeded;
   roadmap_log (ROADMAP_INFO, "got ServerConfig message - serial=%d out of %d, category=%s, key=%s, value=%s",serial+1, GeoConfigContext.num_results, category, key, value );

   GeoConfigContext.num_received++;

   param.category = strdup(category);
   param.name = strdup(key);
   roadmap_config_declare("preferences",&param, "", NULL);
   parse_string( value );
   roadmap_config_set(&param,value);

   if (GeoConfigContext.num_received == GeoConfigContext.num_results) {
      roadmap_log (ROADMAP_INFO, "GeoServerConfig, Got all results... " );
      on_recieved_completed();
   }

   (*rc) = succeeded;
   return data;
}
示例#5
0
const char *on_geo_server_config (/* IN  */const char* data,
/* IN  */void* context,
/* OUT */BOOL* more_data_needed,
/* OUT */roadmap_result* rc) {

   int size;
   // Default error for early exit:
   (*rc) = err_parser_unexpected_data;

   init_context ();

   // Expected data:
   //   <id> <name> <RTServerID> <lang> <num_parameters><version>

   // ID
   data = ReadIntFromString (data, //   [in]      Source string
            ",", //   [in,opt]  Value termination
            NULL, //   [in,opt]  Allowed padding
            &GeoConfigContext.id, //   [out]     Output value
            1); //   [in]      TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n'

   if (!data) {
      roadmap_log (ROADMAP_ERROR,"on_geo_server_config() - Failed to read 'ID'" );
      return NULL;
   }

   // Name
   size = sizeof (GeoConfigContext.name);
   data = ExtractString (data, GeoConfigContext.name, &size, ",", 1);
   if (!data) {
       roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'name'");
       return NULL;
   }


   // lang
   size = sizeof (GeoConfigContext.lang);
   data = ExtractString (data, GeoConfigContext.lang, &size, ",", 1);
   if (!data) {
       roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'lang'");
       return NULL;
   }



   // num_paramerets
   data = ReadIntFromString(  data,                            //   [in]      Source string
                               ",",                        //   [in,opt]  Value termination
                               NULL,                           //   [in,opt]  Allowed padding
                               &GeoConfigContext.num_results,  //   [out]     Output value
                               1);                //   [in]      TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n'

   if (!data) {
       roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'num_parameters'");
       return NULL;
   }


   // version
   data = ReadIntFromString(  data,                            //   [in]      Source string
                               ",\r\n",                        //   [in,opt]  Value termination
                               NULL,                           //   [in,opt]  Allowed padding
                               &GeoConfigContext.version,  //   [out]     Output value
                               TRIM_ALL_CHARS);                //   [in]      TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n'

   if (!data) {
       roadmap_log (ROADMAP_ERROR, "on_geo_server_config() - Failed to read 'version'");
       return NULL;
   }

   roadmap_log (ROADMAP_DEBUG, "got GeoServerConfig message - Id=%d, name=%s lang=%s, num_parameters=%d version=%d",GeoConfigContext.id, GeoConfigContext.name, GeoConfigContext.lang, GeoConfigContext.num_results, GeoConfigContext.version );
   if (GeoConfigContext.num_results == 0){
      roadmap_log (ROADMAP_DEBUG, "GeoServerConfig, No Parameters passed. Completing... " );
      on_recieved_completed();
   }

   (*rc) = succeeded;
   return data;
}
示例#6
0
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;
}
示例#7
0
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;
}