| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // list elements according to which is more convenient and correct for any | 30 // list elements according to which is more convenient and correct for any |
| 31 // specific task. | 31 // specific task. |
| 32 | 32 |
| 33 launch_data_t data_launch = nullptr; | 33 launch_data_t data_launch = nullptr; |
| 34 CFTypeID type_id_cf = CFGetTypeID(property_cf); | 34 CFTypeID type_id_cf = CFGetTypeID(property_cf); |
| 35 | 35 |
| 36 if (type_id_cf == CFDictionaryGetTypeID()) { | 36 if (type_id_cf == CFDictionaryGetTypeID()) { |
| 37 NSDictionary* dictionary_ns = base::mac::CFToNSCast( | 37 NSDictionary* dictionary_ns = base::mac::CFToNSCast( |
| 38 base::mac::CFCastStrict<CFDictionaryRef>(property_cf)); | 38 base::mac::CFCastStrict<CFDictionaryRef>(property_cf)); |
| 39 base::mac::ScopedLaunchData dictionary_launch( | 39 base::mac::ScopedLaunchData dictionary_launch( |
| 40 launch_data_alloc(LAUNCH_DATA_DICTIONARY)); | 40 LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); |
| 41 | 41 |
| 42 for (NSString* key in dictionary_ns) { | 42 for (NSString* key in dictionary_ns) { |
| 43 if (![key isKindOfClass:[NSString class]]) { | 43 if (![key isKindOfClass:[NSString class]]) { |
| 44 return nullptr; | 44 return nullptr; |
| 45 } | 45 } |
| 46 | 46 |
| 47 CFPropertyListRef value_cf = | 47 CFPropertyListRef value_cf = |
| 48 implicit_cast<CFPropertyListRef>([dictionary_ns objectForKey:key]); | 48 implicit_cast<CFPropertyListRef>([dictionary_ns objectForKey:key]); |
| 49 launch_data_t value_launch = CFPropertyToLaunchData(value_cf); | 49 launch_data_t value_launch = CFPropertyToLaunchData(value_cf); |
| 50 if (!value_launch) { | 50 if (!value_launch) { |
| 51 return nullptr; | 51 return nullptr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 launch_data_dict_insert( | 54 LaunchDataDictInsert(dictionary_launch, value_launch, [key UTF8String]); |
| 55 dictionary_launch, value_launch, [key UTF8String]); | |
| 56 } | 55 } |
| 57 | 56 |
| 58 data_launch = dictionary_launch.release(); | 57 data_launch = dictionary_launch.release(); |
| 59 | 58 |
| 60 } else if (type_id_cf == CFArrayGetTypeID()) { | 59 } else if (type_id_cf == CFArrayGetTypeID()) { |
| 61 NSArray* array_ns = base::mac::CFToNSCast( | 60 NSArray* array_ns = base::mac::CFToNSCast( |
| 62 base::mac::CFCastStrict<CFArrayRef>(property_cf)); | 61 base::mac::CFCastStrict<CFArrayRef>(property_cf)); |
| 63 base::mac::ScopedLaunchData array_launch( | 62 base::mac::ScopedLaunchData array_launch( |
| 64 launch_data_alloc(LAUNCH_DATA_ARRAY)); | 63 LaunchDataAlloc(LAUNCH_DATA_ARRAY)); |
| 65 size_t index = 0; | 64 size_t index = 0; |
| 66 | 65 |
| 67 for (id element_ns in array_ns) { | 66 for (id element_ns in array_ns) { |
| 68 CFPropertyListRef element_cf = | 67 CFPropertyListRef element_cf = |
| 69 implicit_cast<CFPropertyListRef>(element_ns); | 68 implicit_cast<CFPropertyListRef>(element_ns); |
| 70 launch_data_t element_launch = CFPropertyToLaunchData(element_cf); | 69 launch_data_t element_launch = CFPropertyToLaunchData(element_cf); |
| 71 if (!element_launch) { | 70 if (!element_launch) { |
| 72 return nullptr; | 71 return nullptr; |
| 73 } | 72 } |
| 74 | 73 |
| 75 launch_data_array_set_index(array_launch, element_launch, index++); | 74 LaunchDataArraySetIndex(array_launch, element_launch, index++); |
| 76 } | 75 } |
| 77 | 76 |
| 78 data_launch = array_launch.release(); | 77 data_launch = array_launch.release(); |
| 79 | 78 |
| 80 } else if (type_id_cf == CFNumberGetTypeID()) { | 79 } else if (type_id_cf == CFNumberGetTypeID()) { |
| 81 CFNumberRef number_cf = base::mac::CFCastStrict<CFNumberRef>(property_cf); | 80 CFNumberRef number_cf = base::mac::CFCastStrict<CFNumberRef>(property_cf); |
| 82 NSNumber* number_ns = base::mac::CFToNSCast(number_cf); | 81 NSNumber* number_ns = base::mac::CFToNSCast(number_cf); |
| 83 switch (CFNumberGetType(number_cf)) { | 82 switch (CFNumberGetType(number_cf)) { |
| 84 case kCFNumberSInt8Type: | 83 case kCFNumberSInt8Type: |
| 85 case kCFNumberSInt16Type: | 84 case kCFNumberSInt16Type: |
| 86 case kCFNumberSInt32Type: | 85 case kCFNumberSInt32Type: |
| 87 case kCFNumberSInt64Type: | 86 case kCFNumberSInt64Type: |
| 88 case kCFNumberCharType: | 87 case kCFNumberCharType: |
| 89 case kCFNumberShortType: | 88 case kCFNumberShortType: |
| 90 case kCFNumberIntType: | 89 case kCFNumberIntType: |
| 91 case kCFNumberLongType: | 90 case kCFNumberLongType: |
| 92 case kCFNumberLongLongType: | 91 case kCFNumberLongLongType: |
| 93 case kCFNumberCFIndexType: | 92 case kCFNumberCFIndexType: |
| 94 case kCFNumberNSIntegerType: { | 93 case kCFNumberNSIntegerType: { |
| 95 data_launch = launch_data_new_integer([number_ns longLongValue]); | 94 data_launch = LaunchDataNewInteger([number_ns longLongValue]); |
| 96 break; | 95 break; |
| 97 } | 96 } |
| 98 | 97 |
| 99 case kCFNumberFloat32Type: | 98 case kCFNumberFloat32Type: |
| 100 case kCFNumberFloat64Type: | 99 case kCFNumberFloat64Type: |
| 101 case kCFNumberFloatType: | 100 case kCFNumberFloatType: |
| 102 case kCFNumberDoubleType: { | 101 case kCFNumberDoubleType: { |
| 103 data_launch = launch_data_new_real([number_ns doubleValue]); | 102 data_launch = LaunchDataNewReal([number_ns doubleValue]); |
| 104 break; | 103 break; |
| 105 } | 104 } |
| 106 | 105 |
| 107 default: { return nullptr; } | 106 default: { return nullptr; } |
| 108 } | 107 } |
| 109 | 108 |
| 110 } else if (type_id_cf == CFBooleanGetTypeID()) { | 109 } else if (type_id_cf == CFBooleanGetTypeID()) { |
| 111 CFBooleanRef boolean_cf = | 110 CFBooleanRef boolean_cf = |
| 112 base::mac::CFCastStrict<CFBooleanRef>(property_cf); | 111 base::mac::CFCastStrict<CFBooleanRef>(property_cf); |
| 113 data_launch = launch_data_new_bool(CFBooleanGetValue(boolean_cf)); | 112 data_launch = LaunchDataNewBool(CFBooleanGetValue(boolean_cf)); |
| 114 | 113 |
| 115 } else if (type_id_cf == CFStringGetTypeID()) { | 114 } else if (type_id_cf == CFStringGetTypeID()) { |
| 116 NSString* string_ns = base::mac::CFToNSCast( | 115 NSString* string_ns = base::mac::CFToNSCast( |
| 117 base::mac::CFCastStrict<CFStringRef>(property_cf)); | 116 base::mac::CFCastStrict<CFStringRef>(property_cf)); |
| 118 | 117 |
| 119 // -fileSystemRepresentation might be more correct than -UTF8String, | 118 // -fileSystemRepresentation might be more correct than -UTF8String, |
| 120 // because these strings can hold paths. The analogous function in | 119 // because these strings can hold paths. The analogous function in |
| 121 // launchctl, CF2launch_data() (10.9.4 | 120 // launchctl, CF2launch_data() (10.9.4 |
| 122 // launchd-842.92.1/support/launchctl.c), uses UTF-8 instead of filesystem | 121 // launchd-842.92.1/support/launchctl.c), uses UTF-8 instead of filesystem |
| 123 // encoding, so do the same here. Note that there’s another occurrence of | 122 // encoding, so do the same here. Note that there’s another occurrence of |
| 124 // -UTF8String above, used for dictionary keys. | 123 // -UTF8String above, used for dictionary keys. |
| 125 data_launch = launch_data_new_string([string_ns UTF8String]); | 124 data_launch = LaunchDataNewString([string_ns UTF8String]); |
| 126 | 125 |
| 127 } else if (type_id_cf == CFDataGetTypeID()) { | 126 } else if (type_id_cf == CFDataGetTypeID()) { |
| 128 NSData* data_ns = base::mac::CFToNSCast( | 127 NSData* data_ns = base::mac::CFToNSCast( |
| 129 base::mac::CFCastStrict<CFDataRef>(property_cf)); | 128 base::mac::CFCastStrict<CFDataRef>(property_cf)); |
| 130 data_launch = launch_data_new_opaque([data_ns bytes], [data_ns length]); | 129 data_launch = LaunchDataNewOpaque([data_ns bytes], [data_ns length]); |
| 131 } else { | 130 } else { |
| 132 base::ScopedCFTypeRef<CFStringRef> type_name_cf( | 131 base::ScopedCFTypeRef<CFStringRef> type_name_cf( |
| 133 CFCopyTypeIDDescription(type_id_cf)); | 132 CFCopyTypeIDDescription(type_id_cf)); |
| 134 DLOG(ERROR) << "unable to convert CFTypeID " << type_id_cf << " (" | 133 DLOG(ERROR) << "unable to convert CFTypeID " << type_id_cf << " (" |
| 135 << base::SysCFStringRefToUTF8(type_name_cf) << ")"; | 134 << base::SysCFStringRefToUTF8(type_name_cf) << ")"; |
| 136 } | 135 } |
| 137 | 136 |
| 138 return data_launch; | 137 return data_launch; |
| 139 } | 138 } |
| 140 } | 139 } |
| 141 | 140 |
| 142 } // namespace crashpad | 141 } // namespace crashpad |
| OLD | NEW |