Debian Codegraph @

Contrib/Dialer/dialer.c

raw
1 // Unicode support by Jim Park -- 08/22/2007
2
3 #define WIN32_LEAN_AND_MEAN
4 #include <windows.h>
5 #include <wininet.h>
6
7 #include <nsis/pluginapi.h> // nsis plugin
8
9 #define NSISFunction(funcname) void __declspec(dllexport) funcname(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
10
11 BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
12 return TRUE;
13 }
14
15 /*************\
16 * LOADER *
17 \*************/
18
19 HMODULE NSISCALL LoadSystemLibrary(LPCSTR name) {
20 LPCTSTR fmt = sizeof(*fmt) > 1 ? TEXT("%s%S.dll") : TEXT("%s%s.dll"); // The module name is always ANSI
21 BYTE bytebuf[(MAX_PATH+1+20+1+3+!0) * sizeof(*fmt)]; // 20+4 is more than enough for
22 LPTSTR path = (LPTSTR) bytebuf; // the dllnames we are using.
23
24 UINT cch = GetSystemDirectory(path, MAX_PATH);
25 if (cch > MAX_PATH) // MAX_PATH was somehow not large enough and we don't support
26 cch = 0; // \\?\ paths so we have to settle for just the name.
27 wsprintf(path + cch, fmt, TEXT("\\") + (!cch || path[cch-1] == '\\'), name);
28
29 return LoadLibrary(path);
30 }
31
32 FARPROC GetWinInetFunc(LPCSTR funcname) {
33 HMODULE hWinInet = LoadSystemLibrary("WININET");
34 return hWinInet ? GetProcAddress(hWinInet, funcname) : (FARPROC) hWinInet;
35 }
36
37
38 /*************\
39 * FUNCTIONS *
40 \*************/
41
42 NSISFunction(AutodialOnline) {
43 typedef BOOL (WINAPI *fInternetAutodial)(DWORD, HWND);
44 fInternetAutodial pInternetAutodial = (fInternetAutodial) GetWinInetFunc("InternetAutodial");
45 if (!pInternetAutodial) {
46 extra->exec_flags->exec_error++;
47 return;
48 }
49
50 EXDLL_INIT();
51
52 if (pInternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE, 0))
53 pushstring(_T("online"));
54 else
55 pushstring(_T("offline"));
56 }
57
58 NSISFunction(AutodialUnattended) {
59 typedef BOOL (WINAPI *fInternetAutodial)(DWORD, HWND);
60 fInternetAutodial pInternetAutodial = (fInternetAutodial) GetWinInetFunc("InternetAutodial");
61 if (!pInternetAutodial) {
62 extra->exec_flags->exec_error++;
63 return;
64 }
65
66 EXDLL_INIT();
67
68 if (pInternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED , 0))
69 pushstring(_T("online"));
70 else
71 pushstring(_T("offline"));
72 }
73
74 NSISFunction(AttemptConnect) {
75 typedef DWORD (WINAPI *fAttemptConn)(DWORD);
76 fAttemptConn pInternetAttemptConnect = (fAttemptConn) GetWinInetFunc("InternetAttemptConnect");
77 if (!pInternetAttemptConnect) {
78 extra->exec_flags->exec_error++;
79 return;
80 }
81
82 EXDLL_INIT();
83
84 if (pInternetAttemptConnect(0) == ERROR_SUCCESS)
85 pushstring(_T("online"));
86 else
87 pushstring(_T("offline"));
88 }
89
90 NSISFunction(GetConnectedState) {
91 DWORD dwState;
92
93 typedef BOOL (WINAPI *fGetConState)(LPDWORD, DWORD);
94 fGetConState pInternetGetConnectedState = (fGetConState) GetWinInetFunc("InternetGetConnectedState");
95 if (!pInternetGetConnectedState) {
96 extra->exec_flags->exec_error++;
97 return;
98 }
99
100 EXDLL_INIT();
101
102 if (pInternetGetConnectedState(&dwState, 0))
103 pushstring(_T("online"));
104 else
105 pushstring(_T("offline"));
106 }
107
108 NSISFunction(AutodialHangup) {
109 typedef BOOL (WINAPI *fAutodial)(DWORD);
110 fAutodial pInternetAutodialHangup = (fAutodial) GetWinInetFunc("InternetAutodialHangup");
111 if (!pInternetAutodialHangup) {
112 extra->exec_flags->exec_error++;
113 return;
114 }
115
116 EXDLL_INIT();
117
118 if (pInternetAutodialHangup(0))
119 pushstring(_T("success"));
120 else
121 pushstring(_T("failure"));
122 }