--- np2/win9x/sstp.cpp 2003/10/16 17:58:49 1.1 +++ np2/win9x/sstp.cpp 2011/03/07 09:54:11 1.8 @@ -1,12 +1,26 @@ -#include "compiler.h" -#include -#include "np2.h" -#include "scrnmng.h" -#include "sstp.h" - +/** + * @file sstp.cpp + * @brief Sakura Script Transfer Protocol handler + * + * @author $Author: yui $ + * @date $Date: 2011/03/07 09:54:11 $ + */ + +#include "compiler.h" +#include +#include +#include "np2.h" +#include "scrnmng.h" +#include "sstp.h" +#if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) +#include "oemtext.h" +#endif + +#if !defined(__GNUC__) +#pragma comment(lib, "wsock32.lib") +#endif // !defined(__GNUC__) static HWND sstphwnd = NULL; -static BOOL sstpinused = FALSE; static int sstp_stat = SSTP_READY; static SOCKET hSocket = INVALID_SOCKET; static WSAData wsadata; @@ -15,20 +29,21 @@ static char sstprcv[0x1000]; static DWORD sstppos = 0; static void (*sstpproc)(HWND, char *) = NULL; -static const char sendermes[] = \ - "SEND SSTP/1.2\r\n" \ - "Sender: Neko Project II\r\n" \ - "Script: \\h\\s0%s\\e\r\n" \ - "Option: notranslate\r\n" \ - "Charset: Shift_JIS\r\n" \ - "\r\n"; +static const OEMCHAR sendermes[] = \ + OEMTEXT("SEND SSTP/1.2\r\n") \ + OEMTEXT("Sender: Neko Project II\r\n") \ + OEMTEXT("Script: \\h\\s0%s\\e\r\n") \ + OEMTEXT("Option: notranslate\r\n") \ + OEMTEXT("Charset: Shift_JIS\r\n") \ + OEMTEXT("\r\n"); static HANDLE check_sakura(void) { HANDLE hsakura; - if ((hsakura = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "sakura")) != NULL) { + hsakura = OpenMutex(MUTEX_ALL_ACCESS, FALSE, _T("sakura")); + if (hsakura != NULL) { CloseHandle(hsakura); } return(hsakura); @@ -37,7 +52,7 @@ static HANDLE check_sakura(void) { // ------------------------------------------------------------------ Async... -BOOL sstp_send(char *msg, void *proc) { +BOOL sstp_send(const OEMCHAR *msg, void (*proc)(HWND hWnd, char *msg)) { sockaddr_in s_in; @@ -55,7 +70,13 @@ BOOL sstp_send(char *msg, void *proc) { 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; sstppos = 0; @@ -78,7 +99,7 @@ BOOL sstp_send(char *msg, void *proc) { } } sstp_stat = SSTP_SENDING; - sstpproc = (void (*)(HWND, char *))proc; + sstpproc = proc; return(SUCCESS); sstp_senderror:; @@ -96,7 +117,7 @@ sstp_senderror:; void sstp_connect(void) { if (hSocket != INVALID_SOCKET) { - send(hSocket, sstpstr, strlen(sstpstr), 0); + send(hSocket, sstpstr, (int)strlen(sstpstr), 0); } } @@ -107,7 +128,7 @@ void sstp_readSocket(void) { int len; char buf[256]; while(1) { - if (ioctlsocket(hSocket, FIONREAD, &available) != NULL) { + if (ioctlsocket(hSocket, FIONREAD, &available) != 0) { break; } if (!available) { @@ -176,7 +197,7 @@ int sstp_result(void) { // 関数一発、送信逃げ。 -BOOL sstp_sendonly(char *msg) { +BOOL sstp_sendonly(const OEMCHAR *msg) { WSAData lwsadata; SOCKET lSocket; @@ -192,8 +213,14 @@ BOOL sstp_sendonly(char *msg) { s_in.sin_port = htons(np2oscfg.sstpport); if (connect(lSocket, (sockaddr *)&s_in, sizeof(s_in)) != SOCKET_ERROR) { - wsprintf(msgstr, sendermes, msg); - send(lSocket, msgstr, strlen(msgstr), 0); +#if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) + 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; } closesocket(lSocket);