0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00

Minor CF enhancements for iOS client.

Added Reachability::reachableVia method.
This commit is contained in:
James Yonan 2012-07-28 12:42:25 +00:00
parent 223ebe8f59
commit 33e7670d90
3 changed files with 42 additions and 17 deletions

View File

@ -70,7 +70,7 @@ namespace openvpn {
std::swap(obj_, other.obj_);
}
void reset(T obj, const Own own=OWN)
void reset(T obj=NULL, const Own own=OWN)
{
if (own == BORROW && obj)
CFRetain(obj);
@ -208,14 +208,19 @@ namespace openvpn {
return dict((const void **)keys.c_data(), (const void **)values.c_data(), std::min(keys.size(), values.size()));
}
inline MutableArray mutable_array()
inline Dict const_dict(MutableDict& mdict)
{
return MutableArray(CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
return Dict(mdict(), CF::BORROW);
}
inline MutableDict mutable_dict()
inline MutableArray mutable_array(const CFIndex capacity=0)
{
return MutableDict(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
return MutableArray(CFArrayCreateMutable(kCFAllocatorDefault, capacity, &kCFTypeArrayCallBacks));
}
inline MutableDict mutable_dict(const CFIndex capacity=0)
{
return MutableDict(CFDictionaryCreateMutable(kCFAllocatorDefault, capacity, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
}
inline Error error(CFStringRef domain, CFIndex code, CFDictionaryRef userInfo)
@ -316,6 +321,16 @@ namespace openvpn {
return s1.defined() && s2.defined() && CFStringCompare(s1(), s2(), compareOptions) == kCFCompareEqualTo;
}
// property lists
inline Data plist(CFTypeRef obj)
{
return Data(CFPropertyListCreateData(kCFAllocatorDefault,
obj,
kCFPropertyListBinaryFormat_v1_0,
0,
NULL));
}
} // namespace CF
} // namespace openvpn

View File

@ -135,52 +135,52 @@ namespace openvpn {
// set a number in a mutable dictionary
inline void dict_set_num_int(MutableDict& dict, CFStringRef key, int value)
inline void dict_set_int(MutableDict& dict, CFStringRef key, int value)
{
Number num = number_from_int(value);
CFDictionarySetValue(dict(), key, num());
}
inline void dict_set_num_int(MutableDict& dict, const char *key, int value)
inline void dict_set_int(MutableDict& dict, const char *key, int value)
{
String keystr = string(key);
Number num = number_from_int(value);
CFDictionarySetValue(dict(), keystr(), num());
}
inline void dict_set_num_int32(MutableDict& dict, CFStringRef key, SInt32 value)
inline void dict_set_int32(MutableDict& dict, CFStringRef key, SInt32 value)
{
Number num = number_from_int32(value);
CFDictionarySetValue(dict(), key, num());
}
inline void dict_set_num_int32(MutableDict& dict, const char *key, SInt32 value)
inline void dict_set_int32(MutableDict& dict, const char *key, SInt32 value)
{
String keystr = string(key);
Number num = number_from_int32(value);
CFDictionarySetValue(dict(), keystr(), num());
}
inline void dict_set_num_long_long(MutableDict& dict, CFStringRef key, long long value)
inline void dict_set_long_long(MutableDict& dict, CFStringRef key, long long value)
{
Number num = number_from_long_long(value);
CFDictionarySetValue(dict(), key, num());
}
inline void dict_set_num_long_long(MutableDict& dict, const char *key, long long value)
inline void dict_set_long_long(MutableDict& dict, const char *key, long long value)
{
String keystr = string(key);
Number num = number_from_long_long(value);
CFDictionarySetValue(dict(), keystr(), num());
}
inline void dict_set_num_index(MutableDict& dict, CFStringRef key, CFIndex value)
inline void dict_set_index(MutableDict& dict, CFStringRef key, CFIndex value)
{
Number num = number_from_index(value);
CFDictionarySetValue(dict(), key, num());
}
inline void dict_set_num_index(MutableDict& dict, const char *key, CFIndex value)
inline void dict_set_index(MutableDict& dict, const char *key, CFIndex value)
{
String keystr = string(key);
Number num = number_from_index(value);
@ -189,19 +189,19 @@ namespace openvpn {
// append number to a mutable array
inline void array_append_num_int(MutableArray& array, int value)
inline void array_append_int(MutableArray& array, int value)
{
Number num = number_from_int(value);
CFArrayAppendValue(array(), num());
}
inline void array_append_num_int32(MutableArray& array, SInt32 value)
inline void array_append_int32(MutableArray& array, SInt32 value)
{
Number num = number_from_int32(value);
CFArrayAppendValue(array(), num());
}
inline void array_append_num_index(MutableArray& array, CFIndex value)
inline void array_append_index(MutableArray& array, CFIndex value)
{
Number num = number_from_index(value);
CFArrayAppendValue(array(), num());

View File

@ -28,7 +28,17 @@ namespace openvpn {
bool defined() const { return bool(didRetrieveFlags); }
bool reachable() const { return bool(flags & kSCNetworkReachabilityFlagsReachable); }
bool connectionRequired() const { return bool(flags & kSCNetworkReachabilityFlagsConnectionRequired); }
bool isWWAN() const { return bool(flags & kSCNetworkReachabilityFlagsIsWWAN); }
bool isWWAN() const { return bool(flags & kSCNetworkReachabilityFlagsIsWWAN); } // cellular
bool reachableVia(const std::string& net_type) const
{
if (net_type == "cellular")
return reachable() && isWWAN();
else if (net_type == "wifi")
return reachable() && !isWWAN();
else
return reachable();
}
std::string to_string() const {
std::ostringstream out;