| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 "dbus/message.h" | 5 #include "dbus/message.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 800 } |
| 801 | 801 |
| 802 bool MessageReader::PopDictEntry(MessageReader* sub_reader) { | 802 bool MessageReader::PopDictEntry(MessageReader* sub_reader) { |
| 803 return PopContainer(DBUS_TYPE_DICT_ENTRY, sub_reader); | 803 return PopContainer(DBUS_TYPE_DICT_ENTRY, sub_reader); |
| 804 } | 804 } |
| 805 | 805 |
| 806 bool MessageReader::PopVariant(MessageReader* sub_reader) { | 806 bool MessageReader::PopVariant(MessageReader* sub_reader) { |
| 807 return PopContainer(DBUS_TYPE_VARIANT, sub_reader); | 807 return PopContainer(DBUS_TYPE_VARIANT, sub_reader); |
| 808 } | 808 } |
| 809 | 809 |
| 810 bool MessageReader::PopArrayOfBytes(uint8** bytes, size_t* length) { | 810 bool MessageReader::PopArrayOfBytes(const uint8** bytes, size_t* length) { |
| 811 MessageReader array_reader(message_); | 811 MessageReader array_reader(message_); |
| 812 if (!PopArray(&array_reader)) | 812 if (!PopArray(&array_reader)) |
| 813 return false; | 813 return false; |
| 814 // An empty array is allowed. | 814 // An empty array is allowed. |
| 815 if (!array_reader.HasMoreData()) { | 815 if (!array_reader.HasMoreData()) { |
| 816 *length = 0; | 816 *length = 0; |
| 817 *bytes = NULL; | 817 *bytes = NULL; |
| 818 return true; | 818 return true; |
| 819 } | 819 } |
| 820 if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) | 820 if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) |
| 821 return false; | 821 return false; |
| 822 int int_length = 0; | 822 int int_length = 0; |
| 823 dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, | 823 dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, |
| 824 bytes, | 824 bytes, |
| 825 &int_length); | 825 &int_length); |
| 826 *length = static_cast<int>(int_length); | 826 *length = static_cast<int>(int_length); |
| 827 return true; | 827 return true; |
| 828 } | 828 } |
| 829 | 829 |
| 830 bool MessageReader::PopArrayOfStrings( | 830 bool MessageReader::PopArrayOfStrings( |
| 831 std::vector<std::string> *strings) { | 831 std::vector<std::string> *strings) { |
| 832 strings->clear(); |
| 832 MessageReader array_reader(message_); | 833 MessageReader array_reader(message_); |
| 833 if (!PopArray(&array_reader)) | 834 if (!PopArray(&array_reader)) |
| 834 return false; | 835 return false; |
| 835 while (array_reader.HasMoreData()) { | 836 while (array_reader.HasMoreData()) { |
| 836 std::string string; | 837 std::string string; |
| 837 if (!array_reader.PopString(&string)) | 838 if (!array_reader.PopString(&string)) |
| 838 return false; | 839 return false; |
| 839 strings->push_back(string); | 840 strings->push_back(string); |
| 840 } | 841 } |
| 841 return true; | 842 return true; |
| 842 } | 843 } |
| 843 | 844 |
| 844 bool MessageReader::PopArrayOfObjectPaths( | 845 bool MessageReader::PopArrayOfObjectPaths( |
| 845 std::vector<ObjectPath> *object_paths) { | 846 std::vector<ObjectPath> *object_paths) { |
| 847 object_paths->clear(); |
| 846 MessageReader array_reader(message_); | 848 MessageReader array_reader(message_); |
| 847 if (!PopArray(&array_reader)) | 849 if (!PopArray(&array_reader)) |
| 848 return false; | 850 return false; |
| 849 while (array_reader.HasMoreData()) { | 851 while (array_reader.HasMoreData()) { |
| 850 ObjectPath object_path; | 852 ObjectPath object_path; |
| 851 if (!array_reader.PopObjectPath(&object_path)) | 853 if (!array_reader.PopObjectPath(&object_path)) |
| 852 return false; | 854 return false; |
| 853 object_paths->push_back(object_path); | 855 object_paths->push_back(object_path); |
| 854 } | 856 } |
| 855 return true; | 857 return true; |
| 856 } | 858 } |
| 857 | 859 |
| 858 bool MessageReader::PopArrayOfBytesAsProto( | 860 bool MessageReader::PopArrayOfBytesAsProto( |
| 859 google::protobuf::MessageLite* protobuf) { | 861 google::protobuf::MessageLite* protobuf) { |
| 860 DCHECK(protobuf != NULL); | 862 DCHECK(protobuf != NULL); |
| 861 char* serialized_buf = NULL; | 863 const char* serialized_buf = NULL; |
| 862 size_t buf_size = 0; | 864 size_t buf_size = 0; |
| 863 if (!PopArrayOfBytes(reinterpret_cast<uint8**>(&serialized_buf), &buf_size)) { | 865 if (!PopArrayOfBytes( |
| 866 reinterpret_cast<const uint8**>(&serialized_buf), &buf_size)) { |
| 864 LOG(ERROR) << "Error reading array of bytes"; | 867 LOG(ERROR) << "Error reading array of bytes"; |
| 865 return false; | 868 return false; |
| 866 } | 869 } |
| 867 if (!protobuf->ParseFromArray(serialized_buf, buf_size)) { | 870 if (!protobuf->ParseFromArray(serialized_buf, buf_size)) { |
| 868 LOG(ERROR) << "Failed to parse protocol buffer from array"; | 871 LOG(ERROR) << "Failed to parse protocol buffer from array"; |
| 869 return false; | 872 return false; |
| 870 } | 873 } |
| 871 return true; | 874 return true; |
| 872 } | 875 } |
| 873 | 876 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); | 982 const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd); |
| 980 if (!success) | 983 if (!success) |
| 981 return false; | 984 return false; |
| 982 | 985 |
| 983 value->PutValue(fd); | 986 value->PutValue(fd); |
| 984 // NB: the caller must check validity before using the value | 987 // NB: the caller must check validity before using the value |
| 985 return true; | 988 return true; |
| 986 } | 989 } |
| 987 | 990 |
| 988 } // namespace dbus | 991 } // namespace dbus |
| OLD | NEW |