├── .gitignore ├── .gitmodules ├── .travis.yml ├── About.md ├── CONTRIBUTING.md ├── LICENSE ├── OSXChangeLog.md ├── Podfile ├── Podfile.lock ├── README.md ├── ShadowWeb ├── ShadowsocksRunner.h ├── ShadowsocksRunner.m ├── en.lproj │ └── Localizable.strings ├── encrypt.c ├── encrypt.h ├── libev │ ├── Changes │ ├── LICENSE │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ ├── Symbols.ev │ ├── Symbols.event │ ├── autogen.sh │ ├── config.h │ ├── config.h.in │ ├── configure.ac │ ├── ev++.h │ ├── ev.c │ ├── ev.h │ ├── ev_kqueue.c │ ├── ev_poll.c │ ├── ev_port.c │ ├── ev_select.c │ ├── ev_vars.h │ ├── ev_win32.c │ ├── ev_wrap.h │ ├── event.c │ └── event.h ├── local.h ├── local.m ├── socks5.h ├── table.h ├── table.m └── zh-Hans.lproj │ ├── InfoPlist.strings │ └── Localizable.strings ├── ShadowsocksX ├── Application.xib ├── Configuration.h ├── Configuration.m ├── Images.xcassets │ ├── AppIcon-2.appiconset │ │ ├── 114.png │ │ ├── 120.png │ │ ├── 144.png │ │ ├── 57.png │ │ ├── 72.png │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── icon_128x128.png │ │ ├── icon_128x128@2x.png │ │ ├── icon_16x16.png │ │ ├── icon_16x16@2x.png │ │ ├── icon_256x256.png │ │ ├── icon_256x256@2x.png │ │ ├── icon_32x32.png │ │ ├── icon_32x32@2x.png │ │ ├── icon_512x512.png │ │ └── icon_512x512@2x.png │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Profile.h ├── Profile.m ├── ProfileManager.h ├── ProfileManager.m ├── QRCodeWindow.xib ├── SWBAppDelegate.h ├── SWBAppDelegate.m ├── SWBApplication.h ├── SWBApplication.m ├── SWBConfigWindowController.h ├── SWBConfigWindowController.m ├── SWBQRCodeWindowController.h ├── SWBQRCodeWindowController.m ├── ShadowsocksX-Info.plist ├── ShadowsocksX-Prefix.pch ├── abp.js ├── en.lproj │ ├── ConfigWindow.xib │ ├── Credits.rtf │ └── InfoPlist.strings ├── install_helper.sh ├── jquery.min.js ├── main.m ├── menu_icon.png ├── menu_icon@2x.png ├── menu_icon_disabled.png ├── menu_icon_disabled@2x.png ├── models │ └── profile.json ├── qrcode.htm ├── qrcode.min.js └── zh-Hans.lproj │ └── ConfigWindow.xib ├── ShadowsocksXTests ├── ShadowsocksXTests-Info.plist ├── ShadowsocksXTests.m └── en.lproj │ └── InfoPlist.strings ├── about.txt ├── appstore.png ├── build.sh ├── ios_128.png ├── osx_128.png ├── packaging └── osx │ ├── arrow.png │ ├── build_dmg.sh │ └── settings.py ├── proxy.pac.gz ├── shadowsocks copy-Info.plist ├── shadowsocks.xcodeproj └── project.pbxproj ├── shadowsocks.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── shadowsocks.xcscmblueprint └── shadowsocks_sysconf ├── main.m ├── shadowsocks_sysconf-Prefix.pch └── shadowsocks_sysconf.1 /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .localized 3 | # Xcode 4 | build/* 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | *.xcworkspace 14 | !default.xcworkspace 15 | *.xcuserdatad 16 | xcuserdata 17 | *.moved-aside 18 | *.xcuserstate 19 | *.swo 20 | *.swp 21 | *.hmap 22 | .idea/ 23 | *.xcbkptlist 24 | 25 | 26 | #CocoaPods 27 | Pods -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "GZIP"] 2 | path = GZIP 3 | url = https://github.com/nicklockwood/GZIP.git 4 | [submodule "AFNetworking"] 5 | path = AFNetworking 6 | url = git@github.com:AFNetworking/AFNetworking.git 7 | [submodule "GCDWebServer"] 8 | path = GCDWebServer 9 | url = git@github.com:swisspol/GCDWebServer.git 10 | [submodule "OpenSSL-for-iPhone"] 11 | path = OpenSSL-for-iPhone 12 | url = git@github.com:clowwindy/OpenSSL-for-iPhone.git 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | xcode_sdk: iphonesimulator 3 | script: ./build.sh 4 | -------------------------------------------------------------------------------- /About.md: -------------------------------------------------------------------------------- 1 | [Shadowsocks for iOS](https://github.com/shadowsocks/shadowsocks-iOS) 2 | =================== 3 | 4 | Copyright (C) 2014 clowwindy 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | This project has used some third party libraries. Thanks to the open source 20 | community for their great job. 21 | 22 | See [LICENSE](https://github.com/shadowsocks/shadowsocks-iOS/blob/master/LICENSE) 23 | for detailed license information. 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | How to Contribute 2 | ================= 3 | 4 | Pull Requests 5 | ------------- 6 | 7 | 1. Pull requests are welcome. If you would like to add a large feature 8 | or make a significant change, make sure to open an issue to discuss with 9 | people first. 10 | 2. Make sure to pass the unit tests. Write unit tests for new modules if 11 | needed. 12 | 13 | Issues 14 | ------ 15 | 16 | 1. Only bugs and feature requests are accepted here. 17 | 2. We'll only work on important features. If the feature you're asking only 18 | benefits a few people, you'd better implement the feature yourself and send us 19 | a pull request, or ask some of your friends to do so. 20 | 3. We don't answer questions of any other types here. Since very few people 21 | are watching the issue tracker here, you'll probably get no help from here. 22 | Read [Troubleshooting] and get help from forums or [mailing lists]. 23 | 24 | 25 | [Troubleshooting]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting 26 | [mailing lists]: https://groups.google.com/forum/#!forum/shadowsocks 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Shadowsocks for iOS and OSX 2 | 3 | Copyright (C) 2014 clowwindy 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | 18 | ****** 19 | 20 | GFWList 21 | 22 | GNU Lesser GPL 23 | https://code.google.com/p/autoproxy-gfwlist/ 24 | 25 | ****** 26 | 27 | iProxy 28 | https://github.com/tcurdt/iProxy 29 | 30 | Apache License 31 | Version 2.0, January 2004 32 | http://www.apache.org/licenses/ 33 | 34 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 35 | 36 | 1. Definitions. 37 | 38 | "License" shall mean the terms and conditions for use, reproduction, 39 | and distribution as defined by Sections 1 through 9 of this document. 40 | 41 | "Licensor" shall mean the copyright owner or entity authorized by 42 | the copyright owner that is granting the License. 43 | 44 | "Legal Entity" shall mean the union of the acting entity and all 45 | other entities that control, are controlled by, or are under common 46 | control with that entity. For the purposes of this definition, 47 | "control" means (i) the power, direct or indirect, to cause the 48 | direction or management of such entity, whether by contract or 49 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 50 | outstanding shares, or (iii) beneficial ownership of such entity. 51 | 52 | "You" (or "Your") shall mean an individual or Legal Entity 53 | exercising permissions granted by this License. 54 | 55 | "Source" form shall mean the preferred form for making modifications, 56 | including but not limited to software source code, documentation 57 | source, and configuration files. 58 | 59 | "Object" form shall mean any form resulting from mechanical 60 | transformation or translation of a Source form, including but 61 | not limited to compiled object code, generated documentation, 62 | and conversions to other media types. 63 | 64 | "Work" shall mean the work of authorship, whether in Source or 65 | Object form, made available under the License, as indicated by a 66 | copyright notice that is included in or attached to the work 67 | (an example is provided in the Appendix below). 68 | 69 | "Derivative Works" shall mean any work, whether in Source or Object 70 | form, that is based on (or derived from) the Work and for which the 71 | editorial revisions, annotations, elaborations, or other modifications 72 | represent, as a whole, an original work of authorship. For the purposes 73 | of this License, Derivative Works shall not include works that remain 74 | separable from, or merely link (or bind by name) to the interfaces of, 75 | the Work and Derivative Works thereof. 76 | 77 | "Contribution" shall mean any work of authorship, including 78 | the original version of the Work and any modifications or additions 79 | to that Work or Derivative Works thereof, that is intentionally 80 | submitted to Licensor for inclusion in the Work by the copyright owner 81 | or by an individual or Legal Entity authorized to submit on behalf of 82 | the copyright owner. For the purposes of this definition, "submitted" 83 | means any form of electronic, verbal, or written communication sent 84 | to the Licensor or its representatives, including but not limited to 85 | communication on electronic mailing lists, source code control systems, 86 | and issue tracking systems that are managed by, or on behalf of, the 87 | Licensor for the purpose of discussing and improving the Work, but 88 | excluding communication that is conspicuously marked or otherwise 89 | designated in writing by the copyright owner as "Not a Contribution." 90 | 91 | "Contributor" shall mean Licensor and any individual or Legal Entity 92 | on behalf of whom a Contribution has been received by Licensor and 93 | subsequently incorporated within the Work. 94 | 95 | 2. Grant of Copyright License. Subject to the terms and conditions of 96 | this License, each Contributor hereby grants to You a perpetual, 97 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 98 | copyright license to reproduce, prepare Derivative Works of, 99 | publicly display, publicly perform, sublicense, and distribute the 100 | Work and such Derivative Works in Source or Object form. 101 | 102 | 3. Grant of Patent License. Subject to the terms and conditions of 103 | this License, each Contributor hereby grants to You a perpetual, 104 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 105 | (except as stated in this section) patent license to make, have made, 106 | use, offer to sell, sell, import, and otherwise transfer the Work, 107 | where such license applies only to those patent claims licensable 108 | by such Contributor that are necessarily infringed by their 109 | Contribution(s) alone or by combination of their Contribution(s) 110 | with the Work to which such Contribution(s) was submitted. If You 111 | institute patent litigation against any entity (including a 112 | cross-claim or counterclaim in a lawsuit) alleging that the Work 113 | or a Contribution incorporated within the Work constitutes direct 114 | or contributory patent infringement, then any patent licenses 115 | granted to You under this License for that Work shall terminate 116 | as of the date such litigation is filed. 117 | 118 | 4. Redistribution. You may reproduce and distribute copies of the 119 | Work or Derivative Works thereof in any medium, with or without 120 | modifications, and in Source or Object form, provided that You 121 | meet the following conditions: 122 | 123 | (a) You must give any other recipients of the Work or 124 | Derivative Works a copy of this License; and 125 | 126 | (b) You must cause any modified files to carry prominent notices 127 | stating that You changed the files; and 128 | 129 | (c) You must retain, in the Source form of any Derivative Works 130 | that You distribute, all copyright, patent, trademark, and 131 | attribution notices from the Source form of the Work, 132 | excluding those notices that do not pertain to any part of 133 | the Derivative Works; and 134 | 135 | (d) If the Work includes a "NOTICE" text file as part of its 136 | distribution, then any Derivative Works that You distribute must 137 | include a readable copy of the attribution notices contained 138 | within such NOTICE file, excluding those notices that do not 139 | pertain to any part of the Derivative Works, in at least one 140 | of the following places: within a NOTICE text file distributed 141 | as part of the Derivative Works; within the Source form or 142 | documentation, if provided along with the Derivative Works; or, 143 | within a display generated by the Derivative Works, if and 144 | wherever such third-party notices normally appear. The contents 145 | of the NOTICE file are for informational purposes only and 146 | do not modify the License. You may add Your own attribution 147 | notices within Derivative Works that You distribute, alongside 148 | or as an addendum to the NOTICE text from the Work, provided 149 | that such additional attribution notices cannot be construed 150 | as modifying the License. 151 | 152 | You may add Your own copyright statement to Your modifications and 153 | may provide additional or different license terms and conditions 154 | for use, reproduction, or distribution of Your modifications, or 155 | for any such Derivative Works as a whole, provided Your use, 156 | reproduction, and distribution of the Work otherwise complies with 157 | the conditions stated in this License. 158 | 159 | 5. Submission of Contributions. Unless You explicitly state otherwise, 160 | any Contribution intentionally submitted for inclusion in the Work 161 | by You to the Licensor shall be under the terms and conditions of 162 | this License, without any additional terms or conditions. 163 | Notwithstanding the above, nothing herein shall supersede or modify 164 | the terms of any separate license agreement you may have executed 165 | with Licensor regarding such Contributions. 166 | 167 | 6. Trademarks. This License does not grant permission to use the trade 168 | names, trademarks, service marks, or product names of the Licensor, 169 | except as required for reasonable and customary use in describing the 170 | origin of the Work and reproducing the content of the NOTICE file. 171 | 172 | 7. Disclaimer of Warranty. Unless required by applicable law or 173 | agreed to in writing, Licensor provides the Work (and each 174 | Contributor provides its Contributions) on an "AS IS" BASIS, 175 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 176 | implied, including, without limitation, any warranties or conditions 177 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 178 | PARTICULAR PURPOSE. You are solely responsible for determining the 179 | appropriateness of using or redistributing the Work and assume any 180 | risks associated with Your exercise of permissions under this License. 181 | 182 | 8. Limitation of Liability. In no event and under no legal theory, 183 | whether in tort (including negligence), contract, or otherwise, 184 | unless required by applicable law (such as deliberate and grossly 185 | negligent acts) or agreed to in writing, shall any Contributor be 186 | liable to You for damages, including any direct, indirect, special, 187 | incidental, or consequential damages of any character arising as a 188 | result of this License or out of the use or inability to use the 189 | Work (including but not limited to damages for loss of goodwill, 190 | work stoppage, computer failure or malfunction, or any and all 191 | other commercial damages or losses), even if such Contributor 192 | has been advised of the possibility of such damages. 193 | 194 | 9. Accepting Warranty or Additional Liability. While redistributing 195 | the Work or Derivative Works thereof, You may choose to offer, 196 | and charge a fee for, acceptance of support, warranty, indemnity, 197 | or other liability obligations and/or rights consistent with this 198 | License. However, in accepting such obligations, You may act only 199 | on Your own behalf and on Your sole responsibility, not on behalf 200 | of any other Contributor, and only if You agree to indemnify, 201 | defend, and hold each Contributor harmless for any liability 202 | incurred by, or claims asserted against, such Contributor by reason 203 | of your accepting any such warranty or additional liability. 204 | 205 | END OF TERMS AND CONDITIONS 206 | 207 | APPENDIX: How to apply the Apache License to your work. 208 | 209 | To apply the Apache License to your work, attach the following 210 | boilerplate notice, with the fields enclosed by brackets "[]" 211 | replaced with your own identifying information. (Don't include 212 | the brackets!) The text should be enclosed in the appropriate 213 | comment syntax for the file format. We also recommend that a 214 | file or class name and description of purpose be included on the 215 | same "printed page" as the copyright notice for easier 216 | identification within third-party archives. 217 | 218 | Copyright [yyyy] [name of copyright owner] 219 | 220 | Licensed under the Apache License, Version 2.0 (the "License"); 221 | you may not use this file except in compliance with the License. 222 | You may obtain a copy of the License at 223 | 224 | http://www.apache.org/licenses/LICENSE-2.0 225 | 226 | Unless required by applicable law or agreed to in writing, software 227 | distributed under the License is distributed on an "AS IS" BASIS, 228 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 229 | See the License for the specific language governing permissions and 230 | limitations under the License. 231 | 232 | ****** 233 | 234 | GCDWebServer 235 | https://github.com/swisspol/GCDWebServer 236 | 237 | Copyright (c) 2012-2013, Pierre-Olivier Latour 238 | All rights reserved. 239 | 240 | Redistribution and use in source and binary forms, with or without 241 | modification, are permitted provided that the following conditions are met: 242 | * Redistributions of source code must retain the above copyright 243 | notice, this list of conditions and the following disclaimer. 244 | * Redistributions in binary form must reproduce the above copyright 245 | notice, this list of conditions and the following disclaimer in the 246 | documentation and/or other materials provided with the distribution. 247 | * Neither the name of the nor the 248 | names of its contributors may be used to endorse or promote products 249 | derived from this software without specific prior written permission. 250 | 251 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 252 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 253 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 254 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 255 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 256 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 257 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 258 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 260 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261 | 262 | ****** 263 | 264 | AppProxyCap by freewizard 265 | https://github.com/freewizard/AppProxyCap 266 | Released in MIT License 267 | 268 | Modified by clowwindy, with some new features 269 | https://github.com/clowwindy/AppProxyCap 270 | 271 | ****** 272 | 273 | base64 274 | 275 | Created by Matt Gallagher on 2009/06/03. 276 | Copyright 2009 Matt Gallagher. All rights reserved. 277 | 278 | This software is provided 'as-is', without any express or implied 279 | warranty. In no event will the authors be held liable for any damages 280 | arising from the use of this software. Permission is granted to anyone to 281 | use this software for any purpose, including commercial applications, and to 282 | alter it and redistribute it freely, subject to the following restrictions: 283 | 284 | 1. The origin of this software must not be misrepresented; you must not 285 | claim that you wrote the original software. If you use this software 286 | in a product, an acknowledgment in the product documentation would be 287 | appreciated but is not required. 288 | 2. Altered source versions must be plainly marked as such, and must not be 289 | misrepresented as being the original software. 290 | 3. This notice may not be removed or altered from any source 291 | distribution. 292 | 293 | ****** 294 | 295 | zxing-objc 296 | 297 | ZXingObjC is available under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html). -------------------------------------------------------------------------------- /OSXChangeLog.md: -------------------------------------------------------------------------------- 1 | 1.0.5 2 | ------ 3 | - Update PAC file 4 | - Add code sign 5 | 6 | 1.0.4 7 | ------ 8 | - Fix system proxy settings cleared when exiting with pac turned off 9 | 10 | 1.0.3 11 | ------ 12 | - Fix 100% CPU problem when using table encryption. 13 | - Fix "Please fill in the blank" message prompted when public server is selected. 14 | 15 | 1.0.2 16 | ------ 17 | - Authorize only once. 18 | 19 | 1.0.1 20 | ------ 21 | - Fix image uploading. 22 | 23 | 1.0 24 | ------ 25 | - Initial version. 26 | 27 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | platform :ios, '9.0' 3 | # Uncomment this line if you're using Swift 4 | # use_frameworks! 5 | 6 | #target 'shadowsocks' do 7 | # pod "libsodium" 8 | #end 9 | 10 | #target 'libshadowsocks' do 11 | # pod "libsodium" 12 | #end 13 | 14 | target 'ShadowsocksX' do 15 | platform :osx, '10.9' 16 | pod "libsodium" 17 | pod 'ZXingObjC', '~> 3.1.0' 18 | end 19 | 20 | 21 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - libsodium (1.0.3) 3 | - ZXingObjC (3.1.0): 4 | - ZXingObjC/All (= 3.1.0) 5 | - ZXingObjC/All (3.1.0) 6 | 7 | DEPENDENCIES: 8 | - libsodium 9 | - ZXingObjC (~> 3.1.0) 10 | 11 | SPEC CHECKSUMS: 12 | libsodium: be547e31dc75725629acc5717dc0a40fc05ef243 13 | ZXingObjC: bf15b3814f7a105b6d99f47da2333c93a063650a 14 | 15 | PODFILE CHECKSUM: 8bb8520ee3c45cc913c12a706643e44707ed659f 16 | 17 | COCOAPODS: 1.0.0 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Shadowsocks GUI for OSX 2 | =========================== 3 | [![OSX Icon](https://raw.githubusercontent.com/RobertYan/ShadowsocksX/develop/osx_128.png)](https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help) 4 | [OSX Version](https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help) 5 | 6 | How to Build 7 | ----- 8 | 9 | - Install Pods; 10 | - Update git modules; 11 | - Open Xcode and build. 12 | 13 | License 14 | ------- 15 | The project is released under the terms of [GPLv3](https://raw.github.com/shadowsocks/shadowsocks-iOS/master/LICENSE). 16 | 17 | Bugs and Issues 18 | ---------------- 19 | 20 | Please visit [issue tracker](https://github.com/RobertYan/ShadowsocksX/issues?state=open) 21 | 22 | Mailing list: http://groups.google.com/group/shadowsocks 23 | 24 | Also see [troubleshooting](https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting) 25 | 26 | -------------------------------------------------------------------------------- /ShadowWeb/ShadowsocksRunner.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 14-2-27. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | 9 | #define kShadowsocksIPKey @"proxy ip" 10 | #define kShadowsocksPortKey @"proxy port" 11 | #define kShadowsocksPasswordKey @"proxy password" 12 | #define kShadowsocksEncryptionKey @"proxy encryption" 13 | #define kShadowsocksProxyModeKey @"proxy mode" 14 | #define kShadowsocksUsePublicServer @"public server" 15 | 16 | 17 | @interface ShadowsocksRunner : NSObject 18 | 19 | + (BOOL)settingsAreNotComplete; 20 | + (BOOL)runProxy; 21 | + (void)reloadConfig; 22 | + (BOOL)openSSURL:(NSURL *)url; 23 | + (NSURL *)generateSSURL; 24 | + (NSString *)configForKey:(NSString *)key; 25 | + (void)saveConfigForKey:(NSString *)key value:(NSString *)value; 26 | + (void)setUsingPublicServer:(BOOL)use; 27 | + (BOOL)isUsingPublicServer; 28 | 29 | 30 | @end -------------------------------------------------------------------------------- /ShadowWeb/ShadowsocksRunner.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 14-2-27. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import "ShadowsocksRunner.h" 7 | #import "local.h" 8 | 9 | 10 | @implementation ShadowsocksRunner { 11 | 12 | } 13 | 14 | + (BOOL)settingsAreNotComplete { 15 | if ((![ShadowsocksRunner isUsingPublicServer]) && ([[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksIPKey] == nil || 16 | [[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPortKey] == nil || 17 | [[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPasswordKey] == nil)) { 18 | return YES; 19 | } else { 20 | return NO; 21 | } 22 | } 23 | 24 | + (BOOL)runProxy { 25 | if (![ShadowsocksRunner settingsAreNotComplete]) { 26 | local_main(); 27 | return YES; 28 | } else { 29 | #ifdef DEBUG 30 | NSLog(@"warning: settings are not complete"); 31 | #endif 32 | return NO; 33 | } 34 | } 35 | 36 | + (void)reloadConfig { 37 | if (![ShadowsocksRunner settingsAreNotComplete]) { 38 | if ([ShadowsocksRunner isUsingPublicServer]) { 39 | set_config("106.186.124.182", "8911", "Shadowsocks", "aes-128-cfb"); 40 | memcpy(shadowsocks_key, "\x45\xd1\xd9\x9e\xbd\xf5\x8c\x85\x34\x55\xdd\x65\x46\xcd\x06\xd3", 16); 41 | } else { 42 | NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kShadowsocksEncryptionKey]; 43 | if (!v) { 44 | v = @"aes-256-cfb"; 45 | } 46 | set_config([[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksIPKey] cStringUsingEncoding:NSUTF8StringEncoding], [[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPortKey] cStringUsingEncoding:NSUTF8StringEncoding], [[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPasswordKey] cStringUsingEncoding:NSUTF8StringEncoding], [v cStringUsingEncoding:NSUTF8StringEncoding]); 47 | } 48 | } 49 | } 50 | 51 | + (BOOL)openSSURL:(NSURL *)url { 52 | if (!url.host) { 53 | return NO; 54 | } 55 | NSString *urlString = [url absoluteString]; 56 | int i = 0; 57 | NSString *errorReason = nil; 58 | while(i < 2) { 59 | if (i == 1) { 60 | NSData *data = [[NSData alloc] initWithBase64EncodedString:url.host options:0]; 61 | NSString *decodedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 62 | urlString = decodedString; 63 | } 64 | i++; 65 | urlString = [urlString stringByReplacingOccurrencesOfString:@"ss://" withString:@"" options:NSAnchoredSearch range:NSMakeRange(0, urlString.length)]; 66 | NSRange firstColonRange = [urlString rangeOfString:@":"]; 67 | NSRange lastColonRange = [urlString rangeOfString:@":" options:NSBackwardsSearch]; 68 | NSRange lastAtRange = [urlString rangeOfString:@"@" options:NSBackwardsSearch]; 69 | if (firstColonRange.length == 0) { 70 | errorReason = @"colon not found"; 71 | continue; 72 | } 73 | if (firstColonRange.location == lastColonRange.location) { 74 | errorReason = @"only one colon"; 75 | continue; 76 | } 77 | if (lastAtRange.length == 0) { 78 | errorReason = @"at not found"; 79 | continue; 80 | } 81 | if (!((firstColonRange.location < lastAtRange.location) && (lastAtRange.location < lastColonRange.location))) { 82 | errorReason = @"wrong position"; 83 | continue; 84 | } 85 | NSString *method = [urlString substringWithRange:NSMakeRange(0, firstColonRange.location)]; 86 | NSString *password = [urlString substringWithRange:NSMakeRange(firstColonRange.location + 1, lastAtRange.location - firstColonRange.location - 1)]; 87 | NSString *IP = [urlString substringWithRange:NSMakeRange(lastAtRange.location + 1, lastColonRange.location - lastAtRange.location - 1)]; 88 | NSString *port = [urlString substringWithRange:NSMakeRange(lastColonRange.location + 1, urlString.length - lastColonRange.location - 1)]; 89 | [ShadowsocksRunner saveConfigForKey:kShadowsocksIPKey value:IP]; 90 | [ShadowsocksRunner saveConfigForKey:kShadowsocksPortKey value:port]; 91 | [ShadowsocksRunner saveConfigForKey:kShadowsocksPasswordKey value:password]; 92 | [ShadowsocksRunner saveConfigForKey:kShadowsocksEncryptionKey value:method]; 93 | [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kShadowsocksUsePublicServer]; 94 | [ShadowsocksRunner reloadConfig]; 95 | return YES; 96 | } 97 | 98 | NSLog(@"%@", errorReason); 99 | return NO; 100 | } 101 | 102 | 103 | +(NSURL *)generateSSURL { 104 | if ([ShadowsocksRunner isUsingPublicServer]) { 105 | return nil; 106 | } 107 | NSString *parts = [NSString stringWithFormat:@"%@:%@@%@:%@", 108 | [ShadowsocksRunner configForKey:kShadowsocksEncryptionKey], 109 | [ShadowsocksRunner configForKey:kShadowsocksPasswordKey], 110 | [ShadowsocksRunner configForKey:kShadowsocksIPKey], 111 | [ShadowsocksRunner configForKey:kShadowsocksPortKey]]; 112 | 113 | NSString *base64String = [[parts dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0]; 114 | NSString *urlString = [NSString stringWithFormat:@"ss://%@", base64String]; 115 | return [NSURL URLWithString:urlString]; 116 | } 117 | 118 | + (void)saveConfigForKey:(NSString *)key value:(NSString *)value { 119 | [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; 120 | } 121 | 122 | + (NSString *)configForKey:(NSString *)key { 123 | return [[NSUserDefaults standardUserDefaults] objectForKey:key]; 124 | } 125 | 126 | + (void)setUsingPublicServer:(BOOL)use { 127 | [[NSUserDefaults standardUserDefaults] setBool:use forKey:kShadowsocksUsePublicServer]; 128 | 129 | } 130 | 131 | + (BOOL)isUsingPublicServer { 132 | NSNumber *usePublicServer = [[NSUserDefaults standardUserDefaults] objectForKey:kShadowsocksUsePublicServer]; 133 | if (usePublicServer != nil) { 134 | return [usePublicServer boolValue]; 135 | } else { 136 | return YES; 137 | } 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /ShadowWeb/en.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | /* 2 | Localizable.strings 3 | ShadowWeb 4 | 5 | Created by clowwindy on 6/17/13. 6 | Copyright (c) 2013 clowwindy. All rights reserved. 7 | */ 8 | -------------------------------------------------------------------------------- /ShadowWeb/encrypt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "local.h" 7 | #include "table.h" 8 | #include "encrypt.h" 9 | 10 | #define CIPHER_TABLE 0 11 | #define CIPHER_OPENSSL 1 12 | #define CIPHER_SODIUM 2 13 | static uint8_t cipher; 14 | 15 | #define SODIUM_BLOCK_SIZE 64 16 | 17 | static unsigned char sodium_buf[BUF_SIZE + SODIUM_BLOCK_SIZE + 16]; 18 | 19 | size_t encryption_iv_len[] = { 20 | 0, 21 | 16, 22 | 8, 23 | 8, 24 | 16, 25 | 16, 26 | 16, 27 | 8, 28 | 8, 29 | 8, 30 | 8, 31 | 0, 32 | 16 33 | }; 34 | 35 | const char *shadowsocks_encryption_names[] = { 36 | "table", 37 | "rc4-md5", 38 | "salsa20", 39 | "chacha20", 40 | "aes-256-cfb", 41 | "aes-192-cfb", 42 | "aes-128-cfb", 43 | "bf-cfb", 44 | "cast5-cfb", 45 | "des-cfb", 46 | "rc2-cfb", 47 | "rc4", 48 | "seed-cfb" 49 | }; 50 | 51 | #define ENCRYPTION_TABLE 0 52 | #define ENCRYPTION_RC4_MD5 1 53 | #define ENCRYPTION_SALSA20 2 54 | #define ENCRYPTION_CHACHA20 3 55 | 56 | static int _method; 57 | static int _key_len; 58 | static const EVP_CIPHER *_cipher; 59 | static unsigned char _key[EVP_MAX_KEY_LENGTH]; 60 | unsigned char *shadowsocks_key; 61 | 62 | void init_cipher(struct encryption_ctx *ctx, const unsigned char *iv, size_t iv_len, int is_cipher); 63 | 64 | int encryption_method_from_string(const char *name) { 65 | // TODO use an O(1) way 66 | for (int i = 0; i < kShadowsocksMethods; i++) { 67 | if (strcasecmp(name, shadowsocks_encryption_names[i]) == 0) { 68 | return i; 69 | } 70 | } 71 | return 0; 72 | } 73 | 74 | void cipher_update(struct encryption_ctx *ctx, unsigned char *out, size_t *outlen, unsigned char *in, size_t inlen) { 75 | if (ctx->cipher == CIPHER_OPENSSL) { 76 | EVP_CipherUpdate(ctx->ctx, out, (int *) outlen, in, inlen); 77 | } else if (ctx->cipher == CIPHER_SODIUM) { 78 | size_t padding = ctx->bytes_remaining; 79 | memcpy(sodium_buf + padding, in, inlen); 80 | if (_method == ENCRYPTION_SALSA20) { 81 | crypto_stream_salsa20_xor_ic(sodium_buf, sodium_buf, padding + inlen, ctx->iv, ctx->ic, _key); 82 | } else if (_method == ENCRYPTION_CHACHA20) { 83 | crypto_stream_chacha20_xor_ic(sodium_buf, sodium_buf, padding + inlen, ctx->iv, ctx->ic, _key); 84 | } 85 | *outlen = inlen; 86 | memcpy(out, sodium_buf + padding, inlen); 87 | padding += inlen; 88 | ctx->ic += padding / SODIUM_BLOCK_SIZE; 89 | ctx->bytes_remaining = padding % SODIUM_BLOCK_SIZE; 90 | } 91 | } 92 | 93 | void encrypt_buf(struct encryption_ctx *ctx, unsigned char *buf, size_t *len) { 94 | if (ctx->cipher == CIPHER_TABLE) { 95 | table_encrypt(buf, *len); 96 | } else { 97 | if (ctx->status == STATUS_EMPTY) { 98 | size_t iv_len = encryption_iv_len[_method]; 99 | memset(ctx->iv, 0, iv_len); 100 | RAND_bytes(ctx->iv, iv_len); 101 | init_cipher(ctx, ctx->iv, iv_len, 1); 102 | size_t out_len = *len + ctx->iv_len; 103 | unsigned char *cipher_text = malloc(out_len); 104 | cipher_update(ctx, cipher_text, &out_len, buf, *len); 105 | memcpy(buf, ctx->iv, iv_len); 106 | memcpy(buf + iv_len, cipher_text, out_len); 107 | *len = iv_len + out_len; 108 | free(cipher_text); 109 | } else { 110 | size_t out_len = *len + ctx->iv_len; 111 | unsigned char *cipher_text = malloc(out_len); 112 | cipher_update(ctx, cipher_text, &out_len, buf, *len); 113 | memcpy(buf, cipher_text, out_len); 114 | *len = out_len; 115 | free(cipher_text); 116 | } 117 | } 118 | } 119 | 120 | void decrypt_buf(struct encryption_ctx *ctx, unsigned char *buf, size_t *len) { 121 | if (ctx->cipher == CIPHER_TABLE) { 122 | table_decrypt(buf, *len); 123 | } else { 124 | if (ctx->status == STATUS_EMPTY) { 125 | size_t iv_len = encryption_iv_len[_method]; 126 | memcpy(ctx->iv, buf, iv_len); 127 | init_cipher(ctx, ctx->iv, iv_len, 0); 128 | size_t out_len = *len + ctx->iv_len; 129 | out_len -= iv_len; 130 | unsigned char *cipher_text = malloc(out_len); 131 | cipher_update(ctx, cipher_text, &out_len, buf + iv_len, *len - iv_len); 132 | memcpy(buf, cipher_text, out_len); 133 | *len = out_len; 134 | free(cipher_text); 135 | } else { 136 | size_t out_len = *len + ctx->iv_len; 137 | unsigned char *cipher_text = malloc(out_len); 138 | cipher_update(ctx, cipher_text, &out_len, buf, *len); 139 | memcpy(buf, cipher_text, out_len); 140 | *len = out_len; 141 | free(cipher_text); 142 | } 143 | } 144 | } 145 | 146 | int send_encrypt(struct encryption_ctx *ctx, int sock, unsigned char *buf, size_t *len, int flags) { 147 | unsigned char mybuf[4096]; 148 | memcpy(mybuf, buf, *len); 149 | encrypt_buf(ctx, mybuf, len); 150 | return send(sock, mybuf, *len, flags); 151 | } 152 | 153 | int recv_decrypt(struct encryption_ctx *ctx, int sock, unsigned char *buf, size_t *len, int flags) { 154 | char mybuf[4096]; 155 | int result = recv(sock, mybuf, *len, flags); 156 | memcpy(buf, mybuf, *len); 157 | decrypt_buf(ctx, buf, len); 158 | return result; 159 | } 160 | 161 | void init_cipher(struct encryption_ctx *ctx, const unsigned char *iv, size_t iv_len, int is_cipher) { 162 | ctx->status = STATUS_INIT; 163 | if (ctx->cipher == CIPHER_OPENSSL) { 164 | EVP_CIPHER_CTX_init(ctx->ctx); 165 | EVP_CipherInit_ex(ctx->ctx, _cipher, NULL, NULL, NULL, is_cipher); 166 | if (!EVP_CIPHER_CTX_set_key_length(ctx->ctx, _key_len)) { 167 | cleanup_encryption(ctx); 168 | return; 169 | } 170 | EVP_CIPHER_CTX_set_padding(ctx->ctx, 1); 171 | unsigned char *true_key; 172 | if (_method == ENCRYPTION_RC4_MD5) { 173 | unsigned char key_iv[32]; 174 | memcpy(key_iv, _key, 16); 175 | memcpy(key_iv + 16, iv, 16); 176 | true_key = MD5(key_iv, 32, NULL); 177 | } else { 178 | true_key = _key; 179 | } 180 | EVP_CipherInit_ex(ctx->ctx, NULL, NULL, true_key, iv, is_cipher); 181 | } else if (ctx->cipher == CIPHER_SODIUM) { 182 | ctx->ic = 0; 183 | ctx->bytes_remaining = 0; 184 | } 185 | ctx->iv_len = encryption_iv_len[_method]; 186 | } 187 | 188 | void init_encryption(struct encryption_ctx *ctx) { 189 | ctx->status = STATUS_EMPTY; 190 | ctx->ctx = EVP_CIPHER_CTX_new(); 191 | ctx->cipher = cipher; 192 | } 193 | 194 | void cleanup_encryption(struct encryption_ctx *ctx) { 195 | if (ctx->status == STATUS_INIT) { 196 | if (ctx->cipher == CIPHER_OPENSSL) { 197 | EVP_CIPHER_CTX_cleanup(ctx->ctx); 198 | } 199 | ctx->status = STATUS_DESTORYED; 200 | } 201 | } 202 | 203 | void config_encryption(const char *password, const char *method) { 204 | SSLeay_add_all_algorithms(); 205 | sodium_init(); 206 | _method = encryption_method_from_string(method); 207 | if (_method == ENCRYPTION_TABLE) { 208 | get_table((unsigned char *) password); 209 | cipher = CIPHER_TABLE; 210 | } else if (_method == ENCRYPTION_SALSA20 || _method == ENCRYPTION_CHACHA20) { 211 | cipher = CIPHER_SODIUM; 212 | _key_len = 32; 213 | unsigned char tmp[EVP_MAX_IV_LENGTH];; 214 | EVP_BytesToKey(EVP_aes_256_cfb(), EVP_md5(), NULL, (unsigned char *)password, 215 | strlen(password), 1, _key, tmp); 216 | shadowsocks_key = _key; 217 | } else { 218 | cipher = CIPHER_OPENSSL; 219 | const char *name = shadowsocks_encryption_names[_method]; 220 | if (_method == ENCRYPTION_RC4_MD5) { 221 | name = "RC4"; 222 | } 223 | _cipher = EVP_get_cipherbyname(name); 224 | if (_cipher == NULL) { 225 | // assert(0); 226 | // TODO 227 | printf("_cipher is nil! \r\nThe %s doesn't supported!\r\n please chose anthor!",name); 228 | } else { 229 | unsigned char tmp[EVP_MAX_IV_LENGTH]; 230 | _key_len = EVP_BytesToKey(_cipher, EVP_md5(), NULL, (unsigned char *)password, 231 | strlen(password), 1, _key, tmp); 232 | shadowsocks_key = _key; 233 | } 234 | 235 | // printf("%d\n", _key_len); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /ShadowWeb/encrypt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #import 4 | #import 5 | 6 | struct encryption_ctx { 7 | EVP_CIPHER_CTX* ctx; 8 | uint8_t status; 9 | unsigned char iv[16]; 10 | size_t iv_len; 11 | size_t bytes_remaining; // only for libsodium 12 | uint64_t ic; // only for libsodium 13 | uint8_t cipher; 14 | }; 15 | 16 | #define STATUS_EMPTY 0 17 | #define STATUS_INIT 1 18 | #define STATUS_DESTORYED 2 19 | 20 | #define kShadowsocksMethods 13 21 | 22 | const char *shadowsocks_encryption_names[]; 23 | 24 | void encrypt_buf(struct encryption_ctx* ctx, unsigned char *buf, size_t *len); 25 | void decrypt_buf(struct encryption_ctx* ctx, unsigned char *buf, size_t *len); 26 | 27 | int send_encrypt(struct encryption_ctx* ctx, int sock, unsigned char *buf, size_t *len, int flags); 28 | int recv_decrypt(struct encryption_ctx* ctx, int sock, unsigned char *buf, size_t *len, int flags); 29 | 30 | void init_encryption(struct encryption_ctx* ctx); 31 | void cleanup_encryption(struct encryption_ctx* ctx); 32 | 33 | void config_encryption(const char *password, const char *method); 34 | 35 | unsigned char *shadowsocks_key; 36 | -------------------------------------------------------------------------------- /ShadowWeb/libev/LICENSE: -------------------------------------------------------------------------------- 1 | All files in libev are Copyright (C)2007,2008,2009 Marc Alexander Lehmann. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following 12 | disclaimer in the documentation and/or other materials provided 13 | with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | Alternatively, the contents of this package may be used under the terms 28 | of the GNU General Public License ("GPL") version 2 or any later version, 29 | in which case the provisions of the GPL are applicable instead of the 30 | above. If you wish to allow the use of your version of this package only 31 | under the terms of the GPL and not to allow others to use your version of 32 | this file under the BSD license, indicate your decision by deleting the 33 | provisions above and replace them with the notice and other provisions 34 | required by the GPL in this and the other files of this package. If you do 35 | not delete the provisions above, a recipient may use your version of this 36 | file under either the BSD or the GPL. 37 | -------------------------------------------------------------------------------- /ShadowWeb/libev/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | 3 | VERSION_INFO = 4:0:0 4 | 5 | EXTRA_DIST = LICENSE Changes libev.m4 autogen.sh \ 6 | ev_vars.h ev_wrap.h \ 7 | ev_epoll.c ev_select.c ev_poll.c ev_kqueue.c ev_port.c ev_win32.c \ 8 | ev.3 ev.pod Symbols.ev Symbols.event 9 | 10 | man_MANS = ev.3 11 | 12 | include_HEADERS = ev.h ev++.h event.h 13 | 14 | lib_LTLIBRARIES = libev.la 15 | 16 | libev_la_SOURCES = ev.c event.c 17 | libev_la_LDFLAGS = -version-info $(VERSION_INFO) 18 | 19 | ev.3: ev.pod 20 | pod2man -n LIBEV -r "libev-$(VERSION)" -c "libev - high performance full featured event loop" -s3 <$< >$@ 21 | -------------------------------------------------------------------------------- /ShadowWeb/libev/README: -------------------------------------------------------------------------------- 1 | libev is a high-performance event loop/event model with lots of features. 2 | (see benchmark at http://libev.schmorp.de/bench.html) 3 | 4 | 5 | ABOUT 6 | 7 | Homepage: http://software.schmorp.de/pkg/libev 8 | Mailinglist: libev@lists.schmorp.de 9 | http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev 10 | Library Documentation: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod 11 | 12 | Libev is modelled (very losely) after libevent and the Event perl 13 | module, but is faster, scales better and is more correct, and also more 14 | featureful. And also smaller. Yay. 15 | 16 | Some of the specialties of libev not commonly found elsewhere are: 17 | 18 | - extensive and detailed, readable documentation (not doxygen garbage). 19 | - fully supports fork, can detect fork in various ways and automatically 20 | re-arms kernel mechanisms that do not support fork. 21 | - highly optimised select, poll, epoll, kqueue and event ports backends. 22 | - filesystem object (path) watching (with optional linux inotify support). 23 | - wallclock-based times (using absolute time, cron-like). 24 | - relative timers/timeouts (handle time jumps). 25 | - fast intra-thread communication between multiple 26 | event loops (with optional fast linux eventfd backend). 27 | - extremely easy to embed. 28 | - very small codebase, no bloated library. 29 | - fully extensible by being able to plug into the event loop, 30 | integrate other event loops, integrate other event loop users. 31 | - very little memory use (small watchers, small event loop data). 32 | - optional C++ interface allowing method and function callbacks 33 | at no extra memory or runtime overhead. 34 | - optional Perl interface with similar characteristics (capable 35 | of running Glib/Gtk2 on libev, interfaces with Net::SNMP and 36 | libadns). 37 | - support for other languages (multiple C++ interfaces, D, Ruby, 38 | Python) available from third-parties. 39 | 40 | Examples of programs that embed libev: the EV perl module, 41 | rxvt-unicode, gvpe (GNU Virtual Private Ethernet), the Deliantra MMORPG 42 | server (http://www.deliantra.net/), Rubinius (a next-generation Ruby 43 | VM), the Ebb web server, the Rev event toolkit. 44 | 45 | 46 | CONTRIBUTORS 47 | 48 | libev was written and designed by Marc Lehmann and Emanuele Giaquinta. 49 | 50 | The following people sent in patches or made other noteworthy 51 | contributions to the design (for minor patches, see the Changes 52 | file. If I forgot to include you, please shout at me, it was an 53 | accident): 54 | 55 | W.C.A. Wijngaards 56 | Christopher Layne 57 | Chris Brody 58 | 59 | -------------------------------------------------------------------------------- /ShadowWeb/libev/Symbols.ev: -------------------------------------------------------------------------------- 1 | ev_async_send 2 | ev_async_start 3 | ev_async_stop 4 | ev_backend 5 | ev_break 6 | ev_check_start 7 | ev_check_stop 8 | ev_child_start 9 | ev_child_stop 10 | ev_cleanup_start 11 | ev_cleanup_stop 12 | ev_clear_pending 13 | ev_default_loop 14 | ev_default_loop_ptr 15 | ev_depth 16 | ev_embed_start 17 | ev_embed_stop 18 | ev_embed_sweep 19 | ev_embeddable_backends 20 | ev_feed_event 21 | ev_feed_fd_event 22 | ev_feed_signal 23 | ev_feed_signal_event 24 | ev_fork_start 25 | ev_fork_stop 26 | ev_idle_start 27 | ev_idle_stop 28 | ev_invoke 29 | ev_invoke_pending 30 | ev_io_start 31 | ev_io_stop 32 | ev_iteration 33 | ev_loop_destroy 34 | ev_loop_fork 35 | ev_loop_new 36 | ev_now 37 | ev_now_update 38 | ev_once 39 | ev_pending_count 40 | ev_periodic_again 41 | ev_periodic_start 42 | ev_periodic_stop 43 | ev_prepare_start 44 | ev_prepare_stop 45 | ev_recommended_backends 46 | ev_ref 47 | ev_resume 48 | ev_run 49 | ev_set_allocator 50 | ev_set_invoke_pending_cb 51 | ev_set_io_collect_interval 52 | ev_set_loop_release_cb 53 | ev_set_syserr_cb 54 | ev_set_timeout_collect_interval 55 | ev_set_userdata 56 | ev_signal_start 57 | ev_signal_stop 58 | ev_sleep 59 | ev_stat_start 60 | ev_stat_stat 61 | ev_stat_stop 62 | ev_supported_backends 63 | ev_suspend 64 | ev_time 65 | ev_timer_again 66 | ev_timer_remaining 67 | ev_timer_start 68 | ev_timer_stop 69 | ev_unref 70 | ev_userdata 71 | ev_verify 72 | ev_version_major 73 | ev_version_minor 74 | -------------------------------------------------------------------------------- /ShadowWeb/libev/Symbols.event: -------------------------------------------------------------------------------- 1 | event_active 2 | event_add 3 | event_base_dispatch 4 | event_base_free 5 | event_base_loop 6 | event_base_loopexit 7 | event_base_once 8 | event_base_priority_init 9 | event_base_set 10 | event_del 11 | event_dispatch 12 | event_get_method 13 | event_get_version 14 | event_init 15 | event_loop 16 | event_loopexit 17 | event_once 18 | event_pending 19 | event_priority_init 20 | event_priority_set 21 | event_set 22 | -------------------------------------------------------------------------------- /ShadowWeb/libev/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf --install --symlink --force 4 | -------------------------------------------------------------------------------- /ShadowWeb/libev/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the `clock_gettime' function. */ 5 | /* #undef HAVE_CLOCK_GETTIME */ 6 | 7 | /* Define to 1 to use the syscall interface for clock_gettime */ 8 | /* #undef HAVE_CLOCK_SYSCALL */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_DLFCN_H 1 12 | 13 | /* Define to 1 if you have the `epoll_ctl' function. */ 14 | /* #undef HAVE_EPOLL_CTL */ 15 | 16 | /* Define to 1 if you have the `eventfd' function. */ 17 | /* #undef HAVE_EVENTFD */ 18 | 19 | /* Define to 1 if the floor function is available */ 20 | #define HAVE_FLOOR 1 21 | 22 | /* Define to 1 if you have the `inotify_init' function. */ 23 | /* #undef HAVE_INOTIFY_INIT */ 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `kqueue' function. */ 29 | #define HAVE_KQUEUE 1 30 | 31 | /* Define to 1 if you have the `rt' library (-lrt). */ 32 | /* #undef HAVE_LIBRT */ 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_MEMORY_H 1 36 | 37 | /* Define to 1 if you have the `nanosleep' function. */ 38 | #define HAVE_NANOSLEEP 1 39 | 40 | /* Define to 1 if you have the `poll' function. */ 41 | #define HAVE_POLL 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_POLL_H 1 45 | 46 | /* Define to 1 if you have the `port_create' function. */ 47 | /* #undef HAVE_PORT_CREATE */ 48 | 49 | /* Define to 1 if you have the header file. */ 50 | /* #undef HAVE_PORT_H */ 51 | 52 | /* Define to 1 if you have the `select' function. */ 53 | #define HAVE_SELECT 1 54 | 55 | /* Define to 1 if you have the `signalfd' function. */ 56 | /* #undef HAVE_SIGNALFD */ 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_STDINT_H 1 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_STDLIB_H 1 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #define HAVE_STRINGS_H 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_STRING_H 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | /* #undef HAVE_SYS_EPOLL_H */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | /* #undef HAVE_SYS_EVENTFD_H */ 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_SYS_EVENT_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | /* #undef HAVE_SYS_INOTIFY_H */ 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_SYS_SELECT_H 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | /* #undef HAVE_SYS_SIGNALFD_H */ 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #define HAVE_SYS_STAT_H 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_SYS_TYPES_H 1 93 | 94 | /* Define to 1 if you have the header file. */ 95 | #define HAVE_UNISTD_H 1 96 | 97 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 98 | */ 99 | #define LT_OBJDIR ".libs/" 100 | 101 | /* Name of package */ 102 | #define PACKAGE "libev" 103 | 104 | /* Define to the address where bug reports for this package should be sent. */ 105 | #define PACKAGE_BUGREPORT "" 106 | 107 | /* Define to the full name of this package. */ 108 | #define PACKAGE_NAME "" 109 | 110 | /* Define to the full name and version of this package. */ 111 | #define PACKAGE_STRING "" 112 | 113 | /* Define to the one symbol short name of this package. */ 114 | #define PACKAGE_TARNAME "" 115 | 116 | /* Define to the home page for this package. */ 117 | #define PACKAGE_URL "" 118 | 119 | /* Define to the version of this package. */ 120 | #define PACKAGE_VERSION "" 121 | 122 | /* Define to 1 if you have the ANSI C header files. */ 123 | #define STDC_HEADERS 1 124 | 125 | /* Version number of package */ 126 | #define VERSION "4.11" 127 | -------------------------------------------------------------------------------- /ShadowWeb/libev/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the `clock_gettime' function. */ 4 | #undef HAVE_CLOCK_GETTIME 5 | 6 | /* Define to 1 to use the syscall interface for clock_gettime */ 7 | #undef HAVE_CLOCK_SYSCALL 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_DLFCN_H 11 | 12 | /* Define to 1 if you have the `epoll_ctl' function. */ 13 | #undef HAVE_EPOLL_CTL 14 | 15 | /* Define to 1 if you have the `eventfd' function. */ 16 | #undef HAVE_EVENTFD 17 | 18 | /* Define to 1 if the floor function is available */ 19 | #undef HAVE_FLOOR 20 | 21 | /* Define to 1 if you have the `inotify_init' function. */ 22 | #undef HAVE_INOTIFY_INIT 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_INTTYPES_H 26 | 27 | /* Define to 1 if you have the `kqueue' function. */ 28 | #undef HAVE_KQUEUE 29 | 30 | /* Define to 1 if you have the `rt' library (-lrt). */ 31 | #undef HAVE_LIBRT 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_MEMORY_H 35 | 36 | /* Define to 1 if you have the `nanosleep' function. */ 37 | #undef HAVE_NANOSLEEP 38 | 39 | /* Define to 1 if you have the `poll' function. */ 40 | #undef HAVE_POLL 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_POLL_H 44 | 45 | /* Define to 1 if you have the `port_create' function. */ 46 | #undef HAVE_PORT_CREATE 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_PORT_H 50 | 51 | /* Define to 1 if you have the `select' function. */ 52 | #undef HAVE_SELECT 53 | 54 | /* Define to 1 if you have the `signalfd' function. */ 55 | #undef HAVE_SIGNALFD 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_STDINT_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_STDLIB_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_STRINGS_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_STRING_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_SYS_EPOLL_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_SYS_EVENTFD_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_SYS_EVENT_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_SYS_INOTIFY_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_SYS_SELECT_H 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #undef HAVE_SYS_SIGNALFD_H 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #undef HAVE_SYS_STAT_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #undef HAVE_SYS_TYPES_H 92 | 93 | /* Define to 1 if you have the header file. */ 94 | #undef HAVE_UNISTD_H 95 | 96 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 97 | */ 98 | #undef LT_OBJDIR 99 | 100 | /* Name of package */ 101 | #undef PACKAGE 102 | 103 | /* Define to the address where bug reports for this package should be sent. */ 104 | #undef PACKAGE_BUGREPORT 105 | 106 | /* Define to the full name of this package. */ 107 | #undef PACKAGE_NAME 108 | 109 | /* Define to the full name and version of this package. */ 110 | #undef PACKAGE_STRING 111 | 112 | /* Define to the one symbol short name of this package. */ 113 | #undef PACKAGE_TARNAME 114 | 115 | /* Define to the home page for this package. */ 116 | #undef PACKAGE_URL 117 | 118 | /* Define to the version of this package. */ 119 | #undef PACKAGE_VERSION 120 | 121 | /* Define to 1 if you have the ANSI C header files. */ 122 | #undef STDC_HEADERS 123 | 124 | /* Version number of package */ 125 | #undef VERSION 126 | -------------------------------------------------------------------------------- /ShadowWeb/libev/configure.ac: -------------------------------------------------------------------------------- 1 | orig_CFLAGS="$CFLAGS" 2 | 3 | AC_INIT 4 | AC_CONFIG_SRCDIR([ev_epoll.c]) 5 | 6 | AM_INIT_AUTOMAKE(libev,4.11) dnl also update ev.h! 7 | AC_CONFIG_HEADERS([config.h]) 8 | AM_MAINTAINER_MODE 9 | 10 | AC_PROG_CC 11 | 12 | dnl Supply default CFLAGS, if not specified 13 | if test -z "$orig_CFLAGS"; then 14 | if test x$GCC = xyes; then 15 | CFLAGS="-g -O3" 16 | fi 17 | fi 18 | 19 | AC_PROG_INSTALL 20 | AC_PROG_LIBTOOL 21 | 22 | m4_include([libev.m4]) 23 | 24 | AC_CONFIG_FILES([Makefile]) 25 | AC_OUTPUT 26 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_kqueue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev kqueue backend 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | void inline_speed 47 | kqueue_change (EV_P_ int fd, int filter, int flags, int fflags) 48 | { 49 | ++kqueue_changecnt; 50 | array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, EMPTY2); 51 | 52 | EV_SET (&kqueue_changes [kqueue_changecnt - 1], fd, filter, flags, fflags, 0, 0); 53 | } 54 | 55 | /* OS X at least needs this */ 56 | #ifndef EV_ENABLE 57 | # define EV_ENABLE 0 58 | #endif 59 | #ifndef NOTE_EOF 60 | # define NOTE_EOF 0 61 | #endif 62 | 63 | static void 64 | kqueue_modify (EV_P_ int fd, int oev, int nev) 65 | { 66 | if (oev != nev) 67 | { 68 | if (oev & EV_READ) 69 | kqueue_change (EV_A_ fd, EVFILT_READ , EV_DELETE, 0); 70 | 71 | if (oev & EV_WRITE) 72 | kqueue_change (EV_A_ fd, EVFILT_WRITE, EV_DELETE, 0); 73 | } 74 | 75 | /* to detect close/reopen reliably, we have to re-add */ 76 | /* event requests even when oev == nev */ 77 | 78 | if (nev & EV_READ) 79 | kqueue_change (EV_A_ fd, EVFILT_READ , EV_ADD | EV_ENABLE, NOTE_EOF); 80 | 81 | if (nev & EV_WRITE) 82 | kqueue_change (EV_A_ fd, EVFILT_WRITE, EV_ADD | EV_ENABLE, NOTE_EOF); 83 | } 84 | 85 | static void 86 | kqueue_poll (EV_P_ ev_tstamp timeout) 87 | { 88 | int res, i; 89 | struct timespec ts; 90 | 91 | /* need to resize so there is enough space for errors */ 92 | if (kqueue_changecnt > kqueue_eventmax) 93 | { 94 | ev_free (kqueue_events); 95 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt); 96 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); 97 | } 98 | 99 | EV_RELEASE_CB; 100 | EV_TS_SET (ts, timeout); 101 | res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); 102 | EV_ACQUIRE_CB; 103 | kqueue_changecnt = 0; 104 | 105 | if (expect_false (res < 0)) 106 | { 107 | if (errno != EINTR) 108 | ev_syserr ("(libev) kevent"); 109 | 110 | return; 111 | } 112 | 113 | for (i = 0; i < res; ++i) 114 | { 115 | int fd = kqueue_events [i].ident; 116 | 117 | if (expect_false (kqueue_events [i].flags & EV_ERROR)) 118 | { 119 | int err = kqueue_events [i].data; 120 | 121 | /* we are only interested in errors for fds that we are interested in :) */ 122 | if (anfds [fd].events) 123 | { 124 | if (err == ENOENT) /* resubmit changes on ENOENT */ 125 | kqueue_modify (EV_A_ fd, 0, anfds [fd].events); 126 | else if (err == EBADF) /* on EBADF, we re-check the fd */ 127 | { 128 | if (fd_valid (fd)) 129 | kqueue_modify (EV_A_ fd, 0, anfds [fd].events); 130 | else 131 | fd_kill (EV_A_ fd); 132 | } 133 | else /* on all other errors, we error out on the fd */ 134 | fd_kill (EV_A_ fd); 135 | } 136 | } 137 | else 138 | fd_event ( 139 | EV_A_ 140 | fd, 141 | kqueue_events [i].filter == EVFILT_READ ? EV_READ 142 | : kqueue_events [i].filter == EVFILT_WRITE ? EV_WRITE 143 | : 0 144 | ); 145 | } 146 | 147 | if (expect_false (res == kqueue_eventmax)) 148 | { 149 | ev_free (kqueue_events); 150 | kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_eventmax + 1); 151 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); 152 | } 153 | } 154 | 155 | int inline_size 156 | kqueue_init (EV_P_ int flags) 157 | { 158 | /* Initialize the kernel queue */ 159 | if ((backend_fd = kqueue ()) < 0) 160 | return 0; 161 | 162 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ 163 | 164 | backend_mintime = 1e-9; /* apparently, they did the right thing in freebsd */ 165 | backend_modify = kqueue_modify; 166 | backend_poll = kqueue_poll; 167 | 168 | kqueue_eventmax = 64; /* initial number of events receivable per poll */ 169 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); 170 | 171 | kqueue_changes = 0; 172 | kqueue_changemax = 0; 173 | kqueue_changecnt = 0; 174 | 175 | return EVBACKEND_KQUEUE; 176 | } 177 | 178 | void inline_size 179 | kqueue_destroy (EV_P) 180 | { 181 | ev_free (kqueue_events); 182 | ev_free (kqueue_changes); 183 | } 184 | 185 | void inline_size 186 | kqueue_fork (EV_P) 187 | { 188 | close (backend_fd); 189 | 190 | while ((backend_fd = kqueue ()) < 0) 191 | ev_syserr ("(libev) kqueue"); 192 | 193 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); 194 | 195 | /* re-register interest in fds */ 196 | fd_rearm_all (EV_A); 197 | } 198 | 199 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_poll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev poll fd activity backend 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #include 41 | 42 | void inline_size 43 | pollidx_init (int *base, int count) 44 | { 45 | /* consider using memset (.., -1, ...), which is practically guaranteed 46 | * to work on all systems implementing poll */ 47 | while (count--) 48 | *base++ = -1; 49 | } 50 | 51 | static void 52 | poll_modify (EV_P_ int fd, int oev, int nev) 53 | { 54 | int idx; 55 | 56 | if (oev == nev) 57 | return; 58 | 59 | array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init); 60 | 61 | idx = pollidxs [fd]; 62 | 63 | if (idx < 0) /* need to allocate a new pollfd */ 64 | { 65 | pollidxs [fd] = idx = pollcnt++; 66 | array_needsize (struct pollfd, polls, pollmax, pollcnt, EMPTY2); 67 | polls [idx].fd = fd; 68 | } 69 | 70 | assert (polls [idx].fd == fd); 71 | 72 | if (nev) 73 | polls [idx].events = 74 | (nev & EV_READ ? POLLIN : 0) 75 | | (nev & EV_WRITE ? POLLOUT : 0); 76 | else /* remove pollfd */ 77 | { 78 | pollidxs [fd] = -1; 79 | 80 | if (expect_true (idx < --pollcnt)) 81 | { 82 | polls [idx] = polls [pollcnt]; 83 | pollidxs [polls [idx].fd] = idx; 84 | } 85 | } 86 | } 87 | 88 | static void 89 | poll_poll (EV_P_ ev_tstamp timeout) 90 | { 91 | struct pollfd *p; 92 | int res; 93 | 94 | EV_RELEASE_CB; 95 | res = poll (polls, pollcnt, timeout * 1e3); 96 | EV_ACQUIRE_CB; 97 | 98 | if (expect_false (res < 0)) 99 | { 100 | if (errno == EBADF) 101 | fd_ebadf (EV_A); 102 | else if (errno == ENOMEM && !syserr_cb) 103 | fd_enomem (EV_A); 104 | else if (errno != EINTR) 105 | ev_syserr ("(libev) poll"); 106 | } 107 | else 108 | for (p = polls; res; ++p) 109 | { 110 | assert (("libev: poll() returned illegal result, broken BSD kernel?", p < polls + pollcnt)); 111 | 112 | if (expect_false (p->revents)) /* this expect is debatable */ 113 | { 114 | --res; 115 | 116 | if (expect_false (p->revents & POLLNVAL)) 117 | fd_kill (EV_A_ p->fd); 118 | else 119 | fd_event ( 120 | EV_A_ 121 | p->fd, 122 | (p->revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) 123 | | (p->revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) 124 | ); 125 | } 126 | } 127 | } 128 | 129 | int inline_size 130 | poll_init (EV_P_ int flags) 131 | { 132 | backend_mintime = 1e-3; 133 | backend_modify = poll_modify; 134 | backend_poll = poll_poll; 135 | 136 | pollidxs = 0; pollidxmax = 0; 137 | polls = 0; pollmax = 0; pollcnt = 0; 138 | 139 | return EVBACKEND_POLL; 140 | } 141 | 142 | void inline_size 143 | poll_destroy (EV_P) 144 | { 145 | ev_free (pollidxs); 146 | ev_free (polls); 147 | } 148 | 149 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev solaris event port backend 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | /* useful reading: 41 | * 42 | * http://bugs.opensolaris.org/view_bug.do?bug_id=6268715 (random results) 43 | * http://bugs.opensolaris.org/view_bug.do?bug_id=6455223 (just totally broken) 44 | * http://bugs.opensolaris.org/view_bug.do?bug_id=6873782 (manpage ETIME) 45 | * http://bugs.opensolaris.org/view_bug.do?bug_id=6874410 (implementation ETIME) 46 | * http://www.mail-archive.com/networking-discuss@opensolaris.org/msg11898.html ETIME vs. nget 47 | * http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/event_port.c (libc) 48 | * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/fs/portfs/port.c#1325 (kernel) 49 | */ 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | void inline_speed 59 | port_associate_and_check (EV_P_ int fd, int ev) 60 | { 61 | if (0 > 62 | port_associate ( 63 | backend_fd, PORT_SOURCE_FD, fd, 64 | (ev & EV_READ ? POLLIN : 0) 65 | | (ev & EV_WRITE ? POLLOUT : 0), 66 | 0 67 | ) 68 | ) 69 | { 70 | if (errno == EBADFD) 71 | fd_kill (EV_A_ fd); 72 | else 73 | ev_syserr ("(libev) port_associate"); 74 | } 75 | } 76 | 77 | static void 78 | port_modify (EV_P_ int fd, int oev, int nev) 79 | { 80 | /* we need to reassociate no matter what, as closes are 81 | * once more silently being discarded. 82 | */ 83 | if (!nev) 84 | { 85 | if (oev) 86 | port_dissociate (backend_fd, PORT_SOURCE_FD, fd); 87 | } 88 | else 89 | port_associate_and_check (EV_A_ fd, nev); 90 | } 91 | 92 | static void 93 | port_poll (EV_P_ ev_tstamp timeout) 94 | { 95 | int res, i; 96 | struct timespec ts; 97 | uint_t nget = 1; 98 | 99 | /* we initialise this to something we will skip in the loop, as */ 100 | /* port_getn can return with nget unchanged, but no indication */ 101 | /* whether it was the original value or has been updated :/ */ 102 | port_events [0].portev_source = 0; 103 | 104 | EV_RELEASE_CB; 105 | EV_TS_SET (ts, timeout); 106 | res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts); 107 | EV_ACQUIRE_CB; 108 | 109 | /* port_getn may or may not set nget on error */ 110 | /* so we rely on port_events [0].portev_source not being updated */ 111 | if (res == -1 && errno != ETIME && errno != EINTR) 112 | ev_syserr ("(libev) port_getn (see http://bugs.opensolaris.org/view_bug.do?bug_id=6268715, try LIBEV_FLAGS=3 env variable)"); 113 | 114 | for (i = 0; i < nget; ++i) 115 | { 116 | if (port_events [i].portev_source == PORT_SOURCE_FD) 117 | { 118 | int fd = port_events [i].portev_object; 119 | 120 | fd_event ( 121 | EV_A_ 122 | fd, 123 | (port_events [i].portev_events & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) 124 | | (port_events [i].portev_events & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) 125 | ); 126 | 127 | fd_change (EV_A_ fd, EV__IOFDSET); 128 | } 129 | } 130 | 131 | if (expect_false (nget == port_eventmax)) 132 | { 133 | ev_free (port_events); 134 | port_eventmax = array_nextsize (sizeof (port_event_t), port_eventmax, port_eventmax + 1); 135 | port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax); 136 | } 137 | } 138 | 139 | int inline_size 140 | port_init (EV_P_ int flags) 141 | { 142 | /* Initialize the kernel queue */ 143 | if ((backend_fd = port_create ()) < 0) 144 | return 0; 145 | 146 | assert (("libev: PORT_SOURCE_FD must not be zero", PORT_SOURCE_FD)); 147 | 148 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ 149 | 150 | /* if my reading of the opensolaris kernel sources are correct, then 151 | * opensolaris does something very stupid: it checks if the time has already 152 | * elapsed and doesn't round up if that is the case,m otherwise it DOES round 153 | * up. Since we can't know what the case is, we need to guess by using a 154 | * "large enough" timeout. Normally, 1e-9 would be correct. 155 | */ 156 | backend_mintime = 1e-3; /* needed to compensate for port_getn returning early */ 157 | backend_modify = port_modify; 158 | backend_poll = port_poll; 159 | 160 | port_eventmax = 64; /* initial number of events receivable per poll */ 161 | port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax); 162 | 163 | return EVBACKEND_PORT; 164 | } 165 | 166 | void inline_size 167 | port_destroy (EV_P) 168 | { 169 | ev_free (port_events); 170 | } 171 | 172 | void inline_size 173 | port_fork (EV_P) 174 | { 175 | close (backend_fd); 176 | 177 | while ((backend_fd = port_create ()) < 0) 178 | ev_syserr ("(libev) port"); 179 | 180 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); 181 | 182 | /* re-register interest in fds */ 183 | fd_rearm_all (EV_A); 184 | } 185 | 186 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_select.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev select fd activity backend 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #ifndef _WIN32 41 | /* for unix systems */ 42 | # include 43 | # ifndef __hpux 44 | /* for REAL unix systems */ 45 | # include 46 | # endif 47 | #endif 48 | 49 | #ifndef EV_SELECT_USE_FD_SET 50 | # ifdef NFDBITS 51 | # define EV_SELECT_USE_FD_SET 0 52 | # else 53 | # define EV_SELECT_USE_FD_SET 1 54 | # endif 55 | #endif 56 | 57 | #if EV_SELECT_IS_WINSOCKET 58 | # undef EV_SELECT_USE_FD_SET 59 | # define EV_SELECT_USE_FD_SET 1 60 | # undef NFDBITS 61 | # define NFDBITS 0 62 | #endif 63 | 64 | #if !EV_SELECT_USE_FD_SET 65 | # define NFDBYTES (NFDBITS / 8) 66 | #endif 67 | 68 | #include 69 | 70 | static void 71 | select_modify (EV_P_ int fd, int oev, int nev) 72 | { 73 | if (oev == nev) 74 | return; 75 | 76 | { 77 | #if EV_SELECT_USE_FD_SET 78 | 79 | #if EV_SELECT_IS_WINSOCKET 80 | SOCKET handle = anfds [fd].handle; 81 | #else 82 | int handle = fd; 83 | #endif 84 | 85 | assert (("libev: fd >= FD_SETSIZE passed to fd_set-based select backend", fd < FD_SETSIZE)); 86 | 87 | /* FD_SET is broken on windows (it adds the fd to a set twice or more, 88 | * which eventually leads to overflows). Need to call it only on changes. 89 | */ 90 | #if EV_SELECT_IS_WINSOCKET 91 | if ((oev ^ nev) & EV_READ) 92 | #endif 93 | if (nev & EV_READ) 94 | FD_SET (handle, (fd_set *)vec_ri); 95 | else 96 | FD_CLR (handle, (fd_set *)vec_ri); 97 | 98 | #if EV_SELECT_IS_WINSOCKET 99 | if ((oev ^ nev) & EV_WRITE) 100 | #endif 101 | if (nev & EV_WRITE) 102 | FD_SET (handle, (fd_set *)vec_wi); 103 | else 104 | FD_CLR (handle, (fd_set *)vec_wi); 105 | 106 | #else 107 | 108 | int word = fd / NFDBITS; 109 | fd_mask mask = 1UL << (fd % NFDBITS); 110 | 111 | if (expect_false (vec_max <= word)) 112 | { 113 | int new_max = word + 1; 114 | 115 | vec_ri = ev_realloc (vec_ri, new_max * NFDBYTES); 116 | vec_ro = ev_realloc (vec_ro, new_max * NFDBYTES); /* could free/malloc */ 117 | vec_wi = ev_realloc (vec_wi, new_max * NFDBYTES); 118 | vec_wo = ev_realloc (vec_wo, new_max * NFDBYTES); /* could free/malloc */ 119 | #ifdef _WIN32 120 | vec_eo = ev_realloc (vec_eo, new_max * NFDBYTES); /* could free/malloc */ 121 | #endif 122 | 123 | for (; vec_max < new_max; ++vec_max) 124 | ((fd_mask *)vec_ri) [vec_max] = 125 | ((fd_mask *)vec_wi) [vec_max] = 0; 126 | } 127 | 128 | ((fd_mask *)vec_ri) [word] |= mask; 129 | if (!(nev & EV_READ)) 130 | ((fd_mask *)vec_ri) [word] &= ~mask; 131 | 132 | ((fd_mask *)vec_wi) [word] |= mask; 133 | if (!(nev & EV_WRITE)) 134 | ((fd_mask *)vec_wi) [word] &= ~mask; 135 | #endif 136 | } 137 | } 138 | 139 | static void 140 | select_poll (EV_P_ ev_tstamp timeout) 141 | { 142 | struct timeval tv; 143 | int res; 144 | int fd_setsize; 145 | 146 | EV_RELEASE_CB; 147 | EV_TV_SET (tv, timeout); 148 | 149 | #if EV_SELECT_USE_FD_SET 150 | fd_setsize = sizeof (fd_set); 151 | #else 152 | fd_setsize = vec_max * NFDBYTES; 153 | #endif 154 | 155 | memcpy (vec_ro, vec_ri, fd_setsize); 156 | memcpy (vec_wo, vec_wi, fd_setsize); 157 | 158 | #ifdef _WIN32 159 | /* pass in the write set as except set. 160 | * the idea behind this is to work around a windows bug that causes 161 | * errors to be reported as an exception and not by setting 162 | * the writable bit. this is so uncontrollably lame. 163 | */ 164 | memcpy (vec_eo, vec_wi, fd_setsize); 165 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, (fd_set *)vec_eo, &tv); 166 | #elif EV_SELECT_USE_FD_SET 167 | fd_setsize = anfdmax < FD_SETSIZE ? anfdmax : FD_SETSIZE; 168 | res = select (fd_setsize, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); 169 | #else 170 | res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); 171 | #endif 172 | EV_ACQUIRE_CB; 173 | 174 | if (expect_false (res < 0)) 175 | { 176 | #if EV_SELECT_IS_WINSOCKET 177 | errno = WSAGetLastError (); 178 | #endif 179 | #ifdef WSABASEERR 180 | /* on windows, select returns incompatible error codes, fix this */ 181 | if (errno >= WSABASEERR && errno < WSABASEERR + 1000) 182 | if (errno == WSAENOTSOCK) 183 | errno = EBADF; 184 | else 185 | errno -= WSABASEERR; 186 | #endif 187 | 188 | #ifdef _WIN32 189 | /* select on windows erroneously returns EINVAL when no fd sets have been 190 | * provided (this is documented). what microsoft doesn't tell you that this bug 191 | * exists even when the fd sets _are_ provided, so we have to check for this bug 192 | * here and emulate by sleeping manually. 193 | * we also get EINVAL when the timeout is invalid, but we ignore this case here 194 | * and assume that EINVAL always means: you have to wait manually. 195 | */ 196 | if (errno == EINVAL) 197 | { 198 | if (timeout) 199 | { 200 | unsigned long ms = timeout * 1e3; 201 | Sleep (ms ? ms : 1); 202 | } 203 | 204 | return; 205 | } 206 | #endif 207 | 208 | if (errno == EBADF) 209 | fd_ebadf (EV_A); 210 | else if (errno == ENOMEM && !syserr_cb) 211 | fd_enomem (EV_A); 212 | else if (errno != EINTR) 213 | ev_syserr ("(libev) select"); 214 | 215 | return; 216 | } 217 | 218 | #if EV_SELECT_USE_FD_SET 219 | 220 | { 221 | int fd; 222 | 223 | for (fd = 0; fd < anfdmax; ++fd) 224 | if (anfds [fd].events) 225 | { 226 | int events = 0; 227 | #if EV_SELECT_IS_WINSOCKET 228 | SOCKET handle = anfds [fd].handle; 229 | #else 230 | int handle = fd; 231 | #endif 232 | 233 | if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ; 234 | if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE; 235 | #ifdef _WIN32 236 | if (FD_ISSET (handle, (fd_set *)vec_eo)) events |= EV_WRITE; 237 | #endif 238 | 239 | if (expect_true (events)) 240 | fd_event (EV_A_ fd, events); 241 | } 242 | } 243 | 244 | #else 245 | 246 | { 247 | int word, bit; 248 | for (word = vec_max; word--; ) 249 | { 250 | fd_mask word_r = ((fd_mask *)vec_ro) [word]; 251 | fd_mask word_w = ((fd_mask *)vec_wo) [word]; 252 | #ifdef _WIN32 253 | word_w |= ((fd_mask *)vec_eo) [word]; 254 | #endif 255 | 256 | if (word_r || word_w) 257 | for (bit = NFDBITS; bit--; ) 258 | { 259 | fd_mask mask = 1UL << bit; 260 | int events = 0; 261 | 262 | events |= word_r & mask ? EV_READ : 0; 263 | events |= word_w & mask ? EV_WRITE : 0; 264 | 265 | if (expect_true (events)) 266 | fd_event (EV_A_ word * NFDBITS + bit, events); 267 | } 268 | } 269 | } 270 | 271 | #endif 272 | } 273 | 274 | int inline_size 275 | select_init (EV_P_ int flags) 276 | { 277 | backend_mintime = 1e-6; 278 | backend_modify = select_modify; 279 | backend_poll = select_poll; 280 | 281 | #if EV_SELECT_USE_FD_SET 282 | vec_ri = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_ri); 283 | vec_ro = ev_malloc (sizeof (fd_set)); 284 | vec_wi = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_wi); 285 | vec_wo = ev_malloc (sizeof (fd_set)); 286 | #ifdef _WIN32 287 | vec_eo = ev_malloc (sizeof (fd_set)); 288 | #endif 289 | #else 290 | vec_max = 0; 291 | vec_ri = 0; 292 | vec_ro = 0; 293 | vec_wi = 0; 294 | vec_wo = 0; 295 | #ifdef _WIN32 296 | vec_eo = 0; 297 | #endif 298 | #endif 299 | 300 | return EVBACKEND_SELECT; 301 | } 302 | 303 | void inline_size 304 | select_destroy (EV_P) 305 | { 306 | ev_free (vec_ri); 307 | ev_free (vec_ro); 308 | ev_free (vec_wi); 309 | ev_free (vec_wo); 310 | #ifdef _WIN32 311 | ev_free (vec_eo); 312 | #endif 313 | } 314 | 315 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_vars.h: -------------------------------------------------------------------------------- 1 | /* 2 | * loop member variable declarations 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #define VARx(type,name) VAR(name, type name) 41 | 42 | VARx(ev_tstamp, now_floor) /* last time we refreshed rt_time */ 43 | VARx(ev_tstamp, mn_now) /* monotonic clock "now" */ 44 | VARx(ev_tstamp, rtmn_diff) /* difference realtime - monotonic time */ 45 | 46 | VARx(ev_tstamp, io_blocktime) 47 | VARx(ev_tstamp, timeout_blocktime) 48 | 49 | VARx(int, backend) 50 | VARx(int, activecnt) /* total number of active events ("refcount") */ 51 | VARx(EV_ATOMIC_T, loop_done) /* signal by ev_break */ 52 | 53 | VARx(int, backend_fd) 54 | VARx(ev_tstamp, backend_mintime) /* assumed typical timer resolution */ 55 | VAR (backend_modify, void (*backend_modify)(EV_P_ int fd, int oev, int nev)) 56 | VAR (backend_poll , void (*backend_poll)(EV_P_ ev_tstamp timeout)) 57 | 58 | VARx(ANFD *, anfds) 59 | VARx(int, anfdmax) 60 | 61 | VAR (pendings, ANPENDING *pendings [NUMPRI]) 62 | VAR (pendingmax, int pendingmax [NUMPRI]) 63 | VAR (pendingcnt, int pendingcnt [NUMPRI]) 64 | VARx(ev_prepare, pending_w) /* dummy pending watcher */ 65 | 66 | /* for reverse feeding of events */ 67 | VARx(W *, rfeeds) 68 | VARx(int, rfeedmax) 69 | VARx(int, rfeedcnt) 70 | 71 | #if EV_USE_EVENTFD || EV_GENWRAP 72 | VARx(int, evfd) 73 | #endif 74 | VAR (evpipe, int evpipe [2]) 75 | VARx(ev_io, pipe_w) 76 | VARx(EV_ATOMIC_T, pipe_write_wanted) 77 | VARx(EV_ATOMIC_T, pipe_write_skipped) 78 | 79 | #if !defined(_WIN32) || EV_GENWRAP 80 | VARx(pid_t, curpid) 81 | #endif 82 | 83 | VARx(char, postfork) /* true if we need to recreate kernel state after fork */ 84 | 85 | #if EV_USE_SELECT || EV_GENWRAP 86 | VARx(void *, vec_ri) 87 | VARx(void *, vec_ro) 88 | VARx(void *, vec_wi) 89 | VARx(void *, vec_wo) 90 | #if defined(_WIN32) || EV_GENWRAP 91 | VARx(void *, vec_eo) 92 | #endif 93 | VARx(int, vec_max) 94 | #endif 95 | 96 | #if EV_USE_POLL || EV_GENWRAP 97 | VARx(struct pollfd *, polls) 98 | VARx(int, pollmax) 99 | VARx(int, pollcnt) 100 | VARx(int *, pollidxs) /* maps fds into structure indices */ 101 | VARx(int, pollidxmax) 102 | #endif 103 | 104 | #if EV_USE_EPOLL || EV_GENWRAP 105 | VARx(struct epoll_event *, epoll_events) 106 | VARx(int, epoll_eventmax) 107 | VARx(int *, epoll_eperms) 108 | VARx(int, epoll_epermcnt) 109 | VARx(int, epoll_epermmax) 110 | #endif 111 | 112 | #if EV_USE_KQUEUE || EV_GENWRAP 113 | VARx(struct kevent *, kqueue_changes) 114 | VARx(int, kqueue_changemax) 115 | VARx(int, kqueue_changecnt) 116 | VARx(struct kevent *, kqueue_events) 117 | VARx(int, kqueue_eventmax) 118 | #endif 119 | 120 | #if EV_USE_PORT || EV_GENWRAP 121 | VARx(struct port_event *, port_events) 122 | VARx(int, port_eventmax) 123 | #endif 124 | 125 | #if EV_USE_IOCP || EV_GENWRAP 126 | VARx(HANDLE, iocp) 127 | #endif 128 | 129 | VARx(int *, fdchanges) 130 | VARx(int, fdchangemax) 131 | VARx(int, fdchangecnt) 132 | 133 | VARx(ANHE *, timers) 134 | VARx(int, timermax) 135 | VARx(int, timercnt) 136 | 137 | #if EV_PERIODIC_ENABLE || EV_GENWRAP 138 | VARx(ANHE *, periodics) 139 | VARx(int, periodicmax) 140 | VARx(int, periodiccnt) 141 | #endif 142 | 143 | #if EV_IDLE_ENABLE || EV_GENWRAP 144 | VAR (idles, ev_idle **idles [NUMPRI]) 145 | VAR (idlemax, int idlemax [NUMPRI]) 146 | VAR (idlecnt, int idlecnt [NUMPRI]) 147 | #endif 148 | VARx(int, idleall) /* total number */ 149 | 150 | VARx(struct ev_prepare **, prepares) 151 | VARx(int, preparemax) 152 | VARx(int, preparecnt) 153 | 154 | VARx(struct ev_check **, checks) 155 | VARx(int, checkmax) 156 | VARx(int, checkcnt) 157 | 158 | #if EV_FORK_ENABLE || EV_GENWRAP 159 | VARx(struct ev_fork **, forks) 160 | VARx(int, forkmax) 161 | VARx(int, forkcnt) 162 | #endif 163 | 164 | #if EV_CLEANUP_ENABLE || EV_GENWRAP 165 | VARx(struct ev_cleanup **, cleanups) 166 | VARx(int, cleanupmax) 167 | VARx(int, cleanupcnt) 168 | #endif 169 | 170 | #if EV_ASYNC_ENABLE || EV_GENWRAP 171 | VARx(EV_ATOMIC_T, async_pending) 172 | VARx(struct ev_async **, asyncs) 173 | VARx(int, asyncmax) 174 | VARx(int, asynccnt) 175 | #endif 176 | 177 | #if EV_USE_INOTIFY || EV_GENWRAP 178 | VARx(int, fs_fd) 179 | VARx(ev_io, fs_w) 180 | VARx(char, fs_2625) /* whether we are running in linux 2.6.25 or newer */ 181 | VAR (fs_hash, ANFS fs_hash [EV_INOTIFY_HASHSIZE]) 182 | #endif 183 | 184 | VARx(EV_ATOMIC_T, sig_pending) 185 | #if EV_USE_SIGNALFD || EV_GENWRAP 186 | VARx(int, sigfd) 187 | VARx(ev_io, sigfd_w) 188 | VARx(sigset_t, sigfd_set) 189 | #endif 190 | 191 | VARx(unsigned int, origflags) /* original loop flags */ 192 | 193 | #if EV_FEATURE_API || EV_GENWRAP 194 | VARx(unsigned int, loop_count) /* total number of loop iterations/blocks */ 195 | VARx(unsigned int, loop_depth) /* #ev_run enters - #ev_run leaves */ 196 | 197 | VARx(void *, userdata) 198 | VAR (release_cb, void (*release_cb)(EV_P)) 199 | VAR (acquire_cb, void (*acquire_cb)(EV_P)) 200 | VAR (invoke_cb , void (*invoke_cb) (EV_P)) 201 | #endif 202 | 203 | #undef VARx 204 | 205 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev win32 compatibility cruft (_not_ a backend) 3 | * 4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #ifdef _WIN32 41 | 42 | /* timeb.h is actually xsi legacy functionality */ 43 | #include 44 | 45 | /* note: the comment below could not be substantiated, but what would I care */ 46 | /* MSDN says this is required to handle SIGFPE */ 47 | /* my wild guess would be that using something floating-pointy is required */ 48 | /* for the crt to do something about it */ 49 | volatile double SIGFPE_REQ = 0.0f; 50 | 51 | /* oh, the humanity! */ 52 | static int 53 | ev_pipe (int filedes [2]) 54 | { 55 | struct sockaddr_in addr = { 0 }; 56 | int addr_size = sizeof (addr); 57 | struct sockaddr_in adr2; 58 | int adr2_size = sizeof (adr2); 59 | SOCKET listener; 60 | SOCKET sock [2] = { -1, -1 }; 61 | 62 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 63 | return -1; 64 | 65 | addr.sin_family = AF_INET; 66 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 67 | addr.sin_port = 0; 68 | 69 | if (bind (listener, (struct sockaddr *)&addr, addr_size)) 70 | goto fail; 71 | 72 | if (getsockname (listener, (struct sockaddr *)&addr, &addr_size)) 73 | goto fail; 74 | 75 | if (listen (listener, 1)) 76 | goto fail; 77 | 78 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 79 | goto fail; 80 | 81 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) 82 | goto fail; 83 | 84 | if ((sock [1] = accept (listener, 0, 0)) < 0) 85 | goto fail; 86 | 87 | /* windows vista returns fantasy port numbers for sockets: 88 | * example for two interconnected tcp sockets: 89 | * 90 | * (Socket::unpack_sockaddr_in getsockname $sock0)[0] == 53364 91 | * (Socket::unpack_sockaddr_in getpeername $sock0)[0] == 53363 92 | * (Socket::unpack_sockaddr_in getsockname $sock1)[0] == 53363 93 | * (Socket::unpack_sockaddr_in getpeername $sock1)[0] == 53365 94 | * 95 | * wow! tridirectional sockets! 96 | * 97 | * this way of checking ports seems to work: 98 | */ 99 | if (getpeername (sock [0], (struct sockaddr *)&addr, &addr_size)) 100 | goto fail; 101 | 102 | if (getsockname (sock [1], (struct sockaddr *)&adr2, &adr2_size)) 103 | goto fail; 104 | 105 | errno = WSAEINVAL; 106 | if (addr_size != adr2_size 107 | || addr.sin_addr.s_addr != adr2.sin_addr.s_addr /* just to be sure, I mean, it's windows */ 108 | || addr.sin_port != adr2.sin_port) 109 | goto fail; 110 | 111 | closesocket (listener); 112 | 113 | #if EV_SELECT_IS_WINSOCKET 114 | filedes [0] = EV_WIN32_HANDLE_TO_FD (sock [0]); 115 | filedes [1] = EV_WIN32_HANDLE_TO_FD (sock [1]); 116 | #else 117 | /* when select isn't winsocket, we also expect socket, connect, accept etc. 118 | * to work on fds */ 119 | filedes [0] = sock [0]; 120 | filedes [1] = sock [1]; 121 | #endif 122 | 123 | return 0; 124 | 125 | fail: 126 | closesocket (listener); 127 | 128 | if (sock [0] != INVALID_SOCKET) closesocket (sock [0]); 129 | if (sock [1] != INVALID_SOCKET) closesocket (sock [1]); 130 | 131 | return -1; 132 | } 133 | 134 | #undef pipe 135 | #define pipe(filedes) ev_pipe (filedes) 136 | 137 | #define EV_HAVE_EV_TIME 1 138 | ev_tstamp 139 | ev_time (void) 140 | { 141 | FILETIME ft; 142 | ULARGE_INTEGER ui; 143 | 144 | GetSystemTimeAsFileTime (&ft); 145 | ui.u.LowPart = ft.dwLowDateTime; 146 | ui.u.HighPart = ft.dwHighDateTime; 147 | 148 | /* msvc cannot convert ulonglong to double... yes, it is that sucky */ 149 | return (LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-7; 150 | } 151 | 152 | #endif 153 | 154 | -------------------------------------------------------------------------------- /ShadowWeb/libev/ev_wrap.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT, automatically generated by update_ev_wrap */ 2 | #ifndef EV_WRAP_H 3 | #define EV_WRAP_H 4 | #define now_floor ((loop)->now_floor) 5 | #define mn_now ((loop)->mn_now) 6 | #define rtmn_diff ((loop)->rtmn_diff) 7 | #define io_blocktime ((loop)->io_blocktime) 8 | #define timeout_blocktime ((loop)->timeout_blocktime) 9 | #define backend ((loop)->backend) 10 | #define activecnt ((loop)->activecnt) 11 | #define loop_done ((loop)->loop_done) 12 | #define backend_fd ((loop)->backend_fd) 13 | #define backend_mintime ((loop)->backend_mintime) 14 | #define backend_modify ((loop)->backend_modify) 15 | #define backend_poll ((loop)->backend_poll) 16 | #define anfds ((loop)->anfds) 17 | #define anfdmax ((loop)->anfdmax) 18 | #define pendings ((loop)->pendings) 19 | #define pendingmax ((loop)->pendingmax) 20 | #define pendingcnt ((loop)->pendingcnt) 21 | #define pending_w ((loop)->pending_w) 22 | #define rfeeds ((loop)->rfeeds) 23 | #define rfeedmax ((loop)->rfeedmax) 24 | #define rfeedcnt ((loop)->rfeedcnt) 25 | #define evfd ((loop)->evfd) 26 | #define evpipe ((loop)->evpipe) 27 | #define pipe_w ((loop)->pipe_w) 28 | #define pipe_write_wanted ((loop)->pipe_write_wanted) 29 | #define pipe_write_skipped ((loop)->pipe_write_skipped) 30 | #define curpid ((loop)->curpid) 31 | #define postfork ((loop)->postfork) 32 | #define vec_ri ((loop)->vec_ri) 33 | #define vec_ro ((loop)->vec_ro) 34 | #define vec_wi ((loop)->vec_wi) 35 | #define vec_wo ((loop)->vec_wo) 36 | #define vec_eo ((loop)->vec_eo) 37 | #define vec_max ((loop)->vec_max) 38 | #define polls ((loop)->polls) 39 | #define pollmax ((loop)->pollmax) 40 | #define pollcnt ((loop)->pollcnt) 41 | #define pollidxs ((loop)->pollidxs) 42 | #define pollidxmax ((loop)->pollidxmax) 43 | #define epoll_events ((loop)->epoll_events) 44 | #define epoll_eventmax ((loop)->epoll_eventmax) 45 | #define epoll_eperms ((loop)->epoll_eperms) 46 | #define epoll_epermcnt ((loop)->epoll_epermcnt) 47 | #define epoll_epermmax ((loop)->epoll_epermmax) 48 | #define kqueue_changes ((loop)->kqueue_changes) 49 | #define kqueue_changemax ((loop)->kqueue_changemax) 50 | #define kqueue_changecnt ((loop)->kqueue_changecnt) 51 | #define kqueue_events ((loop)->kqueue_events) 52 | #define kqueue_eventmax ((loop)->kqueue_eventmax) 53 | #define port_events ((loop)->port_events) 54 | #define port_eventmax ((loop)->port_eventmax) 55 | #define iocp ((loop)->iocp) 56 | #define fdchanges ((loop)->fdchanges) 57 | #define fdchangemax ((loop)->fdchangemax) 58 | #define fdchangecnt ((loop)->fdchangecnt) 59 | #define timers ((loop)->timers) 60 | #define timermax ((loop)->timermax) 61 | #define timercnt ((loop)->timercnt) 62 | #define periodics ((loop)->periodics) 63 | #define periodicmax ((loop)->periodicmax) 64 | #define periodiccnt ((loop)->periodiccnt) 65 | #define idles ((loop)->idles) 66 | #define idlemax ((loop)->idlemax) 67 | #define idlecnt ((loop)->idlecnt) 68 | #define idleall ((loop)->idleall) 69 | #define prepares ((loop)->prepares) 70 | #define preparemax ((loop)->preparemax) 71 | #define preparecnt ((loop)->preparecnt) 72 | #define checks ((loop)->checks) 73 | #define checkmax ((loop)->checkmax) 74 | #define checkcnt ((loop)->checkcnt) 75 | #define forks ((loop)->forks) 76 | #define forkmax ((loop)->forkmax) 77 | #define forkcnt ((loop)->forkcnt) 78 | #define cleanups ((loop)->cleanups) 79 | #define cleanupmax ((loop)->cleanupmax) 80 | #define cleanupcnt ((loop)->cleanupcnt) 81 | #define async_pending ((loop)->async_pending) 82 | #define asyncs ((loop)->asyncs) 83 | #define asyncmax ((loop)->asyncmax) 84 | #define asynccnt ((loop)->asynccnt) 85 | #define fs_fd ((loop)->fs_fd) 86 | #define fs_w ((loop)->fs_w) 87 | #define fs_2625 ((loop)->fs_2625) 88 | #define fs_hash ((loop)->fs_hash) 89 | #define sig_pending ((loop)->sig_pending) 90 | #define sigfd ((loop)->sigfd) 91 | #define sigfd_w ((loop)->sigfd_w) 92 | #define sigfd_set ((loop)->sigfd_set) 93 | #define origflags ((loop)->origflags) 94 | #define loop_count ((loop)->loop_count) 95 | #define loop_depth ((loop)->loop_depth) 96 | #define userdata ((loop)->userdata) 97 | #define release_cb ((loop)->release_cb) 98 | #define acquire_cb ((loop)->acquire_cb) 99 | #define invoke_cb ((loop)->invoke_cb) 100 | #else 101 | #undef EV_WRAP_H 102 | #undef now_floor 103 | #undef mn_now 104 | #undef rtmn_diff 105 | #undef io_blocktime 106 | #undef timeout_blocktime 107 | #undef backend 108 | #undef activecnt 109 | #undef loop_done 110 | #undef backend_fd 111 | #undef backend_mintime 112 | #undef backend_modify 113 | #undef backend_poll 114 | #undef anfds 115 | #undef anfdmax 116 | #undef pendings 117 | #undef pendingmax 118 | #undef pendingcnt 119 | #undef pending_w 120 | #undef rfeeds 121 | #undef rfeedmax 122 | #undef rfeedcnt 123 | #undef evfd 124 | #undef evpipe 125 | #undef pipe_w 126 | #undef pipe_write_wanted 127 | #undef pipe_write_skipped 128 | #undef curpid 129 | #undef postfork 130 | #undef vec_ri 131 | #undef vec_ro 132 | #undef vec_wi 133 | #undef vec_wo 134 | #undef vec_eo 135 | #undef vec_max 136 | #undef polls 137 | #undef pollmax 138 | #undef pollcnt 139 | #undef pollidxs 140 | #undef pollidxmax 141 | #undef epoll_events 142 | #undef epoll_eventmax 143 | #undef epoll_eperms 144 | #undef epoll_epermcnt 145 | #undef epoll_epermmax 146 | #undef kqueue_changes 147 | #undef kqueue_changemax 148 | #undef kqueue_changecnt 149 | #undef kqueue_events 150 | #undef kqueue_eventmax 151 | #undef port_events 152 | #undef port_eventmax 153 | #undef iocp 154 | #undef fdchanges 155 | #undef fdchangemax 156 | #undef fdchangecnt 157 | #undef timers 158 | #undef timermax 159 | #undef timercnt 160 | #undef periodics 161 | #undef periodicmax 162 | #undef periodiccnt 163 | #undef idles 164 | #undef idlemax 165 | #undef idlecnt 166 | #undef idleall 167 | #undef prepares 168 | #undef preparemax 169 | #undef preparecnt 170 | #undef checks 171 | #undef checkmax 172 | #undef checkcnt 173 | #undef forks 174 | #undef forkmax 175 | #undef forkcnt 176 | #undef cleanups 177 | #undef cleanupmax 178 | #undef cleanupcnt 179 | #undef async_pending 180 | #undef asyncs 181 | #undef asyncmax 182 | #undef asynccnt 183 | #undef fs_fd 184 | #undef fs_w 185 | #undef fs_2625 186 | #undef fs_hash 187 | #undef sig_pending 188 | #undef sigfd 189 | #undef sigfd_w 190 | #undef sigfd_set 191 | #undef origflags 192 | #undef loop_count 193 | #undef loop_depth 194 | #undef userdata 195 | #undef release_cb 196 | #undef acquire_cb 197 | #undef invoke_cb 198 | #endif 199 | -------------------------------------------------------------------------------- /ShadowWeb/libev/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libevent compatibility layer 3 | * 4 | * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | #ifdef EV_EVENT_H 45 | # include EV_EVENT_H 46 | #else 47 | # include "event.h" 48 | #endif 49 | 50 | #if EV_MULTIPLICITY 51 | # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base 52 | # define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base 53 | #else 54 | # define dLOOPev 55 | # define dLOOPbase 56 | #endif 57 | 58 | /* never accessed, will always be cast from/to ev_loop */ 59 | struct event_base 60 | { 61 | int dummy; 62 | }; 63 | 64 | static struct event_base *ev_x_cur; 65 | 66 | static ev_tstamp 67 | ev_tv_get (struct timeval *tv) 68 | { 69 | if (tv) 70 | { 71 | ev_tstamp after = tv->tv_sec + tv->tv_usec * 1e-6; 72 | return after ? after : 1e-6; 73 | } 74 | else 75 | return -1.; 76 | } 77 | 78 | #define EVENT_STRINGIFY(s) # s 79 | #define EVENT_VERSION(a,b) EVENT_STRINGIFY (a) "." EVENT_STRINGIFY (b) 80 | 81 | const char *event_get_version (void) 82 | { 83 | /* returns ABI, not API or library, version */ 84 | return EVENT_VERSION (EV_VERSION_MAJOR, EV_VERSION_MINOR); 85 | } 86 | 87 | const char *event_get_method (void) 88 | { 89 | return "libev"; 90 | } 91 | 92 | void *event_init (void) 93 | { 94 | #if EV_MULTIPLICITY 95 | if (ev_x_cur) 96 | ev_x_cur = (struct event_base *)ev_loop_new (EVFLAG_AUTO); 97 | else 98 | ev_x_cur = (struct event_base *)ev_default_loop (EVFLAG_AUTO); 99 | #else 100 | assert (("libev: multiple event bases not supported when not compiled with EV_MULTIPLICITY", !ev_x_cur)); 101 | 102 | ev_x_cur = (struct event_base *)(long)ev_default_loop (EVFLAG_AUTO); 103 | #endif 104 | 105 | return ev_x_cur; 106 | } 107 | 108 | void event_base_free (struct event_base *base) 109 | { 110 | dLOOPbase; 111 | 112 | #if EV_MULTIPLICITY 113 | if (!ev_is_default_loop (loop)) 114 | ev_loop_destroy (loop); 115 | #endif 116 | } 117 | 118 | int event_dispatch (void) 119 | { 120 | return event_base_dispatch (ev_x_cur); 121 | } 122 | 123 | #ifdef EV_STANDALONE 124 | void event_set_log_callback (event_log_cb cb) 125 | { 126 | /* nop */ 127 | } 128 | #endif 129 | 130 | int event_loop (int flags) 131 | { 132 | return event_base_loop (ev_x_cur, flags); 133 | } 134 | 135 | int event_loopexit (struct timeval *tv) 136 | { 137 | return event_base_loopexit (ev_x_cur, tv); 138 | } 139 | 140 | static void 141 | ev_x_cb (struct event *ev, int revents) 142 | { 143 | revents &= EV_READ | EV_WRITE | EV_TIMER | EV_SIGNAL; 144 | 145 | ev->ev_res = revents; 146 | ev->ev_callback (ev->ev_fd, (short)revents, ev->ev_arg); 147 | } 148 | 149 | static void 150 | ev_x_cb_sig (EV_P_ struct ev_signal *w, int revents) 151 | { 152 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.sig)); 153 | 154 | if (revents & EV_ERROR) 155 | event_del (ev); 156 | 157 | ev_x_cb (ev, revents); 158 | } 159 | 160 | static void 161 | ev_x_cb_io (EV_P_ struct ev_io *w, int revents) 162 | { 163 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io)); 164 | 165 | if ((revents & EV_ERROR) || !(ev->ev_events & EV_PERSIST)) 166 | event_del (ev); 167 | 168 | ev_x_cb (ev, revents); 169 | } 170 | 171 | static void 172 | ev_x_cb_to (EV_P_ struct ev_timer *w, int revents) 173 | { 174 | struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, to)); 175 | 176 | event_del (ev); 177 | 178 | ev_x_cb (ev, revents); 179 | } 180 | 181 | void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg) 182 | { 183 | if (events & EV_SIGNAL) 184 | ev_init (&ev->iosig.sig, ev_x_cb_sig); 185 | else 186 | ev_init (&ev->iosig.io, ev_x_cb_io); 187 | 188 | ev_init (&ev->to, ev_x_cb_to); 189 | 190 | ev->ev_base = ev_x_cur; /* not threadsafe, but it's how libevent works */ 191 | ev->ev_fd = fd; 192 | ev->ev_events = events; 193 | ev->ev_pri = 0; 194 | ev->ev_callback = cb; 195 | ev->ev_arg = arg; 196 | ev->ev_res = 0; 197 | ev->ev_flags = EVLIST_INIT; 198 | } 199 | 200 | int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) 201 | { 202 | return event_base_once (ev_x_cur, fd, events, cb, arg, tv); 203 | } 204 | 205 | int event_add (struct event *ev, struct timeval *tv) 206 | { 207 | dLOOPev; 208 | 209 | if (ev->ev_events & EV_SIGNAL) 210 | { 211 | if (!ev_is_active (&ev->iosig.sig)) 212 | { 213 | ev_signal_set (&ev->iosig.sig, ev->ev_fd); 214 | ev_signal_start (EV_A_ &ev->iosig.sig); 215 | 216 | ev->ev_flags |= EVLIST_SIGNAL; 217 | } 218 | } 219 | else if (ev->ev_events & (EV_READ | EV_WRITE)) 220 | { 221 | if (!ev_is_active (&ev->iosig.io)) 222 | { 223 | ev_io_set (&ev->iosig.io, ev->ev_fd, ev->ev_events & (EV_READ | EV_WRITE)); 224 | ev_io_start (EV_A_ &ev->iosig.io); 225 | 226 | ev->ev_flags |= EVLIST_INSERTED; 227 | } 228 | } 229 | 230 | if (tv) 231 | { 232 | ev->to.repeat = ev_tv_get (tv); 233 | ev_timer_again (EV_A_ &ev->to); 234 | ev->ev_flags |= EVLIST_TIMEOUT; 235 | } 236 | else 237 | { 238 | ev_timer_stop (EV_A_ &ev->to); 239 | ev->ev_flags &= ~EVLIST_TIMEOUT; 240 | } 241 | 242 | ev->ev_flags |= EVLIST_ACTIVE; 243 | 244 | return 0; 245 | } 246 | 247 | int event_del (struct event *ev) 248 | { 249 | dLOOPev; 250 | 251 | if (ev->ev_events & EV_SIGNAL) 252 | ev_signal_stop (EV_A_ &ev->iosig.sig); 253 | else if (ev->ev_events & (EV_READ | EV_WRITE)) 254 | ev_io_stop (EV_A_ &ev->iosig.io); 255 | 256 | if (ev_is_active (&ev->to)) 257 | ev_timer_stop (EV_A_ &ev->to); 258 | 259 | ev->ev_flags = EVLIST_INIT; 260 | 261 | return 0; 262 | } 263 | 264 | void event_active (struct event *ev, int res, short ncalls) 265 | { 266 | dLOOPev; 267 | 268 | if (res & EV_TIMEOUT) 269 | ev_feed_event (EV_A_ &ev->to, res & EV_TIMEOUT); 270 | 271 | if (res & EV_SIGNAL) 272 | ev_feed_event (EV_A_ &ev->iosig.sig, res & EV_SIGNAL); 273 | 274 | if (res & (EV_READ | EV_WRITE)) 275 | ev_feed_event (EV_A_ &ev->iosig.io, res & (EV_READ | EV_WRITE)); 276 | } 277 | 278 | int event_pending (struct event *ev, short events, struct timeval *tv) 279 | { 280 | short revents = 0; 281 | dLOOPev; 282 | 283 | if (ev->ev_events & EV_SIGNAL) 284 | { 285 | /* sig */ 286 | if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) 287 | revents |= EV_SIGNAL; 288 | } 289 | else if (ev->ev_events & (EV_READ | EV_WRITE)) 290 | { 291 | /* io */ 292 | if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io)) 293 | revents |= ev->ev_events & (EV_READ | EV_WRITE); 294 | } 295 | 296 | if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to)) 297 | { 298 | revents |= EV_TIMEOUT; 299 | 300 | if (tv) 301 | { 302 | ev_tstamp at = ev_now (EV_A); 303 | 304 | tv->tv_sec = (long)at; 305 | tv->tv_usec = (long)((at - (ev_tstamp)tv->tv_sec) * 1e6); 306 | } 307 | } 308 | 309 | return events & revents; 310 | } 311 | 312 | int event_priority_init (int npri) 313 | { 314 | return event_base_priority_init (ev_x_cur, npri); 315 | } 316 | 317 | int event_priority_set (struct event *ev, int pri) 318 | { 319 | ev->ev_pri = pri; 320 | 321 | return 0; 322 | } 323 | 324 | int event_base_set (struct event_base *base, struct event *ev) 325 | { 326 | ev->ev_base = base; 327 | 328 | return 0; 329 | } 330 | 331 | int event_base_loop (struct event_base *base, int flags) 332 | { 333 | dLOOPbase; 334 | 335 | ev_run (EV_A_ flags); 336 | 337 | return 0; 338 | } 339 | 340 | int event_base_dispatch (struct event_base *base) 341 | { 342 | return event_base_loop (base, 0); 343 | } 344 | 345 | static void 346 | ev_x_loopexit_cb (int revents, void *base) 347 | { 348 | dLOOPbase; 349 | 350 | ev_break (EV_A_ EVBREAK_ONE); 351 | } 352 | 353 | int event_base_loopexit (struct event_base *base, struct timeval *tv) 354 | { 355 | ev_tstamp after = ev_tv_get (tv); 356 | dLOOPbase; 357 | 358 | ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., ev_x_loopexit_cb, (void *)base); 359 | 360 | return 0; 361 | } 362 | 363 | struct ev_x_once 364 | { 365 | int fd; 366 | void (*cb)(int, short, void *); 367 | void *arg; 368 | }; 369 | 370 | static void 371 | ev_x_once_cb (int revents, void *arg) 372 | { 373 | struct ev_x_once *once = (struct ev_x_once *)arg; 374 | 375 | once->cb (once->fd, (short)revents, once->arg); 376 | free (once); 377 | } 378 | 379 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) 380 | { 381 | struct ev_x_once *once = (struct ev_x_once *)malloc (sizeof (struct ev_x_once)); 382 | dLOOPbase; 383 | 384 | if (!once) 385 | return -1; 386 | 387 | once->fd = fd; 388 | once->cb = cb; 389 | once->arg = arg; 390 | 391 | ev_once (EV_A_ fd, events & (EV_READ | EV_WRITE), ev_tv_get (tv), ev_x_once_cb, (void *)once); 392 | 393 | return 0; 394 | } 395 | 396 | int event_base_priority_init (struct event_base *base, int npri) 397 | { 398 | /*dLOOPbase;*/ 399 | 400 | return 0; 401 | } 402 | 403 | -------------------------------------------------------------------------------- /ShadowWeb/libev/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libevent compatibility header, only core events supported 3 | * 4 | * Copyright (c) 2007,2008,2010 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #ifndef EVENT_H_ 41 | #define EVENT_H_ 42 | 43 | #ifdef EV_H 44 | # include EV_H 45 | #else 46 | # include "ev.h" 47 | #endif 48 | 49 | #ifndef EVLOOP_NONBLOCK 50 | # define EVLOOP_NONBLOCK EVRUN_NOWAIT 51 | #endif 52 | #ifndef EVLOOP_ONESHOT 53 | # define EVLOOP_ONESHOT EVRUN_ONCE 54 | #endif 55 | #ifndef EV_TIMEOUT 56 | # define EV_TIMEOUT EV_TIMER 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | extern "C" { 61 | #endif 62 | 63 | /* we need sys/time.h for struct timeval only */ 64 | #if !defined (WIN32) || defined (__MINGW32__) 65 | # include /* mingw seems to need this, for whatever reason */ 66 | # include 67 | #endif 68 | 69 | struct event_base; 70 | 71 | #define EVLIST_TIMEOUT 0x01 72 | #define EVLIST_INSERTED 0x02 73 | #define EVLIST_SIGNAL 0x04 74 | #define EVLIST_ACTIVE 0x08 75 | #define EVLIST_INTERNAL 0x10 76 | #define EVLIST_INIT 0x80 77 | 78 | struct event 79 | { 80 | /* libev watchers we map onto */ 81 | union { 82 | struct ev_io io; 83 | struct ev_signal sig; 84 | } iosig; 85 | struct ev_timer to; 86 | 87 | /* compatibility slots */ 88 | struct event_base *ev_base; 89 | void (*ev_callback)(int, short, void *arg); 90 | void *ev_arg; 91 | int ev_fd; 92 | int ev_pri; 93 | int ev_res; 94 | int ev_flags; 95 | short ev_events; 96 | }; 97 | 98 | #define EV_READ EV_READ 99 | #define EV_WRITE EV_WRITE 100 | #define EV_PERSIST 0x10 101 | 102 | #define EVENT_SIGNAL(ev) ((int) (ev)->ev_fd) 103 | #define EVENT_FD(ev) ((int) (ev)->ev_fd) 104 | 105 | #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) 106 | 107 | #define evtimer_add(ev,tv) event_add (ev, tv) 108 | #define evtimer_set(ev,cb,data) event_set (ev, -1, 0, cb, data) 109 | #define evtimer_del(ev) event_del (ev) 110 | #define evtimer_pending(ev,tv) event_pending (ev, EV_TIMEOUT, tv) 111 | #define evtimer_initialized(ev) event_initialized (ev) 112 | 113 | #define timeout_add(ev,tv) evtimer_add (ev, tv) 114 | #define timeout_set(ev,cb,data) evtimer_set (ev, cb, data) 115 | #define timeout_del(ev) evtimer_del (ev) 116 | #define timeout_pending(ev,tv) evtimer_pending (ev, tv) 117 | #define timeout_initialized(ev) evtimer_initialized (ev) 118 | 119 | #define signal_add(ev,tv) event_add (ev, tv) 120 | #define signal_set(ev,sig,cb,data) event_set (ev, sig, EV_SIGNAL | EV_PERSIST, cb, data) 121 | #define signal_del(ev) event_del (ev) 122 | #define signal_pending(ev,tv) event_pending (ev, EV_SIGNAL, tv) 123 | #define signal_initialized(ev) event_initialized (ev) 124 | 125 | const char *event_get_version (void); 126 | const char *event_get_method (void); 127 | 128 | void *event_init (void); 129 | void event_base_free (struct event_base *base); 130 | 131 | #define EVLOOP_ONCE EVLOOP_ONESHOT 132 | int event_loop (int); 133 | int event_loopexit (struct timeval *tv); 134 | int event_dispatch (void); 135 | 136 | #define _EVENT_LOG_DEBUG 0 137 | #define _EVENT_LOG_MSG 1 138 | #define _EVENT_LOG_WARN 2 139 | #define _EVENT_LOG_ERR 3 140 | typedef void (*event_log_cb)(int severity, const char *msg); 141 | void event_set_log_callback(event_log_cb cb); 142 | 143 | void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg); 144 | int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv); 145 | 146 | int event_add (struct event *ev, struct timeval *tv); 147 | int event_del (struct event *ev); 148 | void event_active (struct event *ev, int res, short ncalls); /* ncalls is being ignored */ 149 | 150 | int event_pending (struct event *ev, short, struct timeval *tv); 151 | 152 | int event_priority_init (int npri); 153 | int event_priority_set (struct event *ev, int pri); 154 | 155 | int event_base_set (struct event_base *base, struct event *ev); 156 | int event_base_loop (struct event_base *base, int); 157 | int event_base_loopexit (struct event_base *base, struct timeval *tv); 158 | int event_base_dispatch (struct event_base *base); 159 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv); 160 | int event_base_priority_init (struct event_base *base, int fd); 161 | 162 | /* next line is different in the libevent+libev version */ 163 | /*libevent-include*/ 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif 170 | 171 | -------------------------------------------------------------------------------- /ShadowWeb/local.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "libev/ev.h" 5 | #include "encrypt.h" 6 | 7 | #define BUF_SIZE 1500 8 | 9 | struct listen_ctx { 10 | ev_io io; 11 | int fd; 12 | struct sockaddr sock; 13 | }; 14 | 15 | struct server { 16 | int fd; 17 | char buf[BUF_SIZE + EVP_MAX_IV_LENGTH + EVP_MAX_BLOCK_LENGTH]; // server send from, remote recv into 18 | char stage; 19 | size_t buf_len; 20 | struct server_ctx *recv_ctx; 21 | struct server_ctx *send_ctx; 22 | struct remote *remote; 23 | }; 24 | struct server_ctx { 25 | ev_io io; 26 | int connected; 27 | struct server *server; 28 | }; 29 | struct remote { 30 | int fd; 31 | char buf[BUF_SIZE + EVP_MAX_IV_LENGTH + EVP_MAX_BLOCK_LENGTH]; // remote send from, server recv into 32 | size_t buf_len; 33 | struct remote_ctx *recv_ctx; 34 | struct remote_ctx *send_ctx; 35 | struct server *server; 36 | struct encryption_ctx recv_encryption_ctx; 37 | struct encryption_ctx send_encryption_ctx; 38 | }; 39 | struct remote_ctx { 40 | ev_io io; 41 | int connected; 42 | struct remote *remote; 43 | }; 44 | 45 | 46 | static void accept_cb (EV_P_ ev_io *w, int revents); 47 | static void server_recv_cb (EV_P_ ev_io *w, int revents); 48 | static void server_send_cb (EV_P_ ev_io *w, int revents); 49 | static void remote_recv_cb (EV_P_ ev_io *w, int revents); 50 | static void remote_send_cb (EV_P_ ev_io *w, int revents); 51 | struct remote* new_remote(int fd); 52 | void free_remote(struct remote *remote); 53 | void close_and_free_remote(EV_P_ struct remote *remote); 54 | struct server* new_server(int fd); 55 | void free_server(struct server *server); 56 | void close_and_free_server(EV_P_ struct server *server); 57 | void set_config(const char *server, const char *remote_port, const char* password, const char* method); 58 | int local_main(); 59 | 60 | -------------------------------------------------------------------------------- /ShadowWeb/socks5.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define SOCKS_VERSION 0x05 4 | #define SOCKS_CMD_CONNECT 0x01 5 | #define SOCKS_IPV4 0x01 6 | #define SOCKS_DOMAIN 0x03 7 | #define SOCKS_IPV6 0x04 8 | #define SOCKS_CMD_NOT_SUPPORTED 0x07 9 | 10 | #pragma pack(1) 11 | 12 | struct method_select_request 13 | { 14 | char ver; 15 | char nmethods; 16 | char methods[255]; 17 | }; 18 | 19 | struct method_select_response 20 | { 21 | char ver; 22 | char method; 23 | }; 24 | 25 | struct socks5_request 26 | { 27 | char ver; 28 | char cmd; 29 | char rsv; 30 | char atyp; 31 | }; 32 | 33 | struct socks5_response 34 | { 35 | char ver; 36 | char rep; 37 | char rsv; 38 | char atyp; 39 | }; 40 | 41 | #pragma pack() 42 | 43 | -------------------------------------------------------------------------------- /ShadowWeb/table.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | unsigned char encrypt_table[256]; 5 | unsigned char decrypt_table[256]; 6 | void get_table(const unsigned char* key); 7 | void table_encrypt(unsigned char *buf, size_t len); 8 | void table_decrypt(unsigned char *buf, size_t len); 9 | 10 | unsigned int _i; 11 | unsigned long long _a; 12 | -------------------------------------------------------------------------------- /ShadowWeb/table.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #include "table.h" 5 | 6 | 7 | static int random_compare(const void *_x, const void *_y) { 8 | uint32_t i = _i; 9 | uint64_t a = _a; 10 | uint8_t x = *((uint8_t *) _x); 11 | uint8_t y = *((uint8_t*) _y); 12 | return (a % (x + i) - a % (y + i)); 13 | } 14 | 15 | 16 | static void merge(uint8_t *left, int llength, uint8_t *right, int rlength) 17 | { 18 | /* Temporary memory locations for the 2 segments of the array to merge. */ 19 | uint8_t *ltmp = (uint8_t *) malloc(llength * sizeof(uint8_t)); 20 | uint8_t *rtmp = (uint8_t *) malloc(rlength * sizeof(uint8_t)); 21 | 22 | /* 23 | * Pointers to the elements being sorted in the temporary memory locations. 24 | */ 25 | uint8_t *ll = ltmp; 26 | uint8_t *rr = rtmp; 27 | 28 | uint8_t *result = left; 29 | 30 | /* 31 | * Copy the segment of the array to be merged into the temporary memory 32 | * locations. 33 | */ 34 | memcpy(ltmp, left, llength * sizeof(uint8_t)); 35 | memcpy(rtmp, right, rlength * sizeof(uint8_t)); 36 | 37 | while (llength > 0 && rlength > 0) { 38 | if (random_compare(ll, rr) <= 0) { 39 | /* 40 | * Merge the first element from the left back into the main array 41 | * if it is smaller or equal to the one on the right. 42 | */ 43 | *result = *ll; 44 | ++ll; 45 | --llength; 46 | } else { 47 | /* 48 | * Merge the first element from the right back into the main array 49 | * if it is smaller than the one on the left. 50 | */ 51 | *result = *rr; 52 | ++rr; 53 | --rlength; 54 | } 55 | ++result; 56 | } 57 | /* 58 | * All the elements from either the left or the right temporary array 59 | * segment have been merged back into the main array. Append the remaining 60 | * elements from the other temporary array back into the main array. 61 | */ 62 | if (llength > 0) 63 | while (llength > 0) { 64 | /* Appending the rest of the left temporary array. */ 65 | *result = *ll; 66 | ++result; 67 | ++ll; 68 | --llength; 69 | } 70 | else 71 | while (rlength > 0) { 72 | /* Appending the rest of the right temporary array. */ 73 | *result = *rr; 74 | ++result; 75 | ++rr; 76 | --rlength; 77 | } 78 | 79 | /* Release the memory used for the temporary arrays. */ 80 | free(ltmp); 81 | free(rtmp); 82 | } 83 | 84 | static void merge_sort(uint8_t array[], uint32_t length) 85 | { 86 | /* This is the middle index and also the length of the right array. */ 87 | uint8_t middle; 88 | 89 | /* 90 | * Pointers to the beginning of the left and right segment of the array 91 | * to be merged. 92 | */ 93 | uint8_t *left, *right; 94 | 95 | /* Length of the left segment of the array to be merged. */ 96 | uint32_t llength; 97 | 98 | if (length <= 1) 99 | return; 100 | 101 | /* Let integer division truncate the value. */ 102 | middle = (uint8_t)(length / 2); 103 | 104 | llength = length - middle; 105 | 106 | /* 107 | * Set the pointers to the appropriate segments of the array to be merged. 108 | */ 109 | left = array; 110 | right = array + llength; 111 | 112 | merge_sort(left, llength); 113 | merge_sort(right, middle); 114 | merge(left, llength, right, middle); 115 | } 116 | 117 | void table_encrypt(unsigned char *buf, size_t len) { 118 | unsigned char *end = buf + len; 119 | while (buf < end) { 120 | *buf = encrypt_table[*buf]; 121 | buf++; 122 | } 123 | } 124 | 125 | void table_decrypt(unsigned char *buf, size_t len) { 126 | unsigned char *end = buf + len; 127 | while (buf < end) { 128 | *buf = decrypt_table[*buf]; 129 | buf++; 130 | } 131 | } 132 | 133 | void get_table(const unsigned char* key) { 134 | unsigned char *table = encrypt_table; 135 | unsigned char tmp_hash[16]; 136 | // tmp_hash = MD5((const unsigned char*)key, strlen(key), NULL); 137 | MD5(key, strlen((const char *)key), tmp_hash); 138 | _a = *(unsigned long long *)tmp_hash; 139 | _a = *(uint64_t *)tmp_hash; 140 | uint32_t i; 141 | 142 | for(i = 0; i < 256; ++i) { 143 | table[i] = (unsigned char)i; 144 | } 145 | for(i = 1; i < 1024; ++i) { 146 | _i = i; 147 | merge_sort(table, 256); 148 | } 149 | for(i = 0; i < 256; ++i) { 150 | // gen decrypt table from encrypt table 151 | decrypt_table[encrypt_table[i]] = (unsigned char)i; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /ShadowWeb/zh-Hans.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ShadowWeb/zh-Hans.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | /* 2 | Localizable.strings 3 | ShadowWeb 4 | 5 | Created by clowwindy on 6/17/13. 6 | Copyright (c) 2013 clowwindy. All rights reserved. 7 | */ 8 | 9 | "Saved" = "已保存"; 10 | "Proxy Settings" = "代理设置"; 11 | "Encryption Method" = "加密方式"; 12 | "Enable/Disable APN" = "启动/停止 APN"; 13 | "IP" = "IP"; 14 | "Port" = "端口"; 15 | "Password" = "密码"; 16 | "Enable Unicom" = "打开联通"; 17 | "Disable Unicom" = "禁用联通"; 18 | "incorrect URL" = "错误的 URL"; 19 | "OK" = "确定"; 20 | "Cancel" = "取消"; 21 | "Yes" = "是"; 22 | "No" = "否"; 23 | "New Tab" = "新标签页"; 24 | "Close" = "关闭"; 25 | "Back" = "后退"; 26 | "Forward" = "前进"; 27 | "Reload" = "刷新"; 28 | "Settings" = "选项"; 29 | "Loading" = "载入中"; 30 | "Untitled" = "无标题"; 31 | "Method" = "加密方法"; 32 | "Proxy Mode" = "代理模式"; 33 | "Help" = "帮助"; 34 | "About" = "关于"; 35 | "Version" = "版本"; 36 | "Visit Website" = "访问主页"; 37 | "Rate This App" = "给我打分"; 38 | "Server" = "服务器"; 39 | "Public" = "热心网友提供"; 40 | "Custom" = "自定义"; 41 | "Config via QRCode" = "用二维码配置"; 42 | "Use this server?" = "使用这个服务器?"; 43 | "Invalid Shadowsocks URL" = "无效的 Shadowsocks URL"; 44 | "Shadowsocks: On" = "Shadowsocks: 打开"; 45 | "Shadowsocks: Off" = "Shadowsocks: 关闭"; 46 | "Turn Shadowsocks On" = "打开 Shadowsocks"; 47 | "Turn Shadowsocks Off" = "关闭 Shadowsocks"; 48 | "Auto Proxy Mode" = "自动代理模式"; 49 | "Global Mode" = "全局模式"; 50 | "Public Server" = "公共服务器"; 51 | "Servers" = "服务器"; 52 | "Open Server Preferences..." = "打开服务器设定..."; 53 | "Please fill in the blanks." = "请填写以下内容。"; 54 | "Show Logs..." = "显示日志..."; 55 | "Edit PAC for Auto Proxy Mode..." = "编辑自动模式的 PAC"; 56 | "Edit User Rule for GFWList..." = "编辑 GFWList 的用户规则"; 57 | "Quit" = "退出"; 58 | "https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help" = "https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-%E5%B8%AE%E5%8A%A9"; 59 | "Show QR Code..." = "显示二维码..."; 60 | "Generate QR Code..." = "生成二维码"; 61 | "Scan QR Code from Screen..." = "扫描二维码"; 62 | "Update PAC from GFWList" = "从 GFWList 更新 PAC"; 63 | "Invalid QR Code" = "无效的二维码"; 64 | "No QR Code Found" = "没有找到二维码"; 65 | -------------------------------------------------------------------------------- /ShadowsocksX/Application.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1070 5 | 13B3116 6 | 4514 7 | 1265 8 | 696.00 9 | 10 | com.apple.InterfaceBuilder.CocoaPlugin 11 | 4514 12 | 13 | 14 | NSCustomObject 15 | 16 | 17 | com.apple.InterfaceBuilder.CocoaPlugin 18 | 19 | 20 | PluginDependencyRecalculationVersion 21 | 22 | 23 | 24 | 25 | NSApplication 26 | 27 | 28 | FirstResponder 29 | 30 | 31 | NSApplication 32 | 33 | 34 | NSFontManager 35 | 36 | 37 | SWBAppDelegate 38 | 39 | 40 | 41 | 42 | 43 | 44 | delegate 45 | 46 | 47 | 48 | 823 49 | 50 | 51 | 52 | delegate 53 | 54 | 55 | 56 | 830 57 | 58 | 59 | 60 | 61 | 62 | 0 63 | 64 | 65 | 66 | 67 | 68 | -2 69 | 70 | 71 | File's Owner 72 | 73 | 74 | -1 75 | 76 | 77 | First Responder 78 | 79 | 80 | -3 81 | 82 | 83 | Application 84 | 85 | 86 | 373 87 | 88 | 89 | 90 | 91 | 828 92 | 93 | 94 | 95 | 96 | 97 | 98 | com.apple.InterfaceBuilder.CocoaPlugin 99 | com.apple.InterfaceBuilder.CocoaPlugin 100 | com.apple.InterfaceBuilder.CocoaPlugin 101 | com.apple.InterfaceBuilder.CocoaPlugin 102 | com.apple.InterfaceBuilder.CocoaPlugin 103 | 104 | 105 | 106 | 107 | 108 | 970 109 | 110 | 111 | 112 | 113 | SWBAppDelegate 114 | NSObject 115 | 116 | window 117 | UIWindow 118 | 119 | 120 | window 121 | 122 | window 123 | UIWindow 124 | 125 | 126 | 127 | IBProjectSource 128 | ./Classes/SWBAppDelegate.h 129 | 130 | 131 | 132 | UIResponder 133 | NSObject 134 | 135 | IBProjectSource 136 | ./Classes/UIResponder.h 137 | 138 | 139 | 140 | UIView 141 | UIResponder 142 | 143 | IBProjectSource 144 | ./Classes/UIView.h 145 | 146 | 147 | 148 | UIWindow 149 | UIView 150 | 151 | IBProjectSource 152 | ./Classes/UIWindow.h 153 | 154 | 155 | 156 | 157 | 0 158 | IBCocoaFramework 159 | YES 160 | 161 | com.apple.InterfaceBuilder.CocoaPlugin.macosx 162 | 163 | 164 | 165 | com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 166 | 167 | 168 | YES 169 | 3 170 | YES 171 | 172 | 173 | -------------------------------------------------------------------------------- /ShadowsocksX/Configuration.h: -------------------------------------------------------------------------------- 1 | // Generated by json_to_model 2 | 3 | #import 4 | #import "Profile.h" 5 | 6 | 7 | @interface Configuration : NSObject 8 | 9 | - (id)initWithJSONData:(NSData *)data; 10 | - (id)initWithJSONDictionary:(NSDictionary *)dictionary; 11 | - (NSDictionary *)JSONDictionary; 12 | - (NSData *)JSONData; 13 | 14 | 15 | @property (nonatomic, assign) NSInteger current; 16 | 17 | @property (nonatomic, strong) NSArray * profiles; 18 | 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /ShadowsocksX/Configuration.m: -------------------------------------------------------------------------------- 1 | // Generated by json_to_model 2 | 3 | #import "Configuration.h" 4 | 5 | @implementation Configuration { 6 | 7 | } 8 | 9 | - (id)initWithJSONDictionary:(NSDictionary *)dictionary { 10 | 11 | self = [super init]; 12 | if (![dictionary isKindOfClass:[NSDictionary class]]) 13 | return nil; 14 | 15 | if (self) { 16 | 17 | self.current = (dictionary[@"current"] != [NSNull null]) ? [dictionary[@"current"] integerValue] : 0; 18 | 19 | self.profiles = [[NSMutableArray alloc] initWithCapacity:16]; 20 | for (NSDictionary *_ in dictionary[@"profiles"]) { 21 | 22 | [((NSMutableArray *)self.profiles) addObject:[[Profile alloc] initWithJSONDictionary:_]]; 23 | 24 | } 25 | 26 | } 27 | return self; 28 | } 29 | 30 | - (id)initWithJSONData:(NSData *)data { 31 | self = [super init]; 32 | if (self) { 33 | NSError *error = nil; 34 | id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; 35 | if (result) { 36 | self = [self initWithJSONDictionary:result]; 37 | } else { 38 | return nil; 39 | } 40 | } 41 | return self; 42 | } 43 | 44 | - (NSDictionary *)JSONDictionary { 45 | 46 | NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; 47 | 48 | 49 | dictionary[@"current"] = @(self.current); 50 | 51 | { 52 | NSMutableArray *_ = [[NSMutableArray alloc] init]; 53 | dictionary[@"profiles"] = _; 54 | 55 | for (Profile *__ in self.profiles) { 56 | 57 | [_ addObject:[__ JSONDictionary]]; 58 | 59 | } 60 | 61 | } 62 | 63 | return dictionary; 64 | } 65 | 66 | 67 | - (NSData *)JSONData { 68 | NSError *error = nil; 69 | NSData *data = [NSJSONSerialization dataWithJSONObject:[self JSONDictionary] options:0 error:&error]; 70 | if (error) { 71 | @throw error; 72 | } 73 | return data; 74 | } 75 | 76 | 77 | @end -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/114.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/120.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/144.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/57.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/72.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon-2.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "3x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "3x" 27 | }, 28 | { 29 | "size" : "57x57", 30 | "idiom" : "iphone", 31 | "filename" : "57.png", 32 | "scale" : "1x" 33 | }, 34 | { 35 | "size" : "57x57", 36 | "idiom" : "iphone", 37 | "filename" : "114.png", 38 | "scale" : "2x" 39 | }, 40 | { 41 | "size" : "60x60", 42 | "idiom" : "iphone", 43 | "filename" : "120.png", 44 | "scale" : "2x" 45 | }, 46 | { 47 | "idiom" : "iphone", 48 | "size" : "60x60", 49 | "scale" : "3x" 50 | }, 51 | { 52 | "idiom" : "ipad", 53 | "size" : "29x29", 54 | "scale" : "1x" 55 | }, 56 | { 57 | "idiom" : "ipad", 58 | "size" : "29x29", 59 | "scale" : "2x" 60 | }, 61 | { 62 | "idiom" : "ipad", 63 | "size" : "40x40", 64 | "scale" : "1x" 65 | }, 66 | { 67 | "idiom" : "ipad", 68 | "size" : "40x40", 69 | "scale" : "2x" 70 | }, 71 | { 72 | "idiom" : "ipad", 73 | "size" : "50x50", 74 | "scale" : "1x" 75 | }, 76 | { 77 | "idiom" : "ipad", 78 | "size" : "50x50", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "72x72", 83 | "idiom" : "ipad", 84 | "filename" : "72.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "72x72", 89 | "idiom" : "ipad", 90 | "filename" : "144.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "idiom" : "ipad", 95 | "size" : "76x76", 96 | "scale" : "1x" 97 | }, 98 | { 99 | "idiom" : "ipad", 100 | "size" : "76x76", 101 | "scale" : "2x" 102 | }, 103 | { 104 | "idiom" : "ipad", 105 | "size" : "83.5x83.5", 106 | "scale" : "2x" 107 | } 108 | ], 109 | "info" : { 110 | "version" : 1, 111 | "author" : "xcode" 112 | } 113 | } -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "icon_16x16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "icon_16x16@2x.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "icon_32x32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "icon_32x32@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "icon_128x128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "icon_128x128@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "icon_256x256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "icon_256x256@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "icon_512x512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "icon_512x512@2x.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_128x128.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_128x128@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_128x128@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_16x16.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_16x16@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_16x16@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_256x256.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_256x256@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_256x256@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_32x32.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_32x32@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_32x32@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_512x512.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_512x512@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/Images.xcassets/AppIcon.appiconset/icon_512x512@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "ipad", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "1x" 9 | }, 10 | { 11 | "orientation" : "landscape", 12 | "idiom" : "ipad", 13 | "extent" : "full-screen", 14 | "minimum-system-version" : "7.0", 15 | "scale" : "1x" 16 | }, 17 | { 18 | "orientation" : "portrait", 19 | "idiom" : "ipad", 20 | "extent" : "full-screen", 21 | "minimum-system-version" : "7.0", 22 | "scale" : "2x" 23 | }, 24 | { 25 | "orientation" : "landscape", 26 | "idiom" : "ipad", 27 | "extent" : "full-screen", 28 | "minimum-system-version" : "7.0", 29 | "scale" : "2x" 30 | }, 31 | { 32 | "orientation" : "portrait", 33 | "idiom" : "ipad", 34 | "extent" : "to-status-bar", 35 | "scale" : "1x" 36 | }, 37 | { 38 | "orientation" : "landscape", 39 | "idiom" : "ipad", 40 | "extent" : "to-status-bar", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "orientation" : "portrait", 45 | "idiom" : "ipad", 46 | "extent" : "to-status-bar", 47 | "scale" : "2x" 48 | }, 49 | { 50 | "orientation" : "landscape", 51 | "idiom" : "ipad", 52 | "extent" : "to-status-bar", 53 | "scale" : "2x" 54 | } 55 | ], 56 | "info" : { 57 | "version" : 1, 58 | "author" : "xcode" 59 | } 60 | } -------------------------------------------------------------------------------- /ShadowsocksX/Profile.h: -------------------------------------------------------------------------------- 1 | // Generated by json_to_model 2 | 3 | #import 4 | 5 | 6 | @interface Profile : NSObject 7 | 8 | - (id)initWithJSONData:(NSData *)data; 9 | - (id)initWithJSONDictionary:(NSDictionary *)dictionary; 10 | - (NSDictionary *)JSONDictionary; 11 | - (NSData *)JSONData; 12 | 13 | 14 | @property (nonatomic, copy) NSString * server; 15 | 16 | @property (nonatomic, assign) NSInteger serverPort; 17 | 18 | @property (nonatomic, copy) NSString * remarks; 19 | 20 | @property (nonatomic, copy) NSString * password; 21 | 22 | @property (nonatomic, copy) NSString * method; 23 | 24 | 25 | @end 26 | 27 | -------------------------------------------------------------------------------- /ShadowsocksX/Profile.m: -------------------------------------------------------------------------------- 1 | // Generated by json_to_model 2 | 3 | #import "Profile.h" 4 | 5 | @implementation Profile { 6 | 7 | } 8 | 9 | - (id)initWithJSONDictionary:(NSDictionary *)dictionary { 10 | 11 | self = [super init]; 12 | if (![dictionary isKindOfClass:[NSDictionary class]]) 13 | return nil; 14 | 15 | if (self) { 16 | 17 | self.server = (dictionary[@"server"] != [NSNull null]) ? dictionary[@"server"] : nil; 18 | 19 | self.serverPort = (dictionary[@"server_port"] != [NSNull null]) ? [dictionary[@"server_port"] integerValue] : 0; 20 | 21 | self.remarks = (dictionary[@"remarks"] != [NSNull null]) ? dictionary[@"remarks"] : nil; 22 | 23 | self.password = (dictionary[@"password"] != [NSNull null]) ? dictionary[@"password"] : nil; 24 | 25 | self.method = (dictionary[@"method"] != [NSNull null]) ? dictionary[@"method"] : nil; 26 | 27 | } 28 | return self; 29 | } 30 | 31 | - (id)initWithJSONData:(NSData *)data { 32 | self = [super init]; 33 | if (self) { 34 | NSError *error = nil; 35 | id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; 36 | if (result) { 37 | self = [self initWithJSONDictionary:result]; 38 | } else { 39 | return nil; 40 | } 41 | } 42 | return self; 43 | } 44 | 45 | - (NSDictionary *)JSONDictionary { 46 | 47 | NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; 48 | 49 | 50 | dictionary[@"server"] = (self.server != nil) ? self.server : [NSNull null]; 51 | 52 | dictionary[@"server_port"] = @(self.serverPort); 53 | 54 | dictionary[@"remarks"] = (self.remarks != nil) ? self.remarks : [NSNull null]; 55 | 56 | dictionary[@"password"] = (self.password != nil) ? self.password : [NSNull null]; 57 | 58 | dictionary[@"method"] = (self.method != nil) ? self.method : [NSNull null]; 59 | 60 | return dictionary; 61 | } 62 | 63 | 64 | - (NSData *)JSONData { 65 | NSError *error = nil; 66 | NSData *data = [NSJSONSerialization dataWithJSONObject:[self JSONDictionary] options:0 error:&error]; 67 | if (error) { 68 | @throw error; 69 | } 70 | return data; 71 | } 72 | 73 | 74 | @end -------------------------------------------------------------------------------- /ShadowsocksX/ProfileManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 11/3/14. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import 7 | #import "Configuration.h" 8 | 9 | @interface ProfileManager : NSObject 10 | 11 | + (Configuration *)configuration; 12 | + (void)saveConfiguration:(Configuration *)configuration; 13 | + (void)reloadShadowsocksRunner; 14 | 15 | @end -------------------------------------------------------------------------------- /ShadowsocksX/ProfileManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 11/3/14. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import "ProfileManager.h" 7 | #import "ShadowsocksRunner.h" 8 | 9 | #define CONFIG_DATA_KEY @"config" 10 | 11 | @implementation ProfileManager { 12 | 13 | } 14 | 15 | + (Configuration *)configuration { 16 | NSData *data = [[NSUserDefaults standardUserDefaults] dataForKey:CONFIG_DATA_KEY]; 17 | Configuration *configuration; 18 | if (data == nil) { 19 | // upgrade data from old version 20 | configuration = [[Configuration alloc] init]; 21 | configuration.profiles = [[NSMutableArray alloc] initWithCapacity:16]; 22 | if ([ShadowsocksRunner isUsingPublicServer]) { 23 | configuration.current = -1; 24 | } else { 25 | configuration.current = 0; 26 | Profile *profile = [[Profile alloc] init]; 27 | profile.server = [ShadowsocksRunner configForKey:kShadowsocksIPKey]; 28 | profile.serverPort = [[ShadowsocksRunner configForKey:kShadowsocksPortKey] integerValue]; 29 | profile.password = [ShadowsocksRunner configForKey:kShadowsocksPasswordKey]; 30 | profile.method = [ShadowsocksRunner configForKey:kShadowsocksEncryptionKey]; 31 | [((NSMutableArray *)configuration.profiles) addObject:profile]; 32 | } 33 | return configuration; 34 | } 35 | if (data == nil) { 36 | // load default configuration 37 | configuration = [[Configuration alloc] init]; 38 | // public server 39 | configuration.current = -1; 40 | configuration.profiles = [[NSMutableArray alloc] initWithCapacity:16]; 41 | } else { 42 | configuration = [[Configuration alloc] initWithJSONData:data]; 43 | } 44 | return configuration; 45 | } 46 | 47 | + (void)saveConfiguration:(Configuration *)configuration { 48 | if (configuration.profiles.count == 0) { 49 | configuration.current = -1; 50 | } 51 | if (configuration.current != -1 && configuration.current >= configuration.profiles.count) { 52 | configuration.current = 0; 53 | } 54 | [[NSUserDefaults standardUserDefaults] setObject:[configuration JSONData] forKey:CONFIG_DATA_KEY]; 55 | [ProfileManager reloadShadowsocksRunner]; 56 | } 57 | 58 | + (void)reloadShadowsocksRunner { 59 | Configuration *configuration = [ProfileManager configuration]; 60 | if (configuration.current == -1) { 61 | [ShadowsocksRunner setUsingPublicServer:YES]; 62 | [ShadowsocksRunner reloadConfig]; 63 | } else { 64 | Profile *profile = configuration.profiles[configuration.current]; 65 | [ShadowsocksRunner setUsingPublicServer:NO]; 66 | [ShadowsocksRunner saveConfigForKey:kShadowsocksIPKey value:profile.server]; 67 | [ShadowsocksRunner saveConfigForKey:kShadowsocksPortKey value:[NSString stringWithFormat:@"%ld", (long)profile.serverPort]]; 68 | [ShadowsocksRunner saveConfigForKey:kShadowsocksPasswordKey value:profile.password]; 69 | [ShadowsocksRunner saveConfigForKey:kShadowsocksEncryptionKey value:profile.method]; 70 | [ShadowsocksRunner reloadConfig]; 71 | } 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /ShadowsocksX/QRCodeWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ShadowsocksX/SWBAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SWBAppDelegate.h 3 | // ShadowsocksX 4 | // 5 | // Created by clowwindy on 14-2-19. 6 | // Copyright (c) 2014年 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SWBAppDelegate : NSObject 12 | 13 | @property (assign) IBOutlet NSWindow *window; 14 | @property (nonatomic, strong) NSStatusItem* item; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /ShadowsocksX/SWBApplication.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 3/1/14. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | 9 | @interface SWBApplication : NSApplication 10 | @end -------------------------------------------------------------------------------- /ShadowsocksX/SWBApplication.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 3/1/14. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import "SWBApplication.h" 7 | 8 | 9 | @implementation SWBApplication { 10 | 11 | } 12 | 13 | // Enable Key Shortcuts 14 | // http://stackoverflow.com/questions/970707/cocoa-keyboard-shortcuts-in-dialog-without-an-edit-menu 15 | - (void) sendEvent:(NSEvent *)event { 16 | if ([event type] == NSKeyDown) { 17 | if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) { 18 | if ([[event charactersIgnoringModifiers] isEqualToString:@"x"]) { 19 | if ([self sendAction:@selector(cut:) to:nil from:self]) 20 | return; 21 | } 22 | else if ([[event charactersIgnoringModifiers] isEqualToString:@"c"]) { 23 | if ([self sendAction:@selector(copy:) to:nil from:self]) 24 | return; 25 | } 26 | else if ([[event charactersIgnoringModifiers] isEqualToString:@"v"]) { 27 | if ([self sendAction:@selector(paste:) to:nil from:self]) 28 | return; 29 | } 30 | else if ([[event charactersIgnoringModifiers] isEqualToString:@"z"]) { 31 | if ([self sendAction:@selector(undo:) to:nil from:self]) 32 | return; 33 | } 34 | else if ([[event charactersIgnoringModifiers] isEqualToString:@"a"]) { 35 | if ([self sendAction:@selector(selectAll:) to:nil from:self]) 36 | return; 37 | } 38 | } 39 | else if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) { 40 | if ([[event charactersIgnoringModifiers] isEqualToString:@"Z"]) { 41 | if ([self sendAction:@selector(redo:) to:nil from:self]) 42 | return; 43 | } 44 | } 45 | } 46 | [super sendEvent:event]; 47 | } 48 | 49 | @end -------------------------------------------------------------------------------- /ShadowsocksX/SWBConfigWindowController.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 14-2-26. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | @protocol SWBConfigWindowControllerDelegate 9 | 10 | @optional 11 | - (void)configurationDidChange; 12 | 13 | @end 14 | 15 | @interface SWBConfigWindowController : NSWindowController 16 | 17 | @property (nonatomic, strong) IBOutlet NSTableView *tableView; 18 | @property (nonatomic, strong) IBOutlet NSTextField *serverField; 19 | @property (nonatomic, strong) IBOutlet NSTextField *portField; 20 | @property (nonatomic, strong) IBOutlet NSComboBox *methodBox; 21 | @property (nonatomic, strong) IBOutlet NSSecureTextField *passwordField; 22 | @property (nonatomic, strong) IBOutlet NSTextField *remarksField; 23 | @property (nonatomic, strong) IBOutlet NSButton *okButton; 24 | @property (nonatomic, strong) IBOutlet NSButton *cancelButton; 25 | @property (nonatomic, strong) IBOutlet NSBox *settingsBox; 26 | @property (nonatomic, strong) IBOutlet NSTextField *placeholderLabel; 27 | @property (nonatomic, weak) id delegate; 28 | 29 | - (IBAction)OK:(id)sender; 30 | - (IBAction)cancel:(id)sender; 31 | 32 | - (IBAction)sectionClick:(id)sender; 33 | 34 | @end -------------------------------------------------------------------------------- /ShadowsocksX/SWBConfigWindowController.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by clowwindy on 14-2-26. 3 | // Copyright (c) 2014 clowwindy. All rights reserved. 4 | // 5 | 6 | #import 7 | #import 8 | #import "SWBConfigWindowController.h" 9 | #import "ShadowsocksRunner.h" 10 | #import "ProfileManager.h" 11 | #import "encrypt.h" 12 | 13 | 14 | @implementation SWBConfigWindowController { 15 | Configuration *configuration; 16 | } 17 | 18 | 19 | - (void)windowWillLoad { 20 | [super windowWillLoad]; 21 | } 22 | 23 | - (void)addMethods { 24 | for (int i = 0; i < kShadowsocksMethods; i++) { 25 | const char* method_name = shadowsocks_encryption_names[i]; 26 | NSString *methodName = [[NSString alloc] initWithBytes:method_name length:strlen(method_name) encoding:NSUTF8StringEncoding]; 27 | [_methodBox addItemWithObjectValue:methodName]; 28 | } 29 | } 30 | 31 | - (void)loadSettings { 32 | configuration = [ProfileManager configuration]; 33 | [self.tableView reloadData]; 34 | [self loadCurrentProfile]; 35 | } 36 | 37 | - (void)saveSettings { 38 | [ProfileManager saveConfiguration:configuration]; 39 | // if (_publicMatrix.selectedColumn == 0) { 40 | // [ShadowsocksRunner setUsingPublicServer:YES]; 41 | // } else { 42 | // [ShadowsocksRunner setUsingPublicServer:NO]; 43 | // [ShadowsocksRunner saveConfigForKey:kShadowsocksIPKey value:[_serverField stringValue]]; 44 | // [ShadowsocksRunner saveConfigForKey:kShadowsocksPortKey value:[_portField stringValue]]; 45 | // [ShadowsocksRunner saveConfigForKey:kShadowsocksPasswordKey value:[_passwordField stringValue]]; 46 | // [ShadowsocksRunner saveConfigForKey:kShadowsocksEncryptionKey value:[_methodBox stringValue]]; 47 | // } 48 | // if (self.delegate != nil) { 49 | // if ([self.delegate respondsToSelector:@selector(configurationDidChange)]) { 50 | // [self.delegate configurationDidChange]; 51 | // } 52 | // } 53 | } 54 | 55 | - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row { 56 | if (self.tableView.selectedRow < 0) { 57 | // always allow no selection to selection 58 | return YES; 59 | } 60 | if (row >= 0 && row < configuration.profiles.count) { 61 | if ([self validateCurrentProfile]) { 62 | [self saveCurrentProfile]; 63 | } else { 64 | return NO; 65 | } 66 | } 67 | // always allow selection to no selection 68 | return YES; 69 | } 70 | 71 | - (void)tableViewSelectionDidChange:(NSNotification *)notification { 72 | if (self.tableView.selectedRow >= 0) { 73 | [self loadCurrentProfile]; 74 | } 75 | } 76 | 77 | - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { 78 | Profile *profile = configuration.profiles[row]; 79 | if ([profile.server isEqualToString:@""]) { 80 | return @"New Server"; 81 | } 82 | return profile.server; 83 | } 84 | 85 | - (IBAction)sectionClick:(id)sender { 86 | NSInteger index = ((NSSegmentedControl *)sender).selectedSegment; 87 | if (index == 0) { 88 | [self add:sender]; 89 | } else if (index == 1) { 90 | [self remove:sender]; 91 | } 92 | } 93 | 94 | - (IBAction)add:(id)sender { 95 | if (configuration.profiles.count != 0 && ![self saveCurrentProfile]) { 96 | [self shakeWindow]; 97 | return; 98 | } 99 | Profile *profile = [[Profile alloc] init]; 100 | profile.server = @""; 101 | profile.serverPort = 8388; 102 | profile.method = @"aes-256-cfb"; 103 | profile.password = @""; 104 | [((NSMutableArray *) configuration.profiles) addObject:profile]; 105 | [self.tableView reloadData]; 106 | [self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:(configuration.profiles.count - 1)] byExtendingSelection:NO]; 107 | [self updateSettingsBoxVisible:self]; 108 | [self loadCurrentProfile]; 109 | } 110 | 111 | - (IBAction)remove:(id)sender { 112 | NSInteger selection = self.tableView.selectedRow; 113 | if (selection >= 0 && selection < configuration.profiles.count) { 114 | [((NSMutableArray *) configuration.profiles) removeObjectAtIndex:selection]; 115 | [self.tableView reloadData]; 116 | [self updateSettingsBoxVisible:self]; 117 | if (configuration.profiles.count > 0) { 118 | [self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:(configuration.profiles.count - 1)] byExtendingSelection:NO]; 119 | } 120 | [self loadCurrentProfile]; 121 | if (configuration.current > selection) { 122 | // select the original profile 123 | configuration.current = configuration.current - 1; 124 | } 125 | } 126 | } 127 | 128 | - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { 129 | return configuration.profiles.count; 130 | } 131 | 132 | - (void)windowDidLoad { 133 | self.tableView.delegate = self; 134 | self.tableView.dataSource = self; 135 | [super windowDidLoad]; 136 | [self addMethods]; 137 | [self loadSettings]; 138 | [self updateSettingsBoxVisible:self]; 139 | } 140 | 141 | - (IBAction)updateSettingsBoxVisible:(id)sender { 142 | if (configuration.profiles.count == 0) { 143 | [_settingsBox setHidden:YES]; 144 | [_placeholderLabel setHidden:NO]; 145 | } else { 146 | [_settingsBox setHidden:NO]; 147 | [_placeholderLabel setHidden:YES]; 148 | } 149 | } 150 | 151 | - (void)loadCurrentProfile { 152 | if (configuration.profiles.count > 0) { 153 | if (self.tableView.selectedRow >= 0 && self.tableView.selectedRow < configuration.profiles.count) { 154 | Profile *profile = configuration.profiles[self.tableView.selectedRow]; 155 | [_serverField setStringValue:profile.server]; 156 | [_portField setStringValue:[NSString stringWithFormat:@"%ld", (long)profile.serverPort]]; 157 | [_methodBox setStringValue:profile.method]; 158 | [_passwordField setStringValue:profile.password]; 159 | if (profile.remarks) { 160 | [_remarksField setStringValue:profile.remarks]; 161 | } else { 162 | [_remarksField setStringValue:@""]; 163 | } 164 | } 165 | } 166 | } 167 | 168 | - (BOOL)saveCurrentProfile { 169 | if (![self validateCurrentProfile]) { 170 | return NO; 171 | } 172 | if (self.tableView.selectedRow >= 0 && self.tableView.selectedRow < configuration.profiles.count) { 173 | Profile *profile = configuration.profiles[self.tableView.selectedRow]; 174 | profile.server = [_serverField stringValue]; 175 | profile.serverPort = [_portField integerValue]; 176 | profile.method = [_methodBox stringValue]; 177 | profile.password = [_passwordField stringValue]; 178 | profile.remarks = [_remarksField stringValue]; 179 | } 180 | 181 | return YES; 182 | } 183 | 184 | - (BOOL)validateCurrentProfile { 185 | if ([[_serverField stringValue] isEqualToString:@""]) { 186 | [_serverField becomeFirstResponder]; 187 | return NO; 188 | } 189 | if ([_portField integerValue] == 0) { 190 | [_portField becomeFirstResponder]; 191 | return NO; 192 | } 193 | if ([[_methodBox stringValue] isEqualToString:@""]) { 194 | [_methodBox becomeFirstResponder]; 195 | return NO; 196 | } 197 | if ([[_passwordField stringValue] isEqualToString:@""]) { 198 | [_passwordField becomeFirstResponder]; 199 | return NO; 200 | } 201 | return YES; 202 | } 203 | 204 | - (IBAction)OK:(id)sender { 205 | if ([self saveCurrentProfile]) { 206 | [self saveSettings]; 207 | [ShadowsocksRunner reloadConfig]; 208 | [self.delegate configurationDidChange]; 209 | [self.window performClose:self]; 210 | } else { 211 | [self shakeWindow]; 212 | } 213 | } 214 | 215 | - (IBAction)cancel:(id)sender { 216 | [self.window performClose:self]; 217 | } 218 | 219 | - (void)shakeWindow { 220 | static int numberOfShakes = 3; 221 | static float durationOfShake = 0.7f; 222 | static float vigourOfShake = 0.03f; 223 | 224 | CGRect frame=[self.window frame]; 225 | CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation]; 226 | 227 | CGMutablePathRef shakePath = CGPathCreateMutable(); 228 | CGPathMoveToPoint(shakePath, NULL, NSMinX(frame), NSMinY(frame)); 229 | int index; 230 | for (index = 0; index < numberOfShakes; ++index) 231 | { 232 | CGPathAddLineToPoint(shakePath, NULL, NSMinX(frame) - frame.size.width * vigourOfShake, NSMinY(frame)); 233 | CGPathAddLineToPoint(shakePath, NULL, NSMinX(frame) + frame.size.width * vigourOfShake, NSMinY(frame)); 234 | } 235 | CGPathCloseSubpath(shakePath); 236 | shakeAnimation.path = shakePath; 237 | shakeAnimation.duration = durationOfShake; 238 | 239 | [self.window setAnimations:[NSDictionary dictionaryWithObject: shakeAnimation forKey:@"frameOrigin"]]; 240 | [[self.window animator] setFrameOrigin:[self.window frame].origin]; 241 | } 242 | 243 | @end -------------------------------------------------------------------------------- /ShadowsocksX/SWBQRCodeWindowController.h: -------------------------------------------------------------------------------- 1 | // 2 | // QRCodeWindowController.h 3 | // shadowsocks 4 | // 5 | // Created by clowwindy on 10/12/14. 6 | // Copyright (c) 2014 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface SWBQRCodeWindowController : NSWindowController 13 | 14 | @property (nonatomic, strong) IBOutlet WebView *webView; 15 | @property (nonatomic, copy) NSString *qrCode; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /ShadowsocksX/SWBQRCodeWindowController.m: -------------------------------------------------------------------------------- 1 | // 2 | // QRCodeWindowController.m 3 | // shadowsocks 4 | // 5 | // Created by clowwindy on 10/12/14. 6 | // Copyright (c) 2014 clowwindy. All rights reserved. 7 | // 8 | 9 | #import "SWBQRCodeWindowController.h" 10 | 11 | @interface SWBQRCodeWindowController () 12 | 13 | @end 14 | 15 | @implementation SWBQRCodeWindowController 16 | 17 | - (void)windowDidLoad { 18 | [super windowDidLoad]; 19 | 20 | // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. 21 | [self.webView.mainFrame loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"qrcode" withExtension:@"htm"]]]; 22 | self.webView.frameLoadDelegate = self; 23 | } 24 | 25 | -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { 26 | if (self.qrCode) { 27 | [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"genCode('%@')", _qrCode]]; 28 | } 29 | } 30 | 31 | -(void)dealloc { 32 | self.webView.frameLoadDelegate = nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /ShadowsocksX/ShadowsocksX-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | Shadowsocks 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 2.6.5 21 | CFBundleSignature 22 | ???? 23 | CFBundleURLTypes 24 | 25 | 26 | CFBundleTypeRole 27 | Viewer 28 | CFBundleURLIconFile 29 | menu_icon@2x 30 | CFBundleURLName 31 | shadowsocks 32 | CFBundleURLSchemes 33 | 34 | ss 35 | 36 | 37 | 38 | CFBundleVersion 39 | 2.6.5 40 | LSApplicationCategoryType 41 | public.app-category.utilities 42 | LSMinimumSystemVersion 43 | ${MACOSX_DEPLOYMENT_TARGET} 44 | LSUIElement 45 | 46 | NSHumanReadableCopyright 47 | Copyright © 2014年 clowwindy. All rights reserved. 48 | NSMainNibFile 49 | Application 50 | NSPrincipalClass 51 | SWBApplication 52 | 53 | 54 | -------------------------------------------------------------------------------- /ShadowsocksX/ShadowsocksX-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | 11 | #define _L(s) NSLocalizedString(@#s, nil) -------------------------------------------------------------------------------- /ShadowsocksX/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /ShadowsocksX/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ShadowsocksX/install_helper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # install_helper.sh 4 | # shadowsocks 5 | # 6 | # Created by clowwindy on 14-3-15. 7 | 8 | cd `dirname "${BASH_SOURCE[0]}"` 9 | sudo mkdir -p "/Library/Application Support/ShadowsocksX/" 10 | sudo cp shadowsocks_sysconf "/Library/Application Support/ShadowsocksX/" 11 | sudo chown root:admin "/Library/Application Support/ShadowsocksX/shadowsocks_sysconf" 12 | sudo chmod +s "/Library/Application Support/ShadowsocksX/shadowsocks_sysconf" 13 | 14 | echo done -------------------------------------------------------------------------------- /ShadowsocksX/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ShadowsocksX 4 | // 5 | // Created by clowwindy on 14-2-19. 6 | // Copyright (c) 2014年 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, const char * argv[]) 12 | { 13 | return NSApplicationMain(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /ShadowsocksX/menu_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/menu_icon.png -------------------------------------------------------------------------------- /ShadowsocksX/menu_icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/menu_icon@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/menu_icon_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/menu_icon_disabled.png -------------------------------------------------------------------------------- /ShadowsocksX/menu_icon_disabled@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ShadowsocksX/menu_icon_disabled@2x.png -------------------------------------------------------------------------------- /ShadowsocksX/models/profile.json: -------------------------------------------------------------------------------- 1 | { 2 | "__class__": "Configuration", 3 | "current": 0, 4 | "profiles": [{ 5 | "__class__": "Profile", 6 | "server":"1.2.3.4", 7 | "server_port":8388, 8 | "password":"barfoo!", 9 | "method":"aes-256-cfb", 10 | "remarks":"test" 11 | }] 12 | } 13 | -------------------------------------------------------------------------------- /ShadowsocksX/qrcode.htm: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 16 |
17 | -------------------------------------------------------------------------------- /ShadowsocksXTests/ShadowsocksXTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | clowwindy.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ShadowsocksXTests/ShadowsocksXTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShadowsocksXTests.m 3 | // ShadowsocksXTests 4 | // 5 | // Created by clowwindy on 14-2-19. 6 | // Copyright (c) 2014年 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ShadowsocksXTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation ShadowsocksXTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /ShadowsocksXTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /about.txt: -------------------------------------------------------------------------------- 1 | Shadowsocks for iOS and OSX 2 | 3 | Copyright (C) 2014 clowwindy 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | 18 | ****** 19 | 20 | GFWList 21 | 22 | GNU Lesser GPL 23 | https://code.google.com/p/autoproxy-gfwlist/ 24 | 25 | ****** 26 | 27 | iProxy 28 | https://github.com/tcurdt/iProxy 29 | 30 | Apache License 31 | Version 2.0, January 2004 32 | http://www.apache.org/licenses/ 33 | 34 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 35 | 36 | 1. Definitions. 37 | 38 | "License" shall mean the terms and conditions for use, reproduction, 39 | and distribution as defined by Sections 1 through 9 of this document. 40 | 41 | "Licensor" shall mean the copyright owner or entity authorized by 42 | the copyright owner that is granting the License. 43 | 44 | "Legal Entity" shall mean the union of the acting entity and all 45 | other entities that control, are controlled by, or are under common 46 | control with that entity. For the purposes of this definition, 47 | "control" means (i) the power, direct or indirect, to cause the 48 | direction or management of such entity, whether by contract or 49 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 50 | outstanding shares, or (iii) beneficial ownership of such entity. 51 | 52 | "You" (or "Your") shall mean an individual or Legal Entity 53 | exercising permissions granted by this License. 54 | 55 | "Source" form shall mean the preferred form for making modifications, 56 | including but not limited to software source code, documentation 57 | source, and configuration files. 58 | 59 | "Object" form shall mean any form resulting from mechanical 60 | transformation or translation of a Source form, including but 61 | not limited to compiled object code, generated documentation, 62 | and conversions to other media types. 63 | 64 | "Work" shall mean the work of authorship, whether in Source or 65 | Object form, made available under the License, as indicated by a 66 | copyright notice that is included in or attached to the work 67 | (an example is provided in the Appendix below). 68 | 69 | "Derivative Works" shall mean any work, whether in Source or Object 70 | form, that is based on (or derived from) the Work and for which the 71 | editorial revisions, annotations, elaborations, or other modifications 72 | represent, as a whole, an original work of authorship. For the purposes 73 | of this License, Derivative Works shall not include works that remain 74 | separable from, or merely link (or bind by name) to the interfaces of, 75 | the Work and Derivative Works thereof. 76 | 77 | "Contribution" shall mean any work of authorship, including 78 | the original version of the Work and any modifications or additions 79 | to that Work or Derivative Works thereof, that is intentionally 80 | submitted to Licensor for inclusion in the Work by the copyright owner 81 | or by an individual or Legal Entity authorized to submit on behalf of 82 | the copyright owner. For the purposes of this definition, "submitted" 83 | means any form of electronic, verbal, or written communication sent 84 | to the Licensor or its representatives, including but not limited to 85 | communication on electronic mailing lists, source code control systems, 86 | and issue tracking systems that are managed by, or on behalf of, the 87 | Licensor for the purpose of discussing and improving the Work, but 88 | excluding communication that is conspicuously marked or otherwise 89 | designated in writing by the copyright owner as "Not a Contribution." 90 | 91 | "Contributor" shall mean Licensor and any individual or Legal Entity 92 | on behalf of whom a Contribution has been received by Licensor and 93 | subsequently incorporated within the Work. 94 | 95 | 2. Grant of Copyright License. Subject to the terms and conditions of 96 | this License, each Contributor hereby grants to You a perpetual, 97 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 98 | copyright license to reproduce, prepare Derivative Works of, 99 | publicly display, publicly perform, sublicense, and distribute the 100 | Work and such Derivative Works in Source or Object form. 101 | 102 | 3. Grant of Patent License. Subject to the terms and conditions of 103 | this License, each Contributor hereby grants to You a perpetual, 104 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 105 | (except as stated in this section) patent license to make, have made, 106 | use, offer to sell, sell, import, and otherwise transfer the Work, 107 | where such license applies only to those patent claims licensable 108 | by such Contributor that are necessarily infringed by their 109 | Contribution(s) alone or by combination of their Contribution(s) 110 | with the Work to which such Contribution(s) was submitted. If You 111 | institute patent litigation against any entity (including a 112 | cross-claim or counterclaim in a lawsuit) alleging that the Work 113 | or a Contribution incorporated within the Work constitutes direct 114 | or contributory patent infringement, then any patent licenses 115 | granted to You under this License for that Work shall terminate 116 | as of the date such litigation is filed. 117 | 118 | 4. Redistribution. You may reproduce and distribute copies of the 119 | Work or Derivative Works thereof in any medium, with or without 120 | modifications, and in Source or Object form, provided that You 121 | meet the following conditions: 122 | 123 | (a) You must give any other recipients of the Work or 124 | Derivative Works a copy of this License; and 125 | 126 | (b) You must cause any modified files to carry prominent notices 127 | stating that You changed the files; and 128 | 129 | (c) You must retain, in the Source form of any Derivative Works 130 | that You distribute, all copyright, patent, trademark, and 131 | attribution notices from the Source form of the Work, 132 | excluding those notices that do not pertain to any part of 133 | the Derivative Works; and 134 | 135 | (d) If the Work includes a "NOTICE" text file as part of its 136 | distribution, then any Derivative Works that You distribute must 137 | include a readable copy of the attribution notices contained 138 | within such NOTICE file, excluding those notices that do not 139 | pertain to any part of the Derivative Works, in at least one 140 | of the following places: within a NOTICE text file distributed 141 | as part of the Derivative Works; within the Source form or 142 | documentation, if provided along with the Derivative Works; or, 143 | within a display generated by the Derivative Works, if and 144 | wherever such third-party notices normally appear. The contents 145 | of the NOTICE file are for informational purposes only and 146 | do not modify the License. You may add Your own attribution 147 | notices within Derivative Works that You distribute, alongside 148 | or as an addendum to the NOTICE text from the Work, provided 149 | that such additional attribution notices cannot be construed 150 | as modifying the License. 151 | 152 | You may add Your own copyright statement to Your modifications and 153 | may provide additional or different license terms and conditions 154 | for use, reproduction, or distribution of Your modifications, or 155 | for any such Derivative Works as a whole, provided Your use, 156 | reproduction, and distribution of the Work otherwise complies with 157 | the conditions stated in this License. 158 | 159 | 5. Submission of Contributions. Unless You explicitly state otherwise, 160 | any Contribution intentionally submitted for inclusion in the Work 161 | by You to the Licensor shall be under the terms and conditions of 162 | this License, without any additional terms or conditions. 163 | Notwithstanding the above, nothing herein shall supersede or modify 164 | the terms of any separate license agreement you may have executed 165 | with Licensor regarding such Contributions. 166 | 167 | 6. Trademarks. This License does not grant permission to use the trade 168 | names, trademarks, service marks, or product names of the Licensor, 169 | except as required for reasonable and customary use in describing the 170 | origin of the Work and reproducing the content of the NOTICE file. 171 | 172 | 7. Disclaimer of Warranty. Unless required by applicable law or 173 | agreed to in writing, Licensor provides the Work (and each 174 | Contributor provides its Contributions) on an "AS IS" BASIS, 175 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 176 | implied, including, without limitation, any warranties or conditions 177 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 178 | PARTICULAR PURPOSE. You are solely responsible for determining the 179 | appropriateness of using or redistributing the Work and assume any 180 | risks associated with Your exercise of permissions under this License. 181 | 182 | 8. Limitation of Liability. In no event and under no legal theory, 183 | whether in tort (including negligence), contract, or otherwise, 184 | unless required by applicable law (such as deliberate and grossly 185 | negligent acts) or agreed to in writing, shall any Contributor be 186 | liable to You for damages, including any direct, indirect, special, 187 | incidental, or consequential damages of any character arising as a 188 | result of this License or out of the use or inability to use the 189 | Work (including but not limited to damages for loss of goodwill, 190 | work stoppage, computer failure or malfunction, or any and all 191 | other commercial damages or losses), even if such Contributor 192 | has been advised of the possibility of such damages. 193 | 194 | 9. Accepting Warranty or Additional Liability. While redistributing 195 | the Work or Derivative Works thereof, You may choose to offer, 196 | and charge a fee for, acceptance of support, warranty, indemnity, 197 | or other liability obligations and/or rights consistent with this 198 | License. However, in accepting such obligations, You may act only 199 | on Your own behalf and on Your sole responsibility, not on behalf 200 | of any other Contributor, and only if You agree to indemnify, 201 | defend, and hold each Contributor harmless for any liability 202 | incurred by, or claims asserted against, such Contributor by reason 203 | of your accepting any such warranty or additional liability. 204 | 205 | END OF TERMS AND CONDITIONS 206 | 207 | APPENDIX: How to apply the Apache License to your work. 208 | 209 | To apply the Apache License to your work, attach the following 210 | boilerplate notice, with the fields enclosed by brackets "[]" 211 | replaced with your own identifying information. (Don't include 212 | the brackets!) The text should be enclosed in the appropriate 213 | comment syntax for the file format. We also recommend that a 214 | file or class name and description of purpose be included on the 215 | same "printed page" as the copyright notice for easier 216 | identification within third-party archives. 217 | 218 | Copyright [yyyy] [name of copyright owner] 219 | 220 | Licensed under the Apache License, Version 2.0 (the "License"); 221 | you may not use this file except in compliance with the License. 222 | You may obtain a copy of the License at 223 | 224 | http://www.apache.org/licenses/LICENSE-2.0 225 | 226 | Unless required by applicable law or agreed to in writing, software 227 | distributed under the License is distributed on an "AS IS" BASIS, 228 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 229 | See the License for the specific language governing permissions and 230 | limitations under the License. 231 | 232 | ****** 233 | 234 | GCDWebServer 235 | https://github.com/swisspol/GCDWebServer 236 | 237 | Copyright (c) 2012-2013, Pierre-Olivier Latour 238 | All rights reserved. 239 | 240 | Redistribution and use in source and binary forms, with or without 241 | modification, are permitted provided that the following conditions are met: 242 | * Redistributions of source code must retain the above copyright 243 | notice, this list of conditions and the following disclaimer. 244 | * Redistributions in binary form must reproduce the above copyright 245 | notice, this list of conditions and the following disclaimer in the 246 | documentation and/or other materials provided with the distribution. 247 | * Neither the name of the nor the 248 | names of its contributors may be used to endorse or promote products 249 | derived from this software without specific prior written permission. 250 | 251 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 252 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 253 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 254 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 255 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 256 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 257 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 258 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 260 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261 | 262 | ****** 263 | 264 | AppProxyCap by freewizard 265 | https://github.com/freewizard/AppProxyCap 266 | Released in MIT License 267 | 268 | Modified by clowwindy, with some new features 269 | https://github.com/clowwindy/AppProxyCap 270 | 271 | ****** 272 | 273 | base64 274 | 275 | Created by Matt Gallagher on 2009/06/03. 276 | Copyright 2009 Matt Gallagher. All rights reserved. 277 | 278 | This software is provided 'as-is', without any express or implied 279 | warranty. In no event will the authors be held liable for any damages 280 | arising from the use of this software. Permission is granted to anyone to 281 | use this software for any purpose, including commercial applications, and to 282 | alter it and redistribute it freely, subject to the following restrictions: 283 | 284 | 1. The origin of this software must not be misrepresented; you must not 285 | claim that you wrote the original software. If you use this software 286 | in a product, an acknowledgment in the product documentation would be 287 | appreciated but is not required. 288 | 2. Altered source versions must be plainly marked as such, and must not be 289 | misrepresented as being the original software. 290 | 3. This notice may not be removed or altered from any source 291 | distribution. 292 | 293 | ****** 294 | 295 | zxing-objc 296 | 297 | ZXingObjC is available under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html). -------------------------------------------------------------------------------- /appstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/appstore.png -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd AppProxyCap/ 4 | git submodule init 5 | git submodule update 6 | cd .. 7 | xcodebuild -sdk iphonesimulator 8 | -------------------------------------------------------------------------------- /ios_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/ios_128.png -------------------------------------------------------------------------------- /osx_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/osx_128.png -------------------------------------------------------------------------------- /packaging/osx/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/packaging/osx/arrow.png -------------------------------------------------------------------------------- /packaging/osx/build_dmg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -ne 1 ] 4 | then 5 | echo 'build_dmg.sh version' 6 | exit 1 7 | fi 8 | 9 | dmgbuild -s settings.py 'Shadowsocks' ShadowsocksX-$1.dmg 10 | # rsync --progress -e ssh ShadowsocksX-$1.dmg frs.sourceforge.net:/home/frs/project/shadowsocksgui/dist/ 11 | 12 | -------------------------------------------------------------------------------- /packaging/osx/settings.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | import biplist 5 | import os.path 6 | 7 | # 8 | # Example settings file for dmgbuild 9 | # 10 | 11 | # Use like this: dmgbuild -s settings.py "Test Volume" test.dmg 12 | 13 | # You can actually use this file for your own application (not just TextEdit) 14 | # by doing e.g. 15 | # 16 | # dmgbuild -s settings.py -D app=/path/to/My.app "My Application" MyApp.dmg 17 | 18 | # .. Useful stuff .............................................................. 19 | 20 | application = defines.get('app', '/Applications/ShadowsocksX.app') 21 | appname = os.path.basename(application) 22 | 23 | def icon_from_app(app_path): 24 | plist_path = os.path.join(app_path, 'Contents', 'Info.plist') 25 | plist = biplist.readPlist(plist_path) 26 | icon_name = plist['CFBundleIconFile'] 27 | icon_root,icon_ext = os.path.splitext(icon_name) 28 | if not icon_ext: 29 | icon_ext = '.icns' 30 | icon_name = icon_root + icon_ext 31 | return os.path.join(app_path, 'Contents', 'Resources', icon_name) 32 | 33 | # .. Basics .................................................................... 34 | 35 | # Uncomment to override the output filename 36 | # filename = 'test.dmg' 37 | 38 | # Uncomment to override the output volume name 39 | # volume_name = 'Test' 40 | 41 | # Volume format (see hdiutil create -help) 42 | format = defines.get('format', 'UDBZ') 43 | 44 | # Volume size (must be large enough for your files) 45 | size = defines.get('size', '8M') 46 | 47 | # Files to include 48 | files = [ application ] 49 | 50 | # Symlinks to create 51 | symlinks = { 'Applications': '/Applications' } 52 | 53 | # Volume icon 54 | # 55 | # You can either define icon, in which case that icon file will be copied to the 56 | # image, *or* you can define badge_icon, in which case the icon file you specify 57 | # will be used to badge the system's Removable Disk icon 58 | # 59 | #icon = '/path/to/icon.icns' 60 | #badge_icon = icon_from_app(application) 61 | 62 | # Where to put the icons 63 | icon_locations = { 64 | appname: (140, 100), 65 | 'Applications': (480, 100) 66 | } 67 | 68 | # .. Window configuration ...................................................... 69 | 70 | # Background 71 | # 72 | # This is a STRING containing any of the following: 73 | # 74 | # #3344ff - web-style RGB color 75 | # #34f - web-style RGB color, short form (#34f == #3344ff) 76 | # rgb(1,0,0) - RGB color, each value is between 0 and 1 77 | # hsl(120,1,.5) - HSL (hue saturation lightness) color 78 | # hwb(300,0,0) - HWB (hue whiteness blackness) color 79 | # cmyk(0,1,0,0) - CMYK color 80 | # goldenrod - X11/SVG named color 81 | # builtin-arrow - A simple built-in background with a blue arrow 82 | # /foo/bar/baz.png - The path to an image file 83 | # 84 | # The hue component in hsl() and hwb() may include a unit; it defaults to 85 | # degrees ('deg'), but also supports radians ('rad') and gradians ('grad' 86 | # or 'gon'). 87 | # 88 | # Other color components may be expressed either in the range 0 to 1, or 89 | # as percentages (e.g. 60% is equivalent to 0.6). 90 | background = 'arrow.png' 91 | 92 | show_status_bar = False 93 | show_tab_view = False 94 | show_toolbar = False 95 | show_pathbar = False 96 | show_sidebar = False 97 | sidebar_width = 180 98 | 99 | # Window position in ((x, y), (w, h)) format 100 | window_rect = ((100, 100), (640, 280)) 101 | 102 | # Select the default view; must be one of 103 | # 104 | # 'icon-view' 105 | # 'list-view' 106 | # 'column-view' 107 | # 'coverflow' 108 | # 109 | default_view = 'icon-view' 110 | 111 | # General view configuration 112 | show_icon_preview = True 113 | 114 | # Set these to True to force inclusion of icon/list view settings (otherwise 115 | # we only include settings for the default view) 116 | include_icon_view_settings = 'auto' 117 | include_list_view_settings = 'auto' 118 | 119 | # .. Icon view configuration ................................................... 120 | 121 | arrange_by = None 122 | grid_offset = (0, 0) 123 | grid_spacing = 120 124 | scroll_position = (0, 0) 125 | label_pos = 'bottom' # or 'right' 126 | text_size = 16 127 | icon_size = 128 128 | 129 | # .. List view configuration ................................................... 130 | 131 | # Column names are as follows: 132 | # 133 | # name 134 | # date-modified 135 | # date-created 136 | # date-added 137 | # date-last-opened 138 | # size 139 | # kind 140 | # label 141 | # version 142 | # comments 143 | # 144 | list_icon_size = 16 145 | list_text_size = 12 146 | list_scroll_position = (0, 0) 147 | list_sort_by = 'name' 148 | list_use_relative_dates = True 149 | list_calculate_all_sizes = False, 150 | list_columns = ('name', 'date-modified', 'size', 'kind', 'date-added') 151 | list_column_widths = { 152 | 'name': 300, 153 | 'date-modified': 181, 154 | 'date-created': 181, 155 | 'date-added': 181, 156 | 'date-last-opened': 181, 157 | 'size': 97, 158 | 'kind': 115, 159 | 'label': 100, 160 | 'version': 75, 161 | 'comments': 300, 162 | } 163 | list_column_sort_directions = { 164 | 'name': 'ascending', 165 | 'date-modified': 'descending', 166 | 'date-created': 'descending', 167 | 'date-added': 'descending', 168 | 'date-last-opened': 'descending', 169 | 'size': 'descending', 170 | 'kind': 'ascending', 171 | 'label': 'ascending', 172 | 'version': 'ascending', 173 | 'comments': 'ascending', 174 | } 175 | -------------------------------------------------------------------------------- /proxy.pac.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertYim/ShadowsocksX/b327d20a297dee429fce0e632757c51b8c7faf13/proxy.pac.gz -------------------------------------------------------------------------------- /shadowsocks copy-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Shadowsocks 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIcons 12 | 13 | CFBundlePrimaryIcon 14 | 15 | CFBundleIconFiles 16 | 17 | icon57.png 18 | icon114.png 19 | icon72.png 20 | icon144.png 21 | 22 | UIPrerenderedIcon 23 | 24 | 25 | 26 | CFBundleIdentifier 27 | ${PRODUCT_NAME:rfc1034identifier} 28 | CFBundleInfoDictionaryVersion 29 | 6.0 30 | CFBundleLocalizations 31 | 32 | en 33 | zh_CN 34 | 35 | CFBundleName 36 | ${PRODUCT_NAME} 37 | CFBundlePackageType 38 | APPL 39 | CFBundleShortVersionString 40 | 1.0.1 41 | CFBundleSignature 42 | ???? 43 | CFBundleVersion 44 | 1.0.1 45 | LSRequiresIPhoneOS 46 | 47 | UIPrerenderedIcon 48 | 49 | UIRequiredDeviceCapabilities 50 | 51 | armv7 52 | 53 | UISupportedInterfaceOrientations 54 | 55 | UIInterfaceOrientationPortrait 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | UISupportedInterfaceOrientations~ipad 60 | 61 | UIInterfaceOrientationPortrait 62 | UIInterfaceOrientationPortraitUpsideDown 63 | UIInterfaceOrientationLandscapeLeft 64 | UIInterfaceOrientationLandscapeRight 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /shadowsocks.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /shadowsocks.xcworkspace/xcshareddata/shadowsocks.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "47B28B5207C05DF6BD98596A65434B6D5978C4BA", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "D13D26D55186243D670B587A687BD8154BF7E34D" : 0, 8 | "70FD92E6422A0BFF8F255BD3943E27A81643B64D" : 0, 9 | "8092C8C7FB5C3FF769ACA4A4D09F354B1F39375F" : 0, 10 | "CF7A89EA97096B2ABF1C411375A43655D55CF356" : 0, 11 | "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : 0, 12 | "47B28B5207C05DF6BD98596A65434B6D5978C4BA" : 0, 13 | "423DC45DFFDDC223DDAAA21CECBECC0E9E51BD53" : 0, 14 | "DD20A1A48C66B5213E0FEBB87A95EF51D6C6F3E8" : 0, 15 | "6ACBD9B75A9AF01FED3B43D5A1DC054996850174" : 0 16 | }, 17 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "3C7EB2B5-7EF7-4E1D-A83B-412D8F2005AA", 18 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 19 | "D13D26D55186243D670B587A687BD8154BF7E34D" : "ShadowsocksX\/NSData-Base64\/", 20 | "70FD92E6422A0BFF8F255BD3943E27A81643B64D" : "ShadowsocksX\/AppProxyCap\/lib\/inject_and_interpose\/", 21 | "8092C8C7FB5C3FF769ACA4A4D09F354B1F39375F" : "ShadowsocksX\/OpenSSL-for-iPhone\/", 22 | "CF7A89EA97096B2ABF1C411375A43655D55CF356" : "ShadowsocksX\/AppProxyCap\/", 23 | "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : "ShadowsocksX\/GCDWebServer\/", 24 | "47B28B5207C05DF6BD98596A65434B6D5978C4BA" : "ShadowsocksX\/", 25 | "423DC45DFFDDC223DDAAA21CECBECC0E9E51BD53" : "ShadowsocksX\/iProxy\/", 26 | "DD20A1A48C66B5213E0FEBB87A95EF51D6C6F3E8" : "ShadowsocksX\/AFNetworking\/", 27 | "6ACBD9B75A9AF01FED3B43D5A1DC054996850174" : "ShadowsocksX\/GZIP\/" 28 | }, 29 | "DVTSourceControlWorkspaceBlueprintNameKey" : "shadowsocks", 30 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 31 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "shadowsocks.xcworkspace", 32 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 33 | { 34 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/clowwindy\/iProxy.git", 35 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 36 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "423DC45DFFDDC223DDAAA21CECBECC0E9E51BD53" 37 | }, 38 | { 39 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/RobertYan\/ShadowsocksX.git", 40 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 41 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "47B28B5207C05DF6BD98596A65434B6D5978C4BA" 42 | }, 43 | { 44 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/nicklockwood\/GZIP.git", 45 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 46 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "6ACBD9B75A9AF01FED3B43D5A1DC054996850174" 47 | }, 48 | { 49 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "git:\/\/github.com\/comex\/inject_and_interpose.git", 50 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 51 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "70FD92E6422A0BFF8F255BD3943E27A81643B64D" 52 | }, 53 | { 54 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "git:\/\/github.com\/clowwindy\/OpenSSL-for-iPhone.git", 55 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 56 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "8092C8C7FB5C3FF769ACA4A4D09F354B1F39375F" 57 | }, 58 | { 59 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/freewizard\/AppProxyCap.git", 60 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 61 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "CF7A89EA97096B2ABF1C411375A43655D55CF356" 62 | }, 63 | { 64 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/l4u\/NSData-Base64.git", 65 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 66 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "D13D26D55186243D670B587A687BD8154BF7E34D" 67 | }, 68 | { 69 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:AFNetworking\/AFNetworking.git", 70 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 71 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "DD20A1A48C66B5213E0FEBB87A95EF51D6C6F3E8" 72 | }, 73 | { 74 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/swisspol\/GCDWebServer", 75 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 76 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "F6F96CA34C5878B0A9123C7C37855491A5E599DA" 77 | } 78 | ] 79 | } -------------------------------------------------------------------------------- /shadowsocks_sysconf/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // shadowsocks_sysconf 4 | // 5 | // Created by clowwindy on 14-3-15. 6 | // Copyright (c) 2014年 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #define VERSION @"1.0.0" 13 | 14 | int main(int argc, const char * argv[]) 15 | { 16 | if (argc != 2) { 17 | printf("usage: shadowsocks_sysconf off/auto/global\n"); 18 | return 1; 19 | } 20 | @autoreleasepool { 21 | NSString *mode = [NSString stringWithUTF8String:argv[1]]; 22 | 23 | NSSet *support_args = [NSSet setWithObjects:@"off", @"auto", @"global", @"-v", nil]; 24 | if (![support_args containsObject:mode]) { 25 | printf("usage: shadowsocks_sysconf off/auto/global\n"); 26 | return 1; 27 | } 28 | 29 | if ([mode isEqualToString:@"-v"]) { 30 | printf("%s", [VERSION UTF8String]); 31 | return 0; 32 | } 33 | 34 | static AuthorizationRef authRef; 35 | static AuthorizationFlags authFlags; 36 | authFlags = kAuthorizationFlagDefaults 37 | | kAuthorizationFlagExtendRights 38 | | kAuthorizationFlagInteractionAllowed 39 | | kAuthorizationFlagPreAuthorize; 40 | OSStatus authErr = AuthorizationCreate(nil, kAuthorizationEmptyEnvironment, authFlags, &authRef); 41 | if (authErr != noErr) { 42 | authRef = nil; 43 | } else { 44 | if (authRef == NULL) { 45 | NSLog(@"No authorization has been granted to modify network configuration"); 46 | return 1; 47 | } 48 | 49 | SCPreferencesRef prefRef = SCPreferencesCreateWithAuthorization(nil, CFSTR("Shadowsocks"), nil, authRef); 50 | 51 | NSDictionary *sets = (__bridge NSDictionary *)SCPreferencesGetValue(prefRef, kSCPrefNetworkServices); 52 | 53 | NSMutableDictionary *proxies = [[NSMutableDictionary alloc] init]; 54 | [proxies setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCFNetworkProxiesHTTPEnable]; 55 | [proxies setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCFNetworkProxiesHTTPSEnable]; 56 | [proxies setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigEnable]; 57 | [proxies setObject:[NSNumber numberWithInt:0] forKey:(NSString *)kCFNetworkProxiesSOCKSEnable]; 58 | 59 | // 遍历系统中的网络设备列表,设置 AirPort 和 Ethernet 的代理 60 | for (NSString *key in [sets allKeys]) { 61 | NSMutableDictionary *dict = [sets objectForKey:key]; 62 | NSString *hardware = [dict valueForKeyPath:@"Interface.Hardware"]; 63 | // NSLog(@"%@", hardware); 64 | if ([hardware isEqualToString:@"AirPort"] || [hardware isEqualToString:@"Wi-Fi"] || [hardware isEqualToString:@"Ethernet"]) { 65 | 66 | if ([mode isEqualToString:@"auto"]) { 67 | 68 | [proxies setObject:@"http://127.0.0.1:8090/proxy.pac" forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigURLString]; 69 | [proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigEnable]; 70 | 71 | } else if ([mode isEqualToString:@"global"]) { 72 | 73 | 74 | [proxies setObject:@"127.0.0.1" forKey:(NSString *) 75 | kCFNetworkProxiesSOCKSProxy]; 76 | [proxies setObject:[NSNumber numberWithInteger:1080] forKey:(NSString*) 77 | kCFNetworkProxiesSOCKSPort]; 78 | [proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString*) 79 | kCFNetworkProxiesSOCKSEnable]; 80 | 81 | } 82 | 83 | SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)[NSString stringWithFormat:@"/%@/%@/%@", kSCPrefNetworkServices, key, kSCEntNetProxies], (__bridge CFDictionaryRef)proxies); 84 | } 85 | } 86 | 87 | SCPreferencesCommitChanges(prefRef); 88 | SCPreferencesApplyChanges(prefRef); 89 | SCPreferencesSynchronize(prefRef); 90 | 91 | } 92 | 93 | printf("pac proxy set to %s", [mode UTF8String]); 94 | } 95 | 96 | return 0; 97 | } -------------------------------------------------------------------------------- /shadowsocks_sysconf/shadowsocks_sysconf-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /shadowsocks_sysconf/shadowsocks_sysconf.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 14-3-15 \" DATE 7 | .Dt shadowsocks_sysconf 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm shadowsocks_sysconf, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner --------------------------------------------------------------------------------