Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/_scproxy.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | afb2f144b98c |
| children |
| rev | line source |
|---|---|
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
1 /* |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
2 * Helper method for urllib to fetch the proxy configuration settings |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
3 * using the SystemConfiguration framework. |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
4 */ |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
5 #include <Python.h> |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
6 #include <SystemConfiguration/SystemConfiguration.h> |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
7 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
8 static int32_t |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
9 cfnum_to_int32(CFNumberRef num) |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
10 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
11 int32_t result; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
12 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
13 CFNumberGetValue(num, kCFNumberSInt32Type, &result); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
14 return result; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
15 } |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
16 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
17 static PyObject* |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
18 cfstring_to_pystring(CFStringRef ref) |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
19 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
20 const char* s; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
21 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
22 s = CFStringGetCStringPtr(ref, kCFStringEncodingUTF8); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
23 if (s) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
24 return PyString_FromString(s); |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
25 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
26 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
27 CFIndex len = CFStringGetLength(ref); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
28 Boolean ok; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
29 PyObject* result; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
30 result = PyString_FromStringAndSize(NULL, len*4); |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
31 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
32 ok = CFStringGetCString(ref, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
33 PyString_AS_STRING(result), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
34 PyString_GET_SIZE(result), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
35 kCFStringEncodingUTF8); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
36 if (!ok) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
37 Py_DECREF(result); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
38 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
39 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
40 _PyString_Resize(&result, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
41 strlen(PyString_AS_STRING(result))); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
42 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
43 return result; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
44 } |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
45 } |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
46 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
47 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
48 static PyObject* |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
49 get_proxy_settings(PyObject* mod __attribute__((__unused__))) |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
50 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
51 CFDictionaryRef proxyDict = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
52 CFNumberRef aNum = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
53 CFArrayRef anArray = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
54 PyObject* result = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
55 PyObject* v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
56 int r; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
57 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
58 proxyDict = SCDynamicStoreCopyProxies(NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
59 if (!proxyDict) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
60 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
61 return Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
62 } |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
63 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
64 result = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
65 if (result == NULL) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
66 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
67 if (&kSCPropNetProxiesExcludeSimpleHostnames != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
68 aNum = CFDictionaryGetValue(proxyDict, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
69 kSCPropNetProxiesExcludeSimpleHostnames); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
70 if (aNum == NULL) { |
|
62436
6e5d21e223d2
The code in _scproxy (a mac specific helper module to
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
61463
diff
changeset
|
71 v = PyBool_FromLong(0); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
72 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
73 v = PyBool_FromLong(cfnum_to_int32(aNum)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
74 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
75 } else { |
|
64979
afb2f144b98c
Merged revisions 85062 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
62436
diff
changeset
|
76 v = PyBool_FromLong(0); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
77 } |
|
60750
725be8f9418b
This patch fixes the handling of a weak-linked
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56141
diff
changeset
|
78 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
79 if (v == NULL) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
80 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
81 r = PyDict_SetItemString(result, "exclude_simple", v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
82 Py_DECREF(v); v = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
83 if (r == -1) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
84 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
85 anArray = CFDictionaryGetValue(proxyDict, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
86 kSCPropNetProxiesExceptionsList); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
87 if (anArray != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
88 CFIndex len = CFArrayGetCount(anArray); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
89 CFIndex i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
90 v = PyTuple_New(len); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
91 if (v == NULL) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
92 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
93 r = PyDict_SetItemString(result, "exceptions", v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
94 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
95 if (r == -1) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
96 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
97 for (i = 0; i < len; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
98 CFStringRef aString = NULL; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
99 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
100 aString = CFArrayGetValueAtIndex(anArray, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
101 if (aString == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
102 PyTuple_SetItem(v, i, Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
103 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
104 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
105 PyObject* t = cfstring_to_pystring(aString); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
106 if (!t) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
107 PyTuple_SetItem(v, i, Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
108 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
109 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
110 PyTuple_SetItem(v, i, t); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
111 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
112 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
113 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
114 } |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
115 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
116 CFRelease(proxyDict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
117 return result; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
118 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
119 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
120 if (proxyDict) CFRelease(proxyDict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
121 Py_XDECREF(result); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
122 return NULL; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
123 } |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
124 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
125 static int |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
126 set_proxy(PyObject* proxies, char* proto, CFDictionaryRef proxyDict, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
127 CFStringRef enabledKey, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
128 CFStringRef hostKey, CFStringRef portKey) |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
129 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
130 CFNumberRef aNum; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
131 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
132 aNum = CFDictionaryGetValue(proxyDict, enabledKey); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
133 if (aNum && cfnum_to_int32(aNum)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
134 CFStringRef hostString; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
135 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
136 hostString = CFDictionaryGetValue(proxyDict, hostKey); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
137 aNum = CFDictionaryGetValue(proxyDict, portKey); |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
138 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
139 if (hostString) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
140 int r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
141 PyObject* h = cfstring_to_pystring(hostString); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
142 PyObject* v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
143 if (h) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
144 if (aNum) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
145 int32_t port = cfnum_to_int32(aNum); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
146 v = PyString_FromFormat("http://%s:%ld", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
147 PyString_AS_STRING(h), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
148 (long)port); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
149 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
150 v = PyString_FromFormat("http://%s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
151 PyString_AS_STRING(h)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
152 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
153 Py_DECREF(h); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
154 if (!v) return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
155 r = PyDict_SetItemString(proxies, proto, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
156 v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
157 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
158 return r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
159 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
160 } |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
161 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
162 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
163 return 0; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
164 } |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
165 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
166 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
167 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
168 static PyObject* |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
169 get_proxies(PyObject* mod __attribute__((__unused__))) |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
170 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
171 PyObject* result = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
172 int r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
173 CFDictionaryRef proxyDict = NULL; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
174 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
175 proxyDict = SCDynamicStoreCopyProxies(NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
176 if (proxyDict == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
177 return PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
178 } |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
179 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
180 result = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
181 if (result == NULL) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
182 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
183 r = set_proxy(result, "http", proxyDict, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
184 kSCPropNetProxiesHTTPEnable, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
185 kSCPropNetProxiesHTTPProxy, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
186 kSCPropNetProxiesHTTPPort); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
187 if (r == -1) goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
188 r = set_proxy(result, "https", proxyDict, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
189 kSCPropNetProxiesHTTPSEnable, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
190 kSCPropNetProxiesHTTPSProxy, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
191 kSCPropNetProxiesHTTPSPort); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
192 if (r == -1) goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
193 r = set_proxy(result, "ftp", proxyDict, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
194 kSCPropNetProxiesFTPEnable, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
195 kSCPropNetProxiesFTPProxy, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
196 kSCPropNetProxiesFTPPort); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
197 if (r == -1) goto error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
198 r = set_proxy(result, "gopher", proxyDict, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
199 kSCPropNetProxiesGopherEnable, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
200 kSCPropNetProxiesGopherProxy, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
201 kSCPropNetProxiesGopherPort); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
202 if (r == -1) goto error; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
203 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
204 CFRelease(proxyDict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
205 return result; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
206 error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
207 if (proxyDict) CFRelease(proxyDict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
208 Py_XDECREF(result); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
209 return NULL; |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
210 } |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
211 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
212 static PyMethodDef mod_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
213 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
214 "_get_proxy_settings", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
215 (PyCFunction)get_proxy_settings, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
216 METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
217 NULL, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
218 }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
219 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
220 "_get_proxies", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
221 (PyCFunction)get_proxies, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
222 METH_NOARGS, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
223 NULL, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
224 }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
225 { 0, 0, 0, 0 } |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
226 }; |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
227 |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
228 void init_scproxy(void) |
|
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
229 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60750
diff
changeset
|
230 (void)Py_InitModule4("_scproxy", mod_methods, NULL, NULL, PYTHON_API_VERSION); |
|
56141
1db6ee9d7be7
r74963 didn't include the merger of _scproxy.c
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff
changeset
|
231 } |
