Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: third_party/libjingle/overrides/talk/base/win32.cc

Issue 9455070: Remove the dependency to ws2_32.dll from talk_base::ThreadManager and talk_base::Thread. (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004--2005, Google Inc. 3 * Copyright 2004--2005, Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 case AF_INET6: { 59 case AF_INET6: {
60 return inet_ntop_v6(src, dst, size); 60 return inet_ntop_v6(src, dst, size);
61 } 61 }
62 } 62 }
63 return NULL; 63 return NULL;
64 } 64 }
65 65
66 // As above, but for inet_pton. Wraps inet_addr for v4, and implements inet_pton 66 // As above, but for inet_pton. Wraps inet_addr for v4, and implements inet_pton
67 // for v6. Slightly more permissive than the RFC specified inet_pton, as it uses 67 // for v6. Slightly more permissive than the RFC specified inet_pton, as it uses
68 // windows' inet_addr which permits octal and hexadecimal values in v4 68 // windows' inet_addr which permits octal and hexadecimal values in v4
69 // addresses, while inet_pton only allows decimal. 69 // addresses, while inet_pton only allows decimal.
Sergey Ulanov 2012/02/29 05:30:31 nit: update this comment.
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
70 // Note that our inet_ntop will output normal 'dotted' v4 addresses only. 70 // Note that our inet_ntop will output normal 'dotted' v4 addresses only.
71 int win32_inet_pton(int af, const char* src, void* dst) { 71 int win32_inet_pton(int af, const char* src, void* dst) {
72 if (!src || !dst) { 72 if (!src || !dst) {
73 return 0; 73 return 0;
74 } 74 }
75 if (af == AF_INET) { 75 if (af == AF_INET) {
76 return inet_pton_v4(src, dst); 76 return inet_pton_v4(src, dst);
77 } else if (af == AF_INET6) { 77 } else if (af == AF_INET6) {
78 return inet_pton_v6(src, dst); 78 return inet_pton_v6(src, dst);
79 } 79 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 *cursor++ = ':'; 165 *cursor++ = ':';
166 *cursor++ = ':'; 166 *cursor++ = ':';
167 i += (max - 1); 167 i += (max - 1);
168 } 168 }
169 } 169 }
170 } 170 }
171 return dst; 171 return dst;
172 } 172 }
173 173
174 // Helper function for inet_pton for IPv4 addresses. 174 // Helper function for inet_pton for IPv4 addresses.
175 // Uses win32's inet_addr. 175 // |src| points to a character string containing an IPv4 network address in
176 // dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is a decimal number
177 // of up to three digits in the range 0 to 255.
178 // The address is converted and copied to dst,
179 // which must be sizeof(struct in_addr) (4) bytes (32 bits) long.
176 int inet_pton_v4(const char* src, void* dst) { 180 int inet_pton_v4(const char* src, void* dst) {
177 uint32 ip = inet_addr(src); 181 int num_dot = 0;
178 if (ip == 0xFFFFFFFF && strcmp(src, "255.255.255.255") != 0) { 182 const char* src_pos = src;
183 unsigned char result[4];
Sergey Ulanov 2012/02/29 05:30:31 Might be better to define const kIpv4AddressSize =
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
184 memset(result, 0, sizeof(result));
tommi (sloooow) - chröme 2012/02/29 09:54:22 nit: instead of memset, you can just do: unsigned
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
185
186 while (*src_pos != 0) {
Sergey Ulanov 2012/02/29 05:30:31 can replace this with a for loop from 0 to 3, that
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 I tried to do that be it seems that won't save muc
187 if (*src_pos < '0' || *src_pos > '9')
Sergey Ulanov 2012/02/29 05:30:31 nit: add a comment explaining why we need it.
Sergey Ulanov 2012/02/29 05:30:31 use isdigit()
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
188 return 0;
189 char* end_pos;
190 long int value = strtol(src_pos, &end_pos, 10);
191 if (value < 0 || value > 255 ||
192 src_pos == end_pos)
Sergey Ulanov 2012/02/29 05:30:31 nit: no need to wrap this line. move this conditio
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
193 return 0;
194 result[num_dot] = value;
195 if (*end_pos == 0)
196 break;
197 src_pos = end_pos;
198 if (*src_pos == '.') {
199 if (++num_dot > 3)
Sergey Ulanov 2012/02/29 05:30:31 move increment out of the if condition: ++num_dot
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
200 return 0;
201 }
202 ++src_pos;
203 }
204 if (num_dot != 3) {
179 return 0; 205 return 0;
180 } 206 }
181 struct in_addr* dst_as_in_addr = reinterpret_cast<struct in_addr*>(dst); 207 memcpy(dst, result, 4);
Sergey Ulanov 2012/02/29 05:30:31 s/4/sizeof(result)/
Ronghua Wu (Left Chromium) 2012/03/01 00:50:13 Done.
182 dst_as_in_addr->s_addr = ip;
183 return 1; 208 return 1;
184 } 209 }
185 210
186 // Helper function for inet_pton for IPv6 addresses. 211 // Helper function for inet_pton for IPv6 addresses.
187 int inet_pton_v6(const char* src, void* dst) { 212 int inet_pton_v6(const char* src, void* dst) {
188 // sscanf will pick any other invalid chars up, but it parses 0xnnnn as hex. 213 // sscanf will pick any other invalid chars up, but it parses 0xnnnn as hex.
189 // Check for literal x in the input string. 214 // Check for literal x in the input string.
190 const char* readcursor = src; 215 const char* readcursor = src;
191 char c = *readcursor++; 216 char c = *readcursor++;
192 while (c) { 217 while (c) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 DWORD count = *GetSidSubAuthorityCount(til->Label.Sid); 456 DWORD count = *GetSidSubAuthorityCount(til->Label.Sid);
432 *level = *GetSidSubAuthority(til->Label.Sid, count - 1); 457 *level = *GetSidSubAuthority(til->Label.Sid, count - 1);
433 ret = true; 458 ret = true;
434 } 459 }
435 } 460 }
436 CloseHandle(token); 461 CloseHandle(token);
437 } 462 }
438 return ret; 463 return ret;
439 } 464 }
440 } // namespace talk_base 465 } // namespace talk_base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698