Logo
~Apps~
~Projects~
~Contact~


inject.cpp File Reference

#include <SocketHandler.h>
#include <StdoutLog.h>
#include "BString.h"
#include "Exception.h"
#include "MetainfoSocket.h"

Include dependency graph for inject.cpp:

Go to the source code of this file.


Functions

bool validate (const std::string &)
int main (int argc, char *argv[])

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file inject.cpp.

References validate().

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 }

bool validate ( const std::string &   ) 

File ......... inject.cpp Published .... 2005-06-14 Author ....... grymse@alhem.net

Definition at line 79 of file inject.cpp.

References Exception::GetText(), and BString::read_file().

Referenced by main().

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 }

Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4