1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <proxy_resolver_v8_wrapper.h>
18 #include <sys/types.h>
19 #include <string.h>
20 #include <codecvt>
21 #include <fstream>
22 #include <iostream>
23
24 const char16_t* spec = u"";
25 const char16_t* host = u"";
26
main(int argc,char * argv[])27 int main(int argc, char *argv[]) {
28 if (argc != 2) {
29 std::cout << "incorrect number of arguments" << std::endl;
30 std::cout << "usage: ./pacrunner mypac.pac" << std::endl;
31 return EXIT_FAILURE;
32 }
33
34 ProxyResolverV8Handle* handle = ProxyResolverV8Handle_new();
35
36 std::ifstream t;
37 t.open(argv[1]);
38 if (t.rdstate() != std::ifstream::goodbit) {
39 std::cout << "error opening file" << std::endl;
40 return EXIT_FAILURE;
41 }
42 t.seekg(0, std::ios::end);
43 size_t size = t.tellg();
44 // allocate an extra byte for the null terminator
45 char* raw = (char*)calloc(size + 1, sizeof(char));
46 t.seekg(0);
47 t.read(raw, size);
48 std::string u8Script(raw);
49 std::u16string u16Script = std::wstring_convert<
50 std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(u8Script);
51
52 ProxyResolverV8Handle_SetPacScript(handle, u16Script.data());
53 ProxyResolverV8Handle_GetProxyForURL(handle, spec, host);
54
55 ProxyResolverV8Handle_delete(handle);
56 return EXIT_SUCCESS;
57 }
58