#include "mapquest_debug.h"
#include "mapquest_queue.h"
#include "mapquest_restcurl.h"
+#include "mapquest_util.h"
#define GEOCODE_URL "https://open.mapquestapi.com/geocoding/v1/address?key=%s&inFormat=kvp&outFormat=json"
else
snprintf(tmpStr, sizeof(tmpStr), GEOCODE_URL, "null");
- strcpy(url, tmpStr);
+ STRCPY(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&boundingBox=%f,%f,%f,%f", top_left.latitude, top_left.longitude, bottom_right.latitude, bottom_right.longitude);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&maxResults=%d", num_results);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&location=%s", address);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
add_handle(url, REQ_TYPE_GEOCODE, user_data);
else
snprintf(tmpStr, sizeof(tmpStr), GEOCODE_URL, "null");
- strcpy(url, tmpStr);
+ STRCPY(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&maxResults=%d", num_results);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&location=%s", address);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
add_handle(url, REQ_TYPE_GEOCODE, user_data);
#include "mapquest_jsonparser.h"
#include "mapquest_queue.h"
#include "mapquest_debug.h"
+#include "mapquest_util.h"
#define ROUTE_UNIT_CONVERSION_MILE_TO_M(x) (1609.34 * (x))
#define ROUTE_UNIT_CONVERSION_MILE_TO_KM(x) (1.60934 * (x))
/* Street Address */
if (streetAddr != NULL) {
(*respAddr)->street_add = (gchar *)g_malloc(strlen((char *)streetAddr) + 1);
- strcpy((*respAddr)->street_add, (char *) streetAddr);
+ STRCPY((*respAddr)->street_add, (char *) streetAddr);
} else {
MAP_DEBUG("street is NULL");
(*respAddr)->street_add = NULL;
/* Neighbourhood */
if (neighbourhood != NULL) {
(*respAddr)->neighbourhood = (gchar *)g_malloc(strlen((char *)neighbourhood) + 1);
- strcpy((*respAddr)->neighbourhood, (char *) neighbourhood);
+ STRCPY((*respAddr)->neighbourhood, (char *) neighbourhood);
} else {
MAP_DEBUG("neighbourhood is NULL");
(*respAddr)->neighbourhood = NULL;
/* City */
if (city != NULL) {
(*respAddr)->city = (gchar *)g_malloc(strlen((char *)city) + 1);
- strcpy((*respAddr)->city, (char *) city);
+ STRCPY((*respAddr)->city, (char *) city);
} else {
MAP_DEBUG("city is NULL");
(*respAddr)->city = NULL;
/* County */
if (county != NULL) {
(*respAddr)->county = (gchar *)g_malloc(strlen((char *)county) + 1);
- strcpy((*respAddr)->county, (char *) county);
+ STRCPY((*respAddr)->county, (char *) county);
} else {
MAP_DEBUG("county is NULL");
(*respAddr)->county = NULL;
/* State */
if (state != NULL) {
(*respAddr)->state = (gchar *)g_malloc(strlen((char *)state) + 1);
- strcpy((*respAddr)->state, (char *) state);
+ STRCPY((*respAddr)->state, (char *) state);
} else {
MAP_DEBUG("state is NULL");
(*respAddr)->state = NULL;
/* Country */
if (country != NULL) {
(*respAddr)->country = (gchar *)g_malloc(strlen((char *)country) + 1);
- strcpy((*respAddr)->country, (char *) country);
+ STRCPY((*respAddr)->country, (char *) country);
} else {
MAP_DEBUG("country is NULL");
(*respAddr)->country = NULL;
/* Postal Code */
if (postalCode != NULL) {
(*respAddr)->postal_code = (gchar *)g_malloc(strlen((char *)postalCode) + 1);
- strcpy((*respAddr)->postal_code, (char *) postalCode);
+ STRCPY((*respAddr)->postal_code, (char *) postalCode);
} else {
MAP_DEBUG("postal_code is NULL");
(*respAddr)->postal_code = NULL;
int length = json_array_get_length(streetsArray);
char street_name[512];
- strcpy(street_name, "");
+ STRCPY(street_name, "");
int index = 0;
for (index = 0; index < length; index++) {
char *name = (char *) json_array_get_string_element(streetsArray, index);
if (index == 0) {
strncpy(street_name, name, sizeof(street_name)-1);
} else {
- strcat(street_name, "/");
+ STRCAT(street_name, "/");
strncat(street_name, name, sizeof(street_name)-strlen(street_name)-1);
}
}
if (strlen(street_name) > 0) {
(*maneuver)->street_name = (gchar *)g_malloc0((strlen((char *)street_name)) + 1);
if ((*maneuver)->street_name)
- strcpy((*maneuver)->street_name, (char *) street_name);
+ STRCPY((*maneuver)->street_name, (char *) street_name);
} else {
(*maneuver)->street_name = NULL;
}
char url[1024];
char tmpStr[512];
- strcpy(url, PLACES_URL);
+ STRCPY(url, PLACES_URL);
if (search_str != NULL) {
snprintf(tmpStr, sizeof(tmpStr), "&q=%s", search_str);
}
}
- strcat(url, "&bounded=1");
+ STRCAT(url, "&bounded=1");
}
- strcat(url, "&addressdetails=1");
+ STRCAT(url, "&addressdetails=1");
if (num_res > 0) {
snprintf(tmpStr, sizeof(tmpStr), "&limit=%d", num_res);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
}
add_handle(url, REQ_TYPE_PLACES, user_data);
#include "mapquest_debug.h"
#include "mapquest_queue.h"
#include "mapquest_restcurl.h"
+#include "mapquest_util.h"
#define REVERSE_GEOCODE_URL "https://open.mapquestapi.com/geocoding/v1/reverse?key=%s&outFormat=json"
else
snprintf(tmpStr, sizeof(tmpStr), REVERSE_GEOCODE_URL, "null");
- strcpy(url, tmpStr);
+ STRCPY(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&location=%f,%f", latitude, longitude);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
add_handle(url, REQ_TYPE_REVGEOCODE, user_data);
#include "mapquest_debug.h"
#include "mapquest_queue.h"
#include "mapquest_restcurl.h"
+#include "mapquest_util.h"
#define ROUTE_URL "https://open.mapquestapi.com/directions/v2/route?key=%s&ambiguities=ignore&outFormat=json&shapeFormat=raw&generalize=0"
int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_type type, route_feature_avoids avoids, route_driving_style style, GList *waypoints, gpointer user_data)
{
- char url[1024];
+ char url[1024] = "";
char tmpStr[512];
if (maps_key != NULL)
else
snprintf(tmpStr, sizeof(tmpStr), ROUTE_URL, "null");
- strcpy(url, tmpStr);
+ STRCPY(url, tmpStr);
- strcat(url, "&unit=m"); /* Keeping default as miles and conversion will be done later */
+ STRCAT(url, "&unit=m"); /* Keeping default as miles and conversion will be done later */
if (type == ROUTE_TYPE_FASTEST)
- strcat(url, "&routeType=fastest");
+ STRCAT(url, "&routeType=fastest");
else if (type == ROUTE_TYPE_SHORTEST)
- strcat(url, "&routeType=shortest");
+ STRCAT(url, "&routeType=shortest");
else if (type == ROUTE_TYPE_PEDESTRIAN)
- strcat(url, "&routeType=pedestrian");
+ STRCAT(url, "&routeType=pedestrian");
else if (type == ROUTE_TYPE_MULTIMODAL)
- strcat(url, "&routeType=multimodal");
+ STRCAT(url, "&routeType=multimodal");
else if (type == ROUTE_TYPE_BICYCLE)
- strcat(url, "&routeType=bicycle");
+ STRCAT(url, "&routeType=bicycle");
if (avoids == ROUTE_AVOID_LIMITED_ACCESS)
- strcat(url, "&avoids=Limited Access");
+ STRCAT(url, "&avoids=Limited Access");
else if (avoids == ROUTE_AVOID_TOLL_ROAD)
- strcat(url, "&avoids=Tollroad");
+ STRCAT(url, "&avoids=Tollroad");
else if (avoids == ROUTE_AVOID_FERRY)
- strcat(url, "&avoids=Ferry");
+ STRCAT(url, "&avoids=Ferry");
else if (avoids == ROUTE_AVOID_UNPAVED)
- strcat(url, "&avoids=Unpaved");
+ STRCAT(url, "&avoids=Unpaved");
else if (avoids == ROUTE_AVOID_SEASONAL_CLOSURE)
- strcat(url, "&avoids=Approximate Seasonal Closure");
+ STRCAT(url, "&avoids=Approximate Seasonal Closure");
else if (avoids == ROUTE_AVOID_COUNTRY_BORDER_CROSSING)
- strcat(url, "&avoids=Country border crossing");
+ STRCAT(url, "&avoids=Country border crossing");
if (style == DRIVING_STYLE_NORMAL)
- strcat(url, "&drivingStyle=2");
+ STRCAT(url, "&drivingStyle=2");
else if (style == DRIVING_STYLE_CAUTIOUS)
- strcat(url, "&drivingStyle=1");
+ STRCAT(url, "&drivingStyle=1");
else if (style == DRIVING_STYLE_AGGRESSIVE)
- strcat(url, "&drivingStyle=3");
+ STRCAT(url, "&drivingStyle=3");
int length = g_list_length(waypoints);
if (length != 0) {
snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", data->latitude, data->longitude);
else
snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", data->latitude, data->longitude);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
}
waypoints_list = g_list_next(waypoints_list);
}
} else {
snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", startPoint.latitude, startPoint.longitude);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", endPoint.latitude, endPoint.longitude);
- strcat(url, tmpStr);
+ STRCAT(url, tmpStr);
}
add_handle(url, REQ_TYPE_ROUTE, user_data);
#include "mapquest_types.h"
+#define STRCPY(buffer, string) strncpy(buffer, string, sizeof(buffer)-strlen(buffer)-1)
+#define STRCAT(buffer, string) strncat(buffer, string, sizeof(buffer)-strlen(buffer)-1)
+
void calculate_point(gdouble Lat1, gdouble Lon1, int dBearing, gdouble dist, coords_s **coord);
#endif /* _MAPQUEST_UTIL_H_ */
#include "mapquest_plugin.h"
#include "mapquest_plugin_internal.h"
#include "mapquest_api.h"
+#include "mapquest_util.h"
#include <maps_error.h>
#include <maps_route_plugin.h>
#include <maps_route_segment_plugin.h>
MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
}
- char resultAddressQuery[1024];
- strcpy(resultAddressQuery, "");
+ char resultAddressQuery[1024] = "";
char *street = NULL;
maps_address_get_street(address, &street);
if (street != NULL)
- strcat(resultAddressQuery, street);
+ STRCAT(resultAddressQuery, street);
char *city = NULL;
maps_address_get_city(address, &city);
if ((strlen(resultAddressQuery) > 0) && (city != NULL)) {
- strcat(resultAddressQuery, ",");
- strcat(resultAddressQuery, city);
+ STRCAT(resultAddressQuery, ",");
+ STRCAT(resultAddressQuery, city);
} else if (city != NULL) {
- strcat(resultAddressQuery, city);
+ STRCAT(resultAddressQuery, city);
}
char *state = NULL;
maps_address_get_state(address, &state);
if ((strlen(resultAddressQuery) > 0) && (state != NULL)) {
- strcat(resultAddressQuery, ",");
- strcat(resultAddressQuery, state);
+ STRCAT(resultAddressQuery, ",");
+ STRCAT(resultAddressQuery, state);
} else if (state != NULL) {
- strcat(resultAddressQuery, state);
+ STRCAT(resultAddressQuery, state);
}
#if 0
char *district = NULL;
maps_address_get_district(address, &district);
if ((strlen(resultAddressQuery) > 0) && (district != NULL)) {
- strcat(resultAddressQuery, ", ");
- strcat(resultAddressQuery, district);
+ STRCAT(resultAddressQuery, ", ");
+ STRCAT(resultAddressQuery, district);
}
char *country = NULL;
maps_address_get_country(address, &country);
if ((strlen(resultAddressQuery) > 0) && (country != NULL)) {
- strcat(resultAddressQuery, ", ");
- strcat(resultAddressQuery, country);
+ STRCAT(resultAddressQuery, ", ");
+ STRCAT(resultAddressQuery, country);
}
char *country_code = NULL;
maps_address_get_country_code(address, &country_code);
if ((strlen(resultAddressQuery) > 0) && (country_code != NULL)) {
- strcat(resultAddressQuery, ", ");
- strcat(resultAddressQuery, country_code);
+ STRCAT(resultAddressQuery, ", ");
+ STRCAT(resultAddressQuery, country_code);
} else if (country_code != NULL) {
- strcat(resultAddressQuery, country_code);
+ STRCAT(resultAddressQuery, country_code);
}
char *county = NULL;
maps_address_get_county(address, &county);
if ((strlen(resultAddressQuery) > 0) && (county != NULL)) {
- strcat(resultAddressQuery, ", ");
- strcat(resultAddressQuery, county);
+ STRCAT(resultAddressQuery, ", ");
+ STRCAT(resultAddressQuery, county);
}
#endif
char *postal_code = NULL;
maps_address_get_postal_code(address, &postal_code);
if ((strlen(resultAddressQuery) > 0) && (postal_code != NULL)) {
- strcat(resultAddressQuery, ",");
- strcat(resultAddressQuery, postal_code);
+ STRCAT(resultAddressQuery, ",");
+ STRCAT(resultAddressQuery, postal_code);
} else if (postal_code != NULL) {
- strcat(resultAddressQuery, postal_code);
+ STRCAT(resultAddressQuery, postal_code);
}
char *modified_address = NULL;