/* * ---------------------------------------------------------------------------------- * * Copyright (c) 2012–2015 Software AG, Darmstadt, Germany and/or * Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries * and/or its affiliates and/or their licensors. Use, reproduction, * transfer, publication or disclosure is prohibited except as specifically * provided for in your License Agreement with Software AG. * *   In the event that you should download or otherwise use this software *   you hereby acknowledge and agree to the terms at *   http://www.my-channels.com/company/terms.html#legalnotices * */ #include "nSampleApp.h" #include "fBase.h" #include "ShellServer.h" #include "Shell.h" #include "Poco/Exception.h" using namespace com::pcbsys::nirvana::apps; namespace com { namespace pcbsys { namespace nirvana { namespace apps { class nP2PShell { private: static nP2PShell *m_pSelf; static bool m_bIsServer; public: static int Main(int argc, char** argv) { if (argc < 2) { Usage(); return 1; } // Get the realm details std::string *pRpropertiesTrimmed = new std::string[4]; int idx = 0; std::string RNAME = argv[1]; if (RNAME.length() == 0) { Usage(); return 1; } std::string shell; if (argc > 2) { shell = argv[2]; printf ("***********************************************************\n"); printf ("* *\n"); printf ("* WARNING WARNING WARNING WARNING WARNING WARNING WARNING *\n"); printf ("* This is a sample application demonstrating how to write *\n"); printf ("* a simple nirvana P2P service. This sample is extremely *\n"); printf ("* insecure and should NEVER be run on any production or *\n"); printf ("* secure hosts. The author accepts no liability for any *\n"); printf ("* damage caused *\n"); printf ("* *\n"); printf ("***********************************************************\n"); } char *pCopyRNAME = strdup (RNAME.c_str()); char *pElement = strtok (pCopyRNAME, ","); while (pElement) { std::string prop = pElement; int first = prop.find_first_not_of ("\t "); int last = prop.find_last_not_of ("\t "); if (first != -1) pRpropertiesTrimmed[idx] = prop.substr (first, last - first + 1); idx++; if (idx == 4) break; pElement = strtok (NULL, ", "); } free (pCopyRNAME); m_pSelf = new nP2PShell(pRpropertiesTrimmed, idx, shell); return 0; } nP2PShell(std::string *pRprops, int nProp, std::string& shell) { try { if (pRprops == NULL) return; if (shell.size() != 0) m_bIsServer = true; if (nP2PShell::m_bIsServer) { ShellServer *pServer = new ShellServer(pRprops, nProp, shell); } else { Shell *pShell = new Shell(pRprops, nProp); } } catch (Exception ex) { printf (ex.displayText().c_str()); } } /** * Prints the usage string for this class */ private: static void Usage() { printf("Usage ...\n\n"); printf("nP2PShell [shell]\n\n"); printf(" \n\n"); printf(" - the rname of the server to connect to\n"); printf("\n[Optional Arguments] \n\n"); printf("[shell] - The type of shell you want to offer. For example cmd for win32 or bash for unix, leave out for client\n"); } }; } } } } nP2PShell* nP2PShell::m_pSelf = NULL; bool nP2PShell::m_bIsServer = false; int main (int argc, char** argv) { return nP2PShell::Main (argc, argv); }