-
Notifications
You must be signed in to change notification settings - Fork 2
/
execute.c
84 lines (73 loc) · 2.26 KB
/
execute.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "execute.h"
#include "execute_i.h"
#ifdef _WIN32
# if WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
# include "execute_wsh.h"
# endif
#else
# include "execute_jscore.h"
#endif
typedef struct g_proxy_execute_s {
// Library reference count
int32_t ref_count;
// Proxy execute interface
proxy_execute_i_s *proxy_execute_i;
} g_proxy_execute_s;
g_proxy_execute_s g_proxy_execute;
bool proxy_execute_get_proxies_for_url(void *ctx, const char *script, const char *url) {
if (!g_proxy_execute.proxy_execute_i)
return false;
return g_proxy_execute.proxy_execute_i->get_proxies_for_url(ctx, script, url);
}
const char *proxy_execute_get_list(void *ctx) {
if (!g_proxy_execute.proxy_execute_i)
return NULL;
return g_proxy_execute.proxy_execute_i->get_list(ctx);
}
int32_t proxy_execute_get_error(void *ctx) {
if (!g_proxy_execute.proxy_execute_i)
return -1;
return g_proxy_execute.proxy_execute_i->get_error(ctx);
}
void *proxy_execute_create(void) {
if (!g_proxy_execute.proxy_execute_i)
return NULL;
return g_proxy_execute.proxy_execute_i->create();
}
bool proxy_execute_delete(void **ctx) {
if (!g_proxy_execute.proxy_execute_i)
return false;
return g_proxy_execute.proxy_execute_i->delete(ctx);
}
bool proxy_execute_global_init(void) {
if (g_proxy_execute.ref_count > 0) {
g_proxy_execute.ref_count++;
return true;
}
memset(&g_proxy_execute, 0, sizeof(g_proxy_execute));
#ifdef _WIN32
# if WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
if (proxy_execute_wsh_global_init())
g_proxy_execute.proxy_execute_i = proxy_execute_wsh_get_interface();
# endif
#else
if (proxy_execute_jscore_global_init())
g_proxy_execute.proxy_execute_i = proxy_execute_jscore_get_interface();
#endif
if (!g_proxy_execute.proxy_execute_i)
return false;
g_proxy_execute.ref_count++;
return true;
}
bool proxy_execute_global_cleanup(void) {
if (--g_proxy_execute.ref_count > 0)
return true;
if (g_proxy_execute.proxy_execute_i)
g_proxy_execute.proxy_execute_i->global_cleanup();
memset(&g_proxy_execute, 0, sizeof(g_proxy_execute));
return true;
}