OSDN Git Service

使われなくなった関数do_cmd_pray()を削除.
[hengband/hengband.git] / src / inet.c
index 6963e67..ee45768 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <stdlib.h>
 
-static char    *errstr;
+static cptr errstr;
 static char    *proxy;
 static int     proxy_port;
 
@@ -100,7 +100,7 @@ int soc_read(int sd, char *buf, size_t sz)
 #endif /* if 0 */
 
 /* ¥×¥í¥­¥·¥µ¡¼¥Ð¤Î¥¢¥É¥ì¥¹¤ò¤ò¥Õ¥¡¥¤¥ë¤«¤éÆɤó¤ÇÀßÄꤹ¤ë */
-static void set_proxy()
+void set_proxy(char *default_url, int default_port)
 {
        char buf[1024];
        size_t len;
@@ -112,30 +112,30 @@ static void set_proxy()
        char tmp[8];
 #endif
 
-       path_build(buf, 1024, ANGBAND_DIR_PREF, "proxy.prf");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, "proxy.prf");
 
-       /* ¥Õ¥¡¥¤¥ë¤«¤éÀßÄê¤òÆɤࡣ*/
+       /* ¥Õ¥¡¥¤¥ë¤«¤éÀßÄê¤òÆɤࡣ */
        fp = my_fopen(buf, "r");
 
        if (!fp)
        {
-               /* ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ïdefine.hÆâ¤Î¥Ç¥Õ¥©¥ë¥È¤òÀßÄê */
-               proxy = HTTP_PROXY;
-               proxy_port = HTTP_PROXY_PORT;
+               /* ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï¥Ç¥Õ¥©¥ë¥È¤òÀßÄê */
+               proxy = default_url;
+               proxy_port = default_port;
                return;
        }
 
-       while (my_fgets(fp, buf, 1024)==0)
+       while (my_fgets(fp, buf, sizeof(buf))==0)
        {
                if (buf[0] != '#' && buf[0] != '\0') break;
        }
 
        my_fclose(fp);
 
-       /* ¥Ý¥¤¥ó¥¿¤òÍÑ°Õ¡£*/
+       /* ¥Ý¥¤¥ó¥¿¤òÍÑ°Õ¡£ */
        s = buf;
 
