4 * PWLib application source file for xmlrpcsrvr
6 * Main program entry point.
8 * Copyright 2002 Equivalence
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
31 #error Must have Expat XML support for this application
36 PCREATE_PROCESS(Xmlrpcsrvr
);
38 const WORD DefaultHTTPPort
= 8000;
41 Xmlrpcsrvr::Xmlrpcsrvr()
42 : PHTTPServiceProcess(ProductInfo
)
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();
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
);
102 html
<< PHTML::Title("Welcome to "+GetName())
105 << PHTML::Heading(1) << "Welcome to "
108 << PProcess::GetOSClass() << ' ' << PProcess::GetOSName()
109 << " Version " << GetVersion(TRUE
) << PHTML::BreakLine()
110 << ' ' << compilationDate
.AsString("d MMMM yy")
111 << PHTML::BreakLine()
113 << PHTML::BreakLine()
115 << PHTML::HotLink(GetHomePage()) << GetManufacturer() << PHTML::HotLink()
117 << PHTML::HotLink(PString("mailto:")+GetEMailAddress()) << GetEMailAddress() << PHTML::HotLink()
118 << PHTML::Paragraph()
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()
127 << GetCopyrightText()
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());
139 PSYSTEMLOG(Fatal
, "Cannot run without HTTP port: " << httpListeningSocket
->GetErrorText());
143 PSYSTEMLOG(Info
, "Service " << GetName() << ' ' << initMsg
);
148 void Xmlrpcsrvr::Main()
153 void Xmlrpcsrvr::FunctionNotifier(PXMLRPCServerParms
& args
, INT
)
155 PTRACE(1, "XMLRPC function called");
158 for (i
= 0; i
< args
.request
.GetParamCount(); i
++) {
159 PStringToString dict
;
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
);
167 PTRACE(2, "Cannot parse XMLRPC argument " << i
);
170 args
.response
.AddParam("return value");
173 // End of File ///////////////////////////////////////////////////////////////