3 * Copyright (C) 2005 ReactOS Team
5 * LICENCE: GPL - See COPYING in the top level directory
6 * PROJECT: ReactOS simple TCP/IP services
7 * FILE: apps/utils/net/tcpsvcs/qotd.c
8 * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
9 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
23 LPCTSTR FilePath
= _T("\\drivers\\etc\\quotes");
25 DWORD WINAPI
QotdHandler(VOID
* Sock_
)
30 TCHAR Quote
[60][BUFSIZ
]; // need to set this dynamically
36 if(! GetSystemDirectory(Sys
, MAX_PATH
))
38 LogEvent(_T("QOTD: Getting system path failed.\n"), 0, TRUE
);
42 _tcscat(Sys
, FilePath
);
44 LogEvent(_T("QOTD: Opening quotes file\n"), 0, FALSE
);
45 if ((fp
= _tfopen(Sys
, "r")) == NULL
)
49 _stprintf(buf
, _T("QOTD: Error opening quote file : %s\n"), Sys
);
50 LogEvent(buf
, 0, TRUE
);
51 LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE
);
55 /* read all quotes in the file into an array */
57 while (_fgetts(Quote
[NumQuotes
], QBUFSIZ
, fp
) != NULL
)
60 LogEvent(_T("QOTD: Closing quotes file\n"), 0, FALSE
);
63 /* randomise the quote */
64 srand((unsigned int) time(0));
65 QuoteToPrint
= rand() % NumQuotes
;
67 if (!SendQuote(Sock
, Quote
[QuoteToPrint
]))
68 LogEvent(_T("QOTD: Error sending data\n"), 0, TRUE
);
71 LogEvent(_T("QOTD: Shutting connection down...\n"), 0, FALSE
);
72 if (ShutdownConnection(Sock
, FALSE
))
73 LogEvent(_T("QOTD: Connection is down\n"), 0, FALSE
);
76 LogEvent(_T("QOTD: Connection shutdown failed\n"), 0, FALSE
);
77 LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE
);
81 LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE
);
88 BOOL
SendQuote(SOCKET Sock
, TCHAR
* Quote
)
93 StringSize
= (INT
)_tcsclen(Quote
);
94 RetVal
= send(Sock
, Quote
, sizeof(TCHAR
) * StringSize
, 0);
96 if (RetVal
== SOCKET_ERROR
)
99 LogEvent(_T("QOTD: Connection closed by peer\n"), 0, FALSE
);