/** ** File ......... inject.cpp ** Published .... 2005-06-14 ** Author ....... grymse@alhem.net **/ /* Copyright (C) 2005 Anders Hedstrom This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef _WIN32 #pragma warning(disable:4786) #endif #include #include #include "BString.h" #include "Exception.h" #include "MetainfoSocket.h" bool validate(const std::string& ); int main(int argc,char *argv[]) { std::string host = "localhost"; port_t port = 16969; std::list files; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-host") && i < argc - 1) host = argv[++i]; else if (!strcmp(argv[i], "-port") && i < argc - 1) port = atoi(argv[++i]); else files.push_back(argv[i]); } for (std::list::iterator it = files.begin(); it != files.end(); it++) { std::string filename = *it; if (filename.size()) { if (validate(filename)) { StdoutLog log; SocketHandler h(&log); MetainfoSocket x(h, filename); x.Open(host, port); h.Add(&x); h.Select(1,0); while (h.GetCount()) { h.Select(1,0); } } } else { printf("Usage: %s [-host ] [-port ] \n", *argv); } } return 0; } bool validate(const std::string& file) { try { FILE *fil = fopen(file.c_str(), "rb"); if (fil) { BString meta; meta.read_file(fil); fclose(fil); } else { printf("Couldn't open '%s'...\n", file.c_str()); } } catch (const Exception& e) { printf("Invalid metainfo file: %s\n", e.GetText().c_str()); return false; } return true; }