| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos_network.h" // NOLINT | 5 #include "chromeos_network.h" // NOLINT |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 | 10 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // in the ScopedHashTable. The hash table will map strings to glib values. | 229 // in the ScopedHashTable. The hash table will map strings to glib values. |
| 230 bool GetProperties(const dbus::Proxy& proxy, glib::ScopedHashTable* result) { | 230 bool GetProperties(const dbus::Proxy& proxy, glib::ScopedHashTable* result) { |
| 231 glib::ScopedError error; | 231 glib::ScopedError error; |
| 232 if (!::dbus_g_proxy_call(proxy.gproxy(), | 232 if (!::dbus_g_proxy_call(proxy.gproxy(), |
| 233 kGetPropertiesFunction, | 233 kGetPropertiesFunction, |
| 234 &Resetter(&error).lvalue(), | 234 &Resetter(&error).lvalue(), |
| 235 G_TYPE_INVALID, | 235 G_TYPE_INVALID, |
| 236 ::dbus_g_type_get_map("GHashTable", G_TYPE_STRING, | 236 ::dbus_g_type_get_map("GHashTable", G_TYPE_STRING, |
| 237 G_TYPE_VALUE), | 237 G_TYPE_VALUE), |
| 238 &Resetter(result).lvalue(), G_TYPE_INVALID)) { | 238 &Resetter(result).lvalue(), G_TYPE_INVALID)) { |
| 239 LOG(WARNING) << "GetProperties failed: " | 239 LOG(WARNING) << "GetProperties on path '" << proxy.path() << "' failed: " |
| 240 << (error->message ? error->message : "Unknown Error."); | 240 << (error->message ? error->message : "Unknown Error."); |
| 241 return false; | 241 return false; |
| 242 } | 242 } |
| 243 return true; | 243 return true; |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Populates an instance of a ServiceInfo with the properties | 246 // Populates an instance of a ServiceInfo with the properties |
| 247 // from a Connman service. | 247 // from a Connman service. |
| 248 void ParseServiceProperties(const glib::ScopedHashTable& properties, | 248 void ParseServiceProperties(const glib::ScopedHashTable& properties, |
| 249 ServiceInfo* info) { | 249 ServiceInfo* info) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 kConnmanIPConfigInterface); | 501 kConnmanIPConfigInterface); |
| 502 glib::ScopedHashTable properties; | 502 glib::ScopedHashTable properties; |
| 503 if (!GetProperties(config_proxy, &properties)) | 503 if (!GetProperties(config_proxy, &properties)) |
| 504 return false; | 504 return false; |
| 505 ParseIPConfigProperties(properties, ipconfig); | 505 ParseIPConfigProperties(properties, ipconfig); |
| 506 return true; | 506 return true; |
| 507 } | 507 } |
| 508 | 508 |
| 509 extern "C" | 509 extern "C" |
| 510 IPConfigStatus* ChromeOSListIPConfigs(const char* device_path) { | 510 IPConfigStatus* ChromeOSListIPConfigs(const char* device_path) { |
| 511 if (!device_path) |
| 512 return NULL; |
| 511 | 513 |
| 512 dbus::BusConnection bus = dbus::GetSystemBusConnection(); | 514 dbus::BusConnection bus = dbus::GetSystemBusConnection(); |
| 513 dbus::Proxy device_proxy(bus, | 515 dbus::Proxy device_proxy(bus, |
| 514 kConnmanServiceName, | 516 kConnmanServiceName, |
| 515 device_path, | 517 device_path, |
| 516 kConnmanDeviceInterface); | 518 kConnmanDeviceInterface); |
| 517 | 519 |
| 518 glib::ScopedHashTable properties; | 520 glib::ScopedHashTable properties; |
| 519 if (!GetProperties(device_proxy, &properties)) { | 521 if (!GetProperties(device_proxy, &properties)) { |
| 520 return NULL; | 522 return NULL; |
| 521 } | 523 } |
| 522 | 524 |
| 523 GHashTable* table = properties.get(); | 525 GHashTable* table = properties.get(); |
| 524 gpointer ptr = g_hash_table_lookup(table, kIPConfigsProperty); | 526 gpointer ptr = g_hash_table_lookup(table, kIPConfigsProperty); |
| 525 if (ptr == NULL) | 527 if (ptr == NULL) |
| 526 return NULL; | 528 return NULL; |
| 527 | 529 |
| 528 GPtrArray* ips_value = | 530 GPtrArray* ips_value = |
| 529 static_cast<GPtrArray*>(g_value_get_boxed(static_cast<GValue*>(ptr))); | 531 static_cast<GPtrArray*>(g_value_get_boxed(static_cast<GValue*>(ptr))); |
| 530 | 532 |
| 531 IPConfigStatus* result = new IPConfigStatus(); | 533 IPConfigStatus* result = new IPConfigStatus(); |
| 532 result->size = ips_value->len; | 534 std::vector<IPConfig> buffer; |
| 535 const char* path = NULL; |
| 536 for (size_t i = 0; i < ips_value->len; i++) { |
| 537 path = static_cast<const char*>(g_ptr_array_index(ips_value, i)); |
| 538 if (!path) { |
| 539 LOG(WARNING) << "Found NULL ip for device " << device_path; |
| 540 continue; |
| 541 } |
| 542 IPConfig ipconfig = {}; |
| 543 if (!ParseIPConfig(path, &ipconfig)) |
| 544 continue; |
| 545 buffer.push_back(ipconfig); |
| 546 } |
| 547 result->size = buffer.size(); |
| 533 if (result->size == 0) { | 548 if (result->size == 0) { |
| 534 result->ips = NULL; | 549 result->ips = NULL; |
| 535 } else { | 550 } else { |
| 536 result->ips = new IPConfig[result->size]; | 551 result->ips = new IPConfig[result->size]; |
| 537 for (size_t i = 0; i < ips_value->len; i++) { | |
| 538 const char* path = | |
| 539 static_cast<const char*>(g_ptr_array_index(ips_value, i)); | |
| 540 ParseIPConfig(path, &result->ips[i]); | |
| 541 } | |
| 542 } | 552 } |
| 553 std::copy(buffer.begin(), buffer.end(), result->ips); |
| 543 return result; | 554 return result; |
| 544 } | 555 } |
| 545 | 556 |
| 546 extern "C" | 557 extern "C" |
| 547 bool ChromeOSAddIPConfig(const char* device_path, IPConfigType type) { | 558 bool ChromeOSAddIPConfig(const char* device_path, IPConfigType type) { |
| 548 dbus::BusConnection bus = dbus::GetSystemBusConnection(); | 559 dbus::BusConnection bus = dbus::GetSystemBusConnection(); |
| 549 dbus::Proxy device_proxy(bus, | 560 dbus::Proxy device_proxy(bus, |
| 550 kConnmanServiceName, | 561 kConnmanServiceName, |
| 551 device_path, | 562 device_path, |
| 552 kConnmanDeviceInterface); | 563 kConnmanDeviceInterface); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 G_TYPE_INVALID, | 654 G_TYPE_INVALID, |
| 644 G_TYPE_INVALID)) { | 655 G_TYPE_INVALID)) { |
| 645 LOG(WARNING) <<"Set IPConfig Property failed: " | 656 LOG(WARNING) <<"Set IPConfig Property failed: " |
| 646 << (error->message ? error->message : "Unknown Error."); | 657 << (error->message ? error->message : "Unknown Error."); |
| 647 return false; | 658 return false; |
| 648 } | 659 } |
| 649 return true; | 660 return true; |
| 650 } | 661 } |
| 651 | 662 |
| 652 void DeleteIPConfigProperties(IPConfig config) { | 663 void DeleteIPConfigProperties(IPConfig config) { |
| 653 delete config.path; | 664 if (config.path) |
| 654 delete config.address; | 665 delete config.path; |
| 655 delete config.broadcast; | 666 if (config.address) |
| 656 delete config.netmask; | 667 delete config.address; |
| 657 delete config.gateway; | 668 if (config.broadcast) |
| 658 delete config.domainname; | 669 delete config.broadcast; |
| 659 delete config.name_servers; | 670 if (config.netmask) |
| 671 delete config.netmask; |
| 672 if (config.gateway) |
| 673 delete config.gateway; |
| 674 if (config.domainname) |
| 675 delete config.domainname; |
| 676 if (config.name_servers) |
| 677 delete config.name_servers; |
| 660 } | 678 } |
| 661 | 679 |
| 662 extern "C" | 680 extern "C" |
| 663 void ChromeOSFreeIPConfig(IPConfig* config) { | 681 void ChromeOSFreeIPConfig(IPConfig* config) { |
| 664 DeleteIPConfigProperties(*config); | 682 DeleteIPConfigProperties(*config); |
| 665 delete config; | 683 delete config; |
| 666 } | 684 } |
| 667 | 685 |
| 668 extern "C" | 686 extern "C" |
| 669 void ChromeOSFreeIPConfigStatus(IPConfigStatus* status) { | 687 void ChromeOSFreeIPConfigStatus(IPConfigStatus* status) { |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 G_TYPE_INVALID)) { | 981 G_TYPE_INVALID)) { |
| 964 LOG(WARNING) << "SetOfflineMode failed: " | 982 LOG(WARNING) << "SetOfflineMode failed: " |
| 965 << (error->message ? error->message : "Unknown Error."); | 983 << (error->message ? error->message : "Unknown Error."); |
| 966 return false; | 984 return false; |
| 967 } | 985 } |
| 968 | 986 |
| 969 return true; | 987 return true; |
| 970 } | 988 } |
| 971 | 989 |
| 972 } // namespace chromeos | 990 } // namespace chromeos |
| OLD | NEW |