diff options
Diffstat (limited to 'src/cloud/car_info.c')
-rw-r--r-- | src/cloud/car_info.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/cloud/car_info.c b/src/cloud/car_info.c index f54d31a..7c977d7 100644 --- a/src/cloud/car_info.c +++ b/src/cloud/car_info.c @@ -29,6 +29,12 @@ #define MAX_LENGTH_MAC 18 #define MAX_LENGTH_SSID 33 +#define SAFE_STR_CPY(src, obj, size)\ +do {\ + if(obj)\ + src = strndup(obj, size);\ +} while(0) + static int validate_ip_address(const char *ip_address); static int validate_mac_address(const char *mac_address); @@ -49,6 +55,20 @@ car_info_t *car_info_create() return car_info; } +car_info_t *car_info_copy(const car_info_t *car_info) +{ + retv_if(!car_info, NULL); + + struct car_info *car_info_cpy = g_new0(struct car_info, 1); + SAFE_STR_CPY(car_info_cpy->id, car_info->id, MAX_LENGTH); + SAFE_STR_CPY(car_info_cpy->name, car_info->name, MAX_LENGTH); + SAFE_STR_CPY(car_info_cpy->ip, car_info->ip, MAX_LENGTH_IP); + SAFE_STR_CPY(car_info_cpy->ap_mac, car_info->ap_mac, MAX_LENGTH_MAC); + SAFE_STR_CPY(car_info_cpy->ap_ssid, car_info->ap_ssid, MAX_LENGTH_SSID); + + return car_info_cpy; +} + void car_info_destroy(car_info_t *car_info) { ret_if(!car_info); |