00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef _WIN32
00024 #pragma warning(disable:4786)
00025 #endif
00026 #include <SocketHandler.h>
00027 #include <StdoutLog.h>
00028 #include "BString.h"
00029 #include "Exception.h"
00030 #include "MetainfoSocket.h"
00031
00032
00033 bool validate(const std::string& );
00034
00035 int main(int argc,char *argv[])
00036 {
00037 std::string host = "localhost";
00038 port_t port = 16969;
00039 std::list<std::string> files;
00040 for (int i = 1; i < argc; i++)
00041 {
00042 if (!strcmp(argv[i], "-host") && i < argc - 1)
00043 host = argv[++i];
00044 else
00045 if (!strcmp(argv[i], "-port") && i < argc - 1)
00046 port = atoi(argv[++i]);
00047 else
00048 files.push_back(argv[i]);
00049 }
00050 for (std::list<std::string>::iterator it = files.begin(); it != files.end(); it++)
00051 {
00052 std::string filename = *it;
00053 if (filename.size())
00054 {
00055 if (validate(filename))
00056 {
00057 StdoutLog log;
00058 SocketHandler h(&log);
00059 MetainfoSocket x(h, filename);
00060 x.SetFlushBeforeClose();
00061 x.Open(host, port);
00062 h.Add(&x);
00063 h.Select(1,0);
00064 while (h.GetCount())
00065 {
00066 h.Select(1,0);
00067 }
00068 }
00069 }
00070 else
00071 {
00072 printf("Usage: %s [-host <host>] [-port <port>] <file>\n", *argv);
00073 }
00074 }
00075 return 0;
00076 }
00077
00078
00079 bool validate(const std::string& file)
00080 {
00081 try
00082 {
00083 FILE *fil = fopen(file.c_str(), "rb");
00084 if (fil)
00085 {
00086 BString meta;
00087 meta.read_file(fil);
00088 fclose(fil);
00089 }
00090 else
00091 {
00092 printf("Couldn't open '%s'...\n", file.c_str());
00093 }
00094 }
00095 catch (const Exception& e)
00096 {
00097 printf("Invalid metainfo file: %s\n", e.GetText().c_str());
00098 return false;
00099 }
00100 return true;
00101 }
00102