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)
19 LPCTSTR FilePath
= _T("\\drivers\\etc\\quotes");
21 DWORD WINAPI
QotdHandler(VOID
* Sock_
)
26 TCHAR Quote
[60][BUFSIZ
]; // need to set this dynamically
32 if(! GetSystemDirectory(Sys
, MAX_PATH
))
34 LogEvent(_T("QOTD: Getting system path failed.\n"), 0, TRUE
);
38 _tcscat(Sys
, FilePath
);
40 LogEvent(_T("QOTD: Opening quotes file\n"), 0, FALSE
);
41 if ((fp
= _tfopen(Sys
, "r")) == NULL
)
45 _stprintf(buf
, _T("QOTD: Error opening quote file : %s\n"), Sys
);
46 LogEvent(buf
, 0, TRUE
);
47 LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE
);
51 /* read all quotes in the file into an array */
53 while (_fgetts(Quote
[NumQuotes
], QBUFSIZ
, fp
) != NULL
)
56 LogEvent(_T("QOTD: Closing quotes file\n"), 0, FALSE
);
59 /* randomise the quote */
60 srand((unsigned int) time(0));
61 QuoteToPrint
= rand() % NumQuotes
;
63 if (!SendQuote(Sock
, Quote
[QuoteToPrint
]))
64 LogEvent(_T("QOTD: Error sending data\n"), 0, TRUE
);
67 LogEvent(_T("QOTD: Shutting connection down...\n"), 0, FALSE
);
68 if (ShutdownConnection(Sock
, FALSE
))
69 LogEvent(_T("QOTD: Connection is down\n"), 0, FALSE
);
72 LogEvent(_T("QOTD: Connection shutdown failed\n"), 0, FALSE
);
73 LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE
);
77 LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE
);
84 BOOL
SendQuote(SOCKET Sock
, TCHAR
* Quote
)
89 StringSize
= (INT
)_tcsclen(Quote
);
90 RetVal
= send(Sock
, Quote
, sizeof(TCHAR
) * StringSize
, 0);
92 if (RetVal
== SOCKET_ERROR
)
95 LogEvent(_T("QOTD: Connection closed by peer\n"), 0, FALSE
);