Mercurial > hg > nnchat
comparison nnchat.c @ 64:6a3a917303e4
Some random cleanups, bring back WinSock support.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Nov 2008 22:33:35 +0200 |
parents | afd90bbb3af6 |
children | e763ef5cfd53 |
comparison
equal
deleted
inserted
replaced
63:afd90bbb3af6 | 64:6a3a917303e4 |
---|---|
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include "th_args.h" | 8 #include "th_args.h" |
9 #include <string.h> | 9 #include <string.h> |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <time.h> | 11 #include <time.h> |
12 #ifdef __WIN32 | |
13 #include <curses.h> | |
14 #else | |
12 #include <ncurses.h> | 15 #include <ncurses.h> |
16 #endif | |
13 | 17 |
14 | 18 |
15 #define SET_MAX_BACKBUF (1024) | 19 #define SET_MAX_BACKBUF (1024) |
16 #define SET_MAX_HISTORY (16) | 20 #define SET_MAX_HISTORY (16) |
17 #define SET_DELAY (15) | 21 #define SET_DELAY (15) |
490 th_free(t); | 494 th_free(t); |
491 } else { | 495 } else { |
492 BOOL isMine = strcmp(p, optUserName) == 0; | 496 BOOL isMine = strcmp(p, optUserName) == 0; |
493 t = stripXMLTags(s); | 497 t = stripXMLTags(s); |
494 h = decodeStr2(t); | 498 h = decodeStr2(t); |
495 printMsg("½5½<½%d½%s½5½>½%d½ %s½0½\n", | 499 printMsg("½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p, h); |
496 isMine ? 14 : 15, p, isMine ? 16 : 0, h); | |
497 th_free(h); | 500 th_free(h); |
498 th_free(t); | 501 th_free(t); |
499 } | 502 } |
500 | 503 |
501 th_free(s); | 504 th_free(s); |
739 return -1; | 742 return -1; |
740 } | 743 } |
741 | 744 |
742 if (!argsOK) | 745 if (!argsOK) |
743 return -2; | 746 return -2; |
744 | 747 |
748 | |
749 #ifdef __WIN32 | |
750 { | |
751 /* Initialize WinSock, if needed */ | |
752 WSADATA wsaData; | |
753 int err = WSAStartup(0x0200, &wsaData); | |
754 if (err != 0) { | |
755 THERR("Could not initialize WinSock DLL: %d\n", err); | |
756 return -3; | |
757 } | |
758 #endif | |
759 | |
745 /* Open logfile */ | 760 /* Open logfile */ |
746 if (optLogFilename) { | 761 if (optLogFilename) { |
747 THMSG(1, "Opening logfile '%s'\n", optLogFilename); | 762 THMSG(1, "Opening logfile '%s'\n", optLogFilename); |
748 | 763 |
749 if ((optLogFile = fopen(optLogFilename, "a")) == NULL) { | 764 if ((optLogFile = fopen(optLogFilename, "a")) == NULL) { |
775 if (sendToSocket(tmpSocket, tmpStr, strlen(tmpStr) + 1) == FALSE) { | 790 if (sendToSocket(tmpSocket, tmpStr, strlen(tmpStr) + 1) == FALSE) { |
776 THERR("Failed to send fakeprobe.\n"); | 791 THERR("Failed to send fakeprobe.\n"); |
777 goto err_exit; | 792 goto err_exit; |
778 } else { | 793 } else { |
779 ssize_t gotBuf; | 794 ssize_t gotBuf; |
780 char tmpBuf[4096]; | 795 char tmpBuf[SET_BUFSIZE]; |
781 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); | 796 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); |
782 tmpBuf[gotBuf-1] = 0; | 797 tmpBuf[gotBuf-1] = 0; |
783 THMSG(2, "Probe got: %s\n", tmpBuf); | 798 THMSG(2, "Probe got: %s\n", tmpBuf); |
784 closeConnection(tmpSocket); | 799 closeConnection(tmpSocket); |
785 } | 800 } |