diff --git a/webrtc/base/checks.cc b/webrtc/base/checks.cc index dd7183362..67f5003de 100644 --- a/webrtc/base/checks.cc +++ b/webrtc/base/checks.cc @@ -15,6 +15,8 @@ #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" +namespace rtc { + void Fatal(const char* file, int line, const char* format, ...) { char msg[256]; @@ -28,3 +30,5 @@ void Fatal(const char* file, int line, const char* format, ...) { << "\n#\n"; abort(); } + +} // namespace rtc diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h index 93f7580ed..5a2841ae9 100644 --- a/webrtc/base/checks.h +++ b/webrtc/base/checks.h @@ -16,12 +16,15 @@ #include +namespace rtc { + // Prints an error message to stderr and aborts execution. void Fatal(const char* file, int line, const char* format, ...); +} // namespace rtc // The UNREACHABLE macro is very useful during development. #define UNREACHABLE() \ - Fatal(__FILE__, __LINE__, "unreachable code") + rtc::Fatal(__FILE__, __LINE__, "unreachable code") #endif // WEBRTC_BASE_CHECKS_H_ diff --git a/webrtc/base/flags.cc b/webrtc/base/flags.cc index bc7a83030..fe7a334a9 100644 --- a/webrtc/base/flags.cc +++ b/webrtc/base/flags.cc @@ -20,7 +20,7 @@ #include "webrtc/base/flags.h" - +namespace rtc { // ----------------------------------------------------------------------------- // Implementation of Flag @@ -296,3 +296,4 @@ WindowsCommandLineArguments::~WindowsCommandLineArguments() { } #endif // WEBRTC_WIN +} // namespace rtc diff --git a/webrtc/base/flags.h b/webrtc/base/flags.h index ac91d8ad6..5cff1cc36 100644 --- a/webrtc/base/flags.h +++ b/webrtc/base/flags.h @@ -28,6 +28,8 @@ #include "webrtc/base/checks.h" #include "webrtc/base/common.h" +namespace rtc { + // Internal use only. union FlagValue { // Note: Because in C++ non-bool values are silently converted into @@ -155,9 +157,9 @@ class Flag { /* define and initialize the flag */ \ c_type FLAG_##name = (default); \ /* register the flag */ \ - static Flag Flag_##name(__FILE__, #name, (comment), \ - Flag::type, &FLAG_##name, \ - FlagValue::New_##type(default)) + static rtc::Flag Flag_##name(__FILE__, #name, (comment), \ + rtc::Flag::type, &FLAG_##name, \ + rtc::FlagValue::New_##type(default)) // Internal use only. @@ -263,5 +265,6 @@ class WindowsCommandLineArguments { }; #endif // WEBRTC_WIN +} // namespace rtc #endif // SHARED_COMMANDLINEFLAGS_FLAGS_H__ diff --git a/webrtc/base/ifaddrs-android.cc b/webrtc/base/ifaddrs-android.cc index 5d022a79a..c8363d567 100644 --- a/webrtc/base/ifaddrs-android.cc +++ b/webrtc/base/ifaddrs-android.cc @@ -23,14 +23,18 @@ #include #include +namespace { + struct netlinkrequest { nlmsghdr header; ifaddrmsg msg; }; -namespace { const int kMaxReadSize = 4096; -}; + +} // namespace + +namespace rtc { int set_ifname(struct ifaddrs* ifaddr, int interface) { char buf[IFNAMSIZ] = {0}; @@ -215,3 +219,5 @@ void freeifaddrs(struct ifaddrs* addrs) { } } #endif // defined(WEBRTC_ANDROID) + +} // namespace rtc diff --git a/webrtc/base/ifaddrs-android.h b/webrtc/base/ifaddrs-android.h index c8671e08f..10890af65 100644 --- a/webrtc/base/ifaddrs-android.h +++ b/webrtc/base/ifaddrs-android.h @@ -13,6 +13,8 @@ #include #include + + // Implementation of getifaddrs for Android. // Fills out a list of ifaddr structs (see below) which contain information // about every network interface available on the host. @@ -27,7 +29,11 @@ struct ifaddrs { // We don't need them (yet?). }; +namespace rtc { + int getifaddrs(struct ifaddrs** result); void freeifaddrs(struct ifaddrs* addrs); +} // namespace rtc + #endif // WEBRTC_BASE_IFADDRS_ANDROID_H_ diff --git a/webrtc/base/md5.cc b/webrtc/base/md5.cc index a4f28d730..54128907a 100644 --- a/webrtc/base/md5.cc +++ b/webrtc/base/md5.cc @@ -25,6 +25,8 @@ #include "webrtc/base/byteorder.h" // for ARCH_CPU_LITTLE_ENDIAN. +namespace rtc { + #ifdef ARCH_CPU_LITTLE_ENDIAN #define ByteReverse(buf, len) // Nothing. #else // ARCH_CPU_BIG_ENDIAN @@ -216,3 +218,5 @@ void MD5Transform(uint32 buf[4], const uint32 in[16]) { buf[2] += c; buf[3] += d; } + +} // namespace rtc diff --git a/webrtc/base/md5.h b/webrtc/base/md5.h index fc563b764..418e214c7 100644 --- a/webrtc/base/md5.h +++ b/webrtc/base/md5.h @@ -17,12 +17,15 @@ // Changes(fbarchard): Ported to C++ and Google style guide. // Made context first parameter in MD5Final for consistency with Sha1. +// Changes(hellner): added rtc namespace #ifndef WEBRTC_BASE_MD5_H_ #define WEBRTC_BASE_MD5_H_ #include "webrtc/base/basictypes.h" +namespace rtc { + // Canonical name for a MD5 context structure, used in many crypto libs. typedef struct MD5Context MD5_CTX; @@ -37,4 +40,6 @@ void MD5Update(MD5Context* context, const uint8* data, size_t len); void MD5Final(MD5Context* context, uint8 digest[16]); void MD5Transform(uint32 buf[4], const uint32 in[16]); +} // namespace rtc + #endif // WEBRTC_BASE_MD5_H_ diff --git a/webrtc/base/openssladapter.cc b/webrtc/base/openssladapter.cc index d0311100e..c9f6b1aaa 100644 --- a/webrtc/base/openssladapter.cc +++ b/webrtc/base/openssladapter.cc @@ -84,9 +84,9 @@ static BIO_METHOD methods_socket = { NULL, }; -BIO_METHOD* BIO_s_socket2() { return(&methods_socket); } +static BIO_METHOD* BIO_s_socket2() { return(&methods_socket); } -BIO* BIO_new_socket(rtc::AsyncSocket* socket) { +static BIO* BIO_new_socket(rtc::AsyncSocket* socket) { BIO* ret = BIO_new(BIO_s_socket2()); if (ret == NULL) { return NULL; diff --git a/webrtc/base/sha1.cc b/webrtc/base/sha1.cc index 8f8bd3d4a..afc5569fd 100644 --- a/webrtc/base/sha1.cc +++ b/webrtc/base/sha1.cc @@ -102,6 +102,8 @@ #include #include +namespace rtc { + void SHA1Transform(uint32 state[5], const uint8 buffer[64]); #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) @@ -280,3 +282,5 @@ void SHA1Final(SHA1_CTX* context, uint8 digest[SHA1_DIGEST_SIZE]) { SHA1Transform(context->state, context->buffer); #endif } + +} // namespace rtc diff --git a/webrtc/base/sha1.h b/webrtc/base/sha1.h index b19c6592e..4862a0049 100644 --- a/webrtc/base/sha1.h +++ b/webrtc/base/sha1.h @@ -5,13 +5,15 @@ * */ -// Ported to C++, Google style and uses basictypes.h +// Ported to C++, Google style, under namespace rtc and uses basictypes.h #ifndef WEBRTC_BASE_SHA1_H_ #define WEBRTC_BASE_SHA1_H_ #include "webrtc/base/basictypes.h" +namespace rtc { + struct SHA1_CTX { uint32 state[5]; // TODO: Change bit count to uint64. @@ -26,3 +28,5 @@ void SHA1Update(SHA1_CTX* context, const uint8* data, size_t len); void SHA1Final(SHA1_CTX* context, uint8 digest[SHA1_DIGEST_SIZE]); #endif // WEBRTC_BASE_SHA1_H_ + +} // namespace rtc diff --git a/webrtc/base/sslroots.h b/webrtc/base/sslroots.h index 0f983cd60..31d601c16 100644 --- a/webrtc/base/sslroots.h +++ b/webrtc/base/sslroots.h @@ -8,6 +8,7 @@ /* subject:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root */ /* issuer :/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root */ +namespace rtc { const unsigned char AddTrust_External_Root_certificate[1082]={ 0x30,0x82,0x04,0x36,0x30,0x82,0x03,0x1E,0xA0,0x03,0x02,0x01,0x02,0x02,0x01,0x01, @@ -4928,3 +4929,4 @@ const size_t kSSLCertCertificateSizeList[] = { 1076, }; +} // namspace rtc diff --git a/webrtc/base/unittest_main.cc b/webrtc/base/unittest_main.cc index c7adb7931..7c4630e3c 100644 --- a/webrtc/base/unittest_main.cc +++ b/webrtc/base/unittest_main.cc @@ -77,9 +77,9 @@ rtc::Pathname GetTalkDirectory() { int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); - FlagList::SetFlagsFromCommandLine(&argc, argv, false); + rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false); if (FLAG_help) { - FlagList::Print(NULL, false); + rtc::FlagList::Print(NULL, false); return 0; } diff --git a/webrtc/base/urlencode.cc b/webrtc/base/urlencode.cc index 5619e05cb..b152829ae 100644 --- a/webrtc/base/urlencode.cc +++ b/webrtc/base/urlencode.cc @@ -36,8 +36,8 @@ static int HexPairValue(const char * code) { } } -int InternalUrlDecode(const char *source, char *dest, - bool encode_space_as_plus) { +static int InternalUrlDecode(const char *source, char *dest, + bool encode_space_as_plus) { char * start = dest; while (*source) { @@ -74,6 +74,16 @@ int InternalUrlDecode(const char *source, char *dest, return static_cast(dest - start); } +static bool IsValidUrlChar(char ch, bool unsafe_only) { + if (unsafe_only) { + return !(ch <= ' ' || strchr("\\\"^&`<>[]{}", ch)); + } else { + return isalnum(ch) || strchr("-_.!~*'()", ch); + } +} + +namespace rtc { + int UrlDecode(const char *source, char *dest) { return InternalUrlDecode(source, dest, true); } @@ -82,14 +92,6 @@ int UrlDecodeWithoutEncodingSpaceAsPlus(const char *source, char *dest) { return InternalUrlDecode(source, dest, false); } -bool IsValidUrlChar(char ch, bool unsafe_only) { - if (unsafe_only) { - return !(ch <= ' ' || strchr("\\\"^&`<>[]{}", ch)); - } else { - return isalnum(ch) || strchr("-_.!~*'()", ch); - } -} - int InternalUrlEncode(const char *source, char *dest, unsigned int max, bool encode_space_as_plus, bool unsafe_only) { static const char *digits = "0123456789ABCDEF"; @@ -177,3 +179,5 @@ std::string UrlEncodeStringForOnlyUnsafeChars(const std::string & decoded) { return InternalUrlEncodeString(decoded, false, true); } + +} // namespace rtc diff --git a/webrtc/base/urlencode.h b/webrtc/base/urlencode.h index 6195f8380..fc10f3880 100644 --- a/webrtc/base/urlencode.h +++ b/webrtc/base/urlencode.h @@ -13,6 +13,8 @@ #include +namespace rtc { + // Decode all encoded characters. Also decode + as space. int UrlDecode(const char *source, char *dest); @@ -41,3 +43,4 @@ std::string UrlEncodeStringForOnlyUnsafeChars(const std::string & decoded); #endif +} // namespace rtc diff --git a/webrtc/base/urlencode_unittest.cc b/webrtc/base/urlencode_unittest.cc index 2214fbf2a..52169132e 100644 --- a/webrtc/base/urlencode_unittest.cc +++ b/webrtc/base/urlencode_unittest.cc @@ -13,6 +13,8 @@ #include "webrtc/base/thread.h" #include "webrtc/base/urlencode.h" +using rtc::UrlEncode; + TEST(Urlencode, SourceTooLong) { char source[] = "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"; @@ -61,21 +63,21 @@ TEST(Urlencode, Encoding1) { TEST(Urlencode, Encoding2) { char source[] = "A^ "; char dest[8]; - ASSERT_EQ(7, UrlEncodeWithoutEncodingSpaceAsPlus(source, dest, - ARRAY_SIZE(dest))); + ASSERT_EQ(7, rtc::UrlEncodeWithoutEncodingSpaceAsPlus(source, dest, + ARRAY_SIZE(dest))); ASSERT_STREQ("A%5E%20", dest); } TEST(Urldecode, Decoding1) { char source[] = "A%5E+"; char dest[8]; - ASSERT_EQ(3, UrlDecode(source, dest)); + ASSERT_EQ(3, rtc::UrlDecode(source, dest)); ASSERT_STREQ("A^ ", dest); } TEST(Urldecode, Decoding2) { char source[] = "A%5E+"; char dest[8]; - ASSERT_EQ(3, UrlDecodeWithoutEncodingSpaceAsPlus(source, dest)); + ASSERT_EQ(3, rtc::UrlDecodeWithoutEncodingSpaceAsPlus(source, dest)); ASSERT_STREQ("A^+", dest); }