Fixed loading of plug ins when multiple plug in class sets used. Especially H.323...
[pwlib.git] / samples / xmlrpcsrvr / main.cxx
blobc1de6cca91da4bbb07538231972fe2704a4eb42b
1 /*
2 * main.cxx
4 * PWLib application source file for xmlrpcsrvr
6 * Main program entry point.
8 * Copyright 2002 Equivalence
10 * $Log$
11 * Revision 1.4 2003/09/26 13:41:32 rjongbloed
12 * Added special test to give more indicative error if try to compile without Expat support.
14 * Revision 1.3 2003/04/17 00:03:23 craigs
15 * Changed default port from 6666 to 8000 to remove conflicts with other programs
16 * that use that port by default
18 * Revision 1.2 2002/10/23 15:58:18 craigs
19 * Fixed problem with parsing requests, and added sample return value
21 * Revision 1.1 2002/10/02 08:58:20 craigs
22 * Initial version
26 #include <ptlib.h>
27 #include "main.h"
28 #include "custom.h"
30 #if !P_EXPAT
31 #error Must have Expat XML support for this application
32 #endif
36 PCREATE_PROCESS(Xmlrpcsrvr);
38 const WORD DefaultHTTPPort = 8000;
41 Xmlrpcsrvr::Xmlrpcsrvr()
42 : PHTTPServiceProcess(ProductInfo)
44 xmlrpcServer = NULL;
48 BOOL Xmlrpcsrvr::OnStart()
50 GetFile().GetDirectory().Change();
52 httpNameSpace.AddResource(new PHTTPDirectory("data", "data"));
53 httpNameSpace.AddResource(new PServiceHTTPDirectory("html", "html"));
55 xmlrpcServer = new PXMLRPCServerResource();
57 xmlrpcServer->SetMethod("Function1", PCREATE_NOTIFIER(FunctionNotifier));
59 return PHTTPServiceProcess::OnStart();
63 void Xmlrpcsrvr::OnStop()
65 PHTTPServiceProcess::OnStop();
67 delete xmlrpcServer;
68 xmlrpcServer = NULL;
73 void Xmlrpcsrvr::OnConfigChanged()
78 void Xmlrpcsrvr::OnControl()
83 PString Xmlrpcsrvr::GetPageGraphic()
85 return Xmlrpcsrvr::GetPageGraphic();
89 void Xmlrpcsrvr::AddUnregisteredText(PHTML &)
94 BOOL Xmlrpcsrvr::Initialise(const char * initMsg)
96 // create the home page
97 static const char welcomeHtml[] = "welcome.html";
98 if (PFile::Exists(welcomeHtml))
99 httpNameSpace.AddResource(new PServiceHTTPFile(welcomeHtml, TRUE), PHTTPSpace::Overwrite);
100 else {
101 PHTML html;
102 html << PHTML::Title("Welcome to "+GetName())
103 << PHTML::Body()
104 << "<CENTER>\r\n"
105 << PHTML::Heading(1) << "Welcome to "
106 << gifHTML
107 << PHTML::Heading(1)
108 << PProcess::GetOSClass() << ' ' << PProcess::GetOSName()
109 << " Version " << GetVersion(TRUE) << PHTML::BreakLine()
110 << ' ' << compilationDate.AsString("d MMMM yy")
111 << PHTML::BreakLine()
112 << "by"
113 << PHTML::BreakLine()
114 << PHTML::Heading(3)
115 << PHTML::HotLink(GetHomePage()) << GetManufacturer() << PHTML::HotLink()
116 << PHTML::Heading(3)
117 << PHTML::HotLink(PString("mailto:")+GetEMailAddress()) << GetEMailAddress() << PHTML::HotLink()
118 << PHTML::Paragraph()
119 << PHTML::HRule()
120 << PHTML::Paragraph()
122 << PHTML::HotLink("http://www.equival.com.au/xmlrpcsrvr/relnotes/" + GetVersion(TRUE) + ".html")
123 << "Release notes" << PHTML::HotLink()
124 << " on this version of " << GetProductName() << " are available."
125 << PHTML::Paragraph()
126 << PHTML::HRule()
127 << GetCopyrightText()
128 << PHTML::Body();
129 httpNameSpace.AddResource(new PServiceHTTPString("welcome.html", html), PHTTPSpace::Overwrite);
132 // note we do NOT use Overwrite
133 httpNameSpace.AddResource(xmlrpcServer);
135 // set up the HTTP port for listening & start the first HTTP thread
136 if (ListenForHTTP(DefaultHTTPPort))
137 PSYSTEMLOG(Info, "Opened master socket for HTTP: " << httpListeningSocket->GetPort());
138 else {
139 PSYSTEMLOG(Fatal, "Cannot run without HTTP port: " << httpListeningSocket->GetErrorText());
140 return FALSE;
143 PSYSTEMLOG(Info, "Service " << GetName() << ' ' << initMsg);
144 return TRUE;
148 void Xmlrpcsrvr::Main()
150 Suspend();
153 void Xmlrpcsrvr::FunctionNotifier(PXMLRPCServerParms & args, INT)
155 PTRACE(1, "XMLRPC function called");
157 PINDEX i;
158 for (i = 0; i < args.request.GetParamCount(); i++) {
159 PStringToString dict;
160 PString type;
161 PString value;
162 if (args.request.GetParam(i, dict))
163 PTRACE(2, "XMLRPC argument " << i << " is struct: " << dict);
164 else if (args.request.GetParam(i, type, value))
165 PTRACE(2, "XMLRPC argument " << i << " is " << type << " with value " << value);
166 else
167 PTRACE(2, "Cannot parse XMLRPC argument " << i);
170 args.response.AddParam("return value");
173 // End of File ///////////////////////////////////////////////////////////////