|
|
| version 1.1, 2003/10/16 17:58:49 | version 1.7, 2011/02/17 10:36:05 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include <commctrl.h> | #include <winsock.h> |
| #include "np2.h" | #include <commctrl.h> |
| #include "scrnmng.h" | #include "np2.h" |
| #include "sstp.h" | #include "scrnmng.h" |
| #include "sstp.h" | |
| #if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) | |
| #include "oemtext.h" | |
| #endif | |
| static HWND sstphwnd = NULL; | static HWND sstphwnd = NULL; |
| static BOOL sstpinused = FALSE; | |
| static int sstp_stat = SSTP_READY; | static int sstp_stat = SSTP_READY; |
| static SOCKET hSocket = INVALID_SOCKET; | static SOCKET hSocket = INVALID_SOCKET; |
| static WSAData wsadata; | static WSAData wsadata; |
| Line 15 static char sstprcv[0x1000]; | Line 18 static char sstprcv[0x1000]; |
| static DWORD sstppos = 0; | static DWORD sstppos = 0; |
| static void (*sstpproc)(HWND, char *) = NULL; | static void (*sstpproc)(HWND, char *) = NULL; |
| static const char sendermes[] = \ | static const OEMCHAR sendermes[] = \ |
| "SEND SSTP/1.2\r\n" \ | OEMTEXT("SEND SSTP/1.2\r\n") \ |
| "Sender: Neko Project II\r\n" \ | OEMTEXT("Sender: Neko Project II\r\n") \ |
| "Script: \\h\\s0%s\\e\r\n" \ | OEMTEXT("Script: \\h\\s0%s\\e\r\n") \ |
| "Option: notranslate\r\n" \ | OEMTEXT("Option: notranslate\r\n") \ |
| "Charset: Shift_JIS\r\n" \ | OEMTEXT("Charset: Shift_JIS\r\n") \ |
| "\r\n"; | OEMTEXT("\r\n"); |
| static HANDLE check_sakura(void) { | static HANDLE check_sakura(void) { |
| HANDLE hsakura; | HANDLE hsakura; |
| if ((hsakura = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "sakura")) != NULL) { | hsakura = OpenMutex(MUTEX_ALL_ACCESS, FALSE, _T("sakura")); |
| if (hsakura != NULL) { | |
| CloseHandle(hsakura); | CloseHandle(hsakura); |
| } | } |
| return(hsakura); | return(hsakura); |
| Line 37 static HANDLE check_sakura(void) { | Line 41 static HANDLE check_sakura(void) { |
| // ------------------------------------------------------------------ Async... | // ------------------------------------------------------------------ Async... |
| BOOL sstp_send(char *msg, void *proc) { | BOOL sstp_send(const OEMCHAR *msg, void (*proc)(HWND hWnd, char *msg)) { |
| sockaddr_in s_in; | sockaddr_in s_in; |
| Line 55 BOOL sstp_send(char *msg, void *proc) { | Line 59 BOOL sstp_send(char *msg, void *proc) { |
| return(FAILURE); | return(FAILURE); |
| } | } |
| wsprintf(sstpstr, sendermes, msg); | #if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) |
| OEMCHAR oem[0x1000]; | |
| OEMSPRINTF(oem, sendermes, msg); | |
| oemtext_oemtosjis(sstpstr, NELEMENTS(sstpstr), oem, -1); | |
| #else | |
| OEMSPRINTF(sstpstr, sendermes, msg); | |
| #endif | |
| sstprcv[0] = 0; | sstprcv[0] = 0; |
| sstppos = 0; | sstppos = 0; |
| Line 78 BOOL sstp_send(char *msg, void *proc) { | Line 88 BOOL sstp_send(char *msg, void *proc) { |
| } | } |
| } | } |
| sstp_stat = SSTP_SENDING; | sstp_stat = SSTP_SENDING; |
| sstpproc = (void (*)(HWND, char *))proc; | sstpproc = proc; |
| return(SUCCESS); | return(SUCCESS); |
| sstp_senderror:; | sstp_senderror:; |
| Line 96 sstp_senderror:; | Line 106 sstp_senderror:; |
| void sstp_connect(void) { | void sstp_connect(void) { |
| if (hSocket != INVALID_SOCKET) { | if (hSocket != INVALID_SOCKET) { |
| send(hSocket, sstpstr, strlen(sstpstr), 0); | send(hSocket, sstpstr, (int)strlen(sstpstr), 0); |
| } | } |
| } | } |
| Line 107 void sstp_readSocket(void) { | Line 117 void sstp_readSocket(void) { |
| int len; | int len; |
| char buf[256]; | char buf[256]; |
| while(1) { | while(1) { |
| if (ioctlsocket(hSocket, FIONREAD, &available) != NULL) { | if (ioctlsocket(hSocket, FIONREAD, &available) != 0) { |
| break; | break; |
| } | } |
| if (!available) { | if (!available) { |
| Line 176 int sstp_result(void) { | Line 186 int sstp_result(void) { |
| // 関数一発、送信逃げ。 | // 関数一発、送信逃げ。 |
| BOOL sstp_sendonly(char *msg) { | BOOL sstp_sendonly(const OEMCHAR *msg) { |
| WSAData lwsadata; | WSAData lwsadata; |
| SOCKET lSocket; | SOCKET lSocket; |
| Line 192 BOOL sstp_sendonly(char *msg) { | Line 202 BOOL sstp_sendonly(char *msg) { |
| s_in.sin_port = htons(np2oscfg.sstpport); | s_in.sin_port = htons(np2oscfg.sstpport); |
| if (connect(lSocket, (sockaddr *)&s_in, sizeof(s_in)) | if (connect(lSocket, (sockaddr *)&s_in, sizeof(s_in)) |
| != SOCKET_ERROR) { | != SOCKET_ERROR) { |
| wsprintf(msgstr, sendermes, msg); | #if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) |
| send(lSocket, msgstr, strlen(msgstr), 0); | OEMCHAR oem[0x1000]; |
| OEMSPRINTF(oem, sendermes, msg); | |
| oemtext_oemtosjis(msgstr, NELEMENTS(msgstr), oem, -1); | |
| #else | |
| OEMSPRINTF(msgstr, sendermes, msg); | |
| #endif | |
| send(lSocket, msgstr, (int)strlen(msgstr), 0); | |
| ret = SUCCESS; | ret = SUCCESS; |
| } | } |
| closesocket(lSocket); | closesocket(lSocket); |