-       /* "http://" ¤«¤é»Ï¤Þ¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï¤½¤ÎÉôʬ¤ò¥«¥Ã¥È¤¹¤ë¡£*/
+       /* "http://" ¤«¤é»Ï¤Þ¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï¤½¤ÎÉôʬ¤ò¥«¥Ã¥È¤¹¤ë¡£ */
 #if defined(WINDOWS)
        if (!strnicmp(s, "http://", 7))
        {
@@ -163,7 +163,7 @@ static void set_proxy()
        len = strlen(s);
        proxy = malloc(len + 1);
 
-       /* ¥Ý¡¼¥ÈÈֹ椬¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¡¢¤¢¤ì¤Ðproxy_port¤ËÀßÄê¡£*/
+       /* ¥Ý¡¼¥ÈÈֹ椬¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¡¢¤¢¤ì¤Ðproxy_port¤ËÀßÄê¡£ */
        --len;
        while (len > 0 && isdigit(s[len]))
                --len;
@@ -176,7 +176,7 @@ static void set_proxy()
        else
        {
                strcpy(proxy, s);
-               proxy_port = HTTP_PROXY_PORT;
+               proxy_port = default_port;
        }
 
        /* ¥×¥í¥­¥·¤Î¥¢¥É¥ì¥¹¤òproxy¤Ë¥³¥Ô¡¼ */
@@ -223,12 +223,12 @@ int soc_write_str(int sd, char *buf)
 #endif
 
 #if !defined(WINDOWS) && !defined(MACINTOSH)
-static jmp_buf env;
+static sigjmp_buf      env;
 static void (*sig_int_saved)(int);
 static void (*sig_alm_saved)(int);
 #endif
 
-static void restore_signal()
+static void restore_signal(void)
 {
 #if !defined(WINDOWS) && !defined(MACINTOSH)
        struct itimerval        val0;
@@ -256,9 +256,9 @@ static void interrupt_report(int sig)
 #endif
 
 
+/* ¥µ¡¼¥Ð¤Ë¥³¥Í¥¯¥È¤¹¤ë´Ø¿ô¡£ */
+int connect_server(int timeout, const char *host, int port)
 #ifndef MACINTOSH
-/* ¥µ¡¼¥Ð¤Ë¥³¥Í¥¯¥È¤¹¤ë´Ø¿ô¡£ Win, unix */
-static int connect_server(int timeout, const char *host, int port)
 {
        int                     sd;
        struct sockaddr_in      to;
@@ -274,7 +274,7 @@ static int connect_server(int timeout, const char *host, int port)
        val.it_value.tv_sec = timeout;
        val.it_value.tv_usec = 0;
 
-       /* ¥¿¥¤¥à¥¢¥¦¥È¡¢¤â¤·¤¯¤ÏÃæÃǤ·¤¿»þ¤Î½èÍý¡£*/
+       /* ¥¿¥¤¥à¥¢¥¦¥È¡¢¤â¤·¤¯¤ÏÃæÃǤ·¤¿»þ¤Î½èÍý¡£ */
        if ((ret = sigsetjmp(env,1)) != 0)
        {
 #ifdef JP
@@ -292,9 +292,12 @@ static int connect_server(int timeout, const char *host, int port)
        }
        sig_int_saved = signal(SIGINT, interrupt_report);
        sig_alm_saved = signal(SIGALRM, interrupt_report);
-    
+
        /* ¥¿¥¤¥à¥¢¥¦¥È¤Î»þ´Ö¤òÀßÄê */
        setitimer(ITIMER_REAL, &val, NULL);
+#else
+       /* Unused in Windows */
+       (void)timeout;
 #endif
 
        /* ¥×¥í¥­¥·¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ð¥×¥í¥­¥·¤Ë·Ò¤° */
@@ -332,23 +335,15 @@ static int connect_server(int timeout, const char *host, int port)
        to.sin_family = AF_INET;
 
        if(proxy && proxy[0] && proxy_port)
-               to.sin_port = htons(proxy_port);
+               to.sin_port = htons((unsigned short int)proxy_port);
        else
-               to.sin_port = htons(port);
+               to.sin_port = htons((unsigned short int)port);
 
 #ifndef WINDOWS
        if ((sd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
-       {
-#ifdef JP
-               errstr = "¥¨¥é¡¼: ¥½¥±¥Ã¥È¤òÀ¸À®¤Ç¤­¤Þ¤»¤ó";
-#else
-               errstr = "Error : cannot create socket.";
-#endif
-               restore_signal();
-               return -1;
-       }
 #else
        if  ((sd = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+#endif
        {
 #ifdef JP
                errstr = "¥¨¥é¡¼: ¥½¥±¥Ã¥È¤òÀ¸À®¤Ç¤­¤Þ¤»¤ó";
@@ -358,7 +353,6 @@ static int connect_server(int timeout, const char *host, int port)
                restore_signal();
                return -1;
        }
-#endif
 
        if (connect(sd, (struct sockaddr *)&to, sizeof(to)) < 0)
        {
@@ -383,8 +377,7 @@ static int connect_server(int timeout, const char *host, int port)
 
 #else /* !MACINTOSH */
 
-/* ¥µ¡¼¥Ð¤Ë¥³¥Í¥¯¥È¤¹¤ë´Ø¿ô¡£ Mac */
-static int connect_server(int timeout, const char *host, int port)
+        /* ¥µ¡¼¥Ð¤Ë¥³¥Í¥¯¥È¤¹¤ë´Ø¿ô¡£ Mac */
 {
        OSStatus err;
        InetHostInfo    response;
@@ -481,13 +474,6 @@ static int connect_server(int timeout, const char *host, int port)
 }
 #endif
 
-int connect_scoreserver(void)
-{
-       /* ¥×¥í¥­¥·¤òÀßÄꤹ¤ë */
-       set_proxy();
-
-       return connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
-}
 
 int disconnect_server(int sd)
 {
@@ -508,8 +494,7 @@ int disconnect_server(int sd)
 #endif
 }
 
-char *
-soc_err()
+cptr soc_err()
 {
        return errstr;
 }