Subject | Re: [Firebird-Architect] Strategic Replacement for Services API |
---|---|
Author | Jim Starkey |
Post date | 2005-07-28T14:55:55Z |
David Jencks wrote:
server:
void AdminServer::server(Socket *serverSocket)
{
socket = serverSocket;
XMLParse parse;
for (;;)
{
Element *response;
JString string = socket->getString();
if (echo)
printf ("%s", (const char*) string);
Element *element = parse.parse (string);
const char *request = element->name;
if (strcmp (request, "Request") == 0)
response = processRequest (element);
else if (strcmp (request, "Login") == 0)
response = login (element);
else
response = genError ("request not understood");
send (response);
delete response;
}
}
Element* AdminServer::processRequest(Element *request)
{
if (!loggedIn)
return genError ("not logged in");
try
{
const char *op = request->getAttributeValue ("operation");
if (!op)
return genError ("illformed request");
if (strcmp (op, "getSiteInfo") == 0)
return getSiteInfo();
if (strcmp (op, "updateDirectory") == 0)
return updateDirectory(request);
if (strcmp (op, "createDirectory") == 0)
return createDirectory(request);
if (strcmp (op, "createUserFile") == 0)
return createUserFile(request);
if (strcmp (op, "addUser") == 0)
return updateUser(request);
if (strcmp (op, "updateUser") == 0)
return updateUser(request);
if (strcmp (op, "deleteUser") == 0)
return updateUser(request);
if (strcmp (op, "restartServer") == 0)
return restartServer(request);
if (strcmp (op, "startServer") == 0)
return startServer(request);
if (strcmp (op, "stopServer") == 0)
return stopServer(request);
if (strcmp (op, "ping") == 0)
return genSuccess();
if (strcmp (op, "createNameVirtualHost") == 0)
return createNameVirtualHost (request);
if (strcmp (op, "updateVirtualHost") == 0)
return updateVirtualHost (request);
if (strcmp (op, "deleteVirtualHost") == 0)
return deleteVirtualHost (request);
return genError ("Unknown request '%s'", op);
}
catch (SQLException& exception)
{
return genError (exception.getText());
}
catch (AdminException& exception)
{
Element *element = genError (exception.getText());
if (exception.lineNumber)
{
JString loc;
loc.Format ("%s:%d", (const char*) exception.fileName,
exception.lineNumber);
element->addAttribute ("line", loc);
}
return element;
}
}
Element* AdminServer::genError(const char *text, ... )
{
va_list args;
va_start (args, text);
char temp [1024];
if (vsnprintf (temp, sizeof (temp) - 1, text, args) < 0)
temp [sizeof (temp) - 1] = 0;
Element *element = new Element ("Error");
element->addAttribute ("text", temp);
return element;
}
Element* AdminServer::genSuccess()
{
return new Element ("Success");
}
That about 90% of the infrastructure.
--
Jim Starkey
Netfrastructure, Inc.
978 526-1376
>Are you thinking of providing a schema for the command and responseI doubt it. Here is the germaine code from the Netfrastructure admin
>structures? How will the extensibility elements fit into the schema?
>IMO schemas are pretty much necessary but the extensibiltiy stuff gets
>hairy quickly.
>
>
server:
void AdminServer::server(Socket *serverSocket)
{
socket = serverSocket;
XMLParse parse;
for (;;)
{
Element *response;
JString string = socket->getString();
if (echo)
printf ("%s", (const char*) string);
Element *element = parse.parse (string);
const char *request = element->name;
if (strcmp (request, "Request") == 0)
response = processRequest (element);
else if (strcmp (request, "Login") == 0)
response = login (element);
else
response = genError ("request not understood");
send (response);
delete response;
}
}
Element* AdminServer::processRequest(Element *request)
{
if (!loggedIn)
return genError ("not logged in");
try
{
const char *op = request->getAttributeValue ("operation");
if (!op)
return genError ("illformed request");
if (strcmp (op, "getSiteInfo") == 0)
return getSiteInfo();
if (strcmp (op, "updateDirectory") == 0)
return updateDirectory(request);
if (strcmp (op, "createDirectory") == 0)
return createDirectory(request);
if (strcmp (op, "createUserFile") == 0)
return createUserFile(request);
if (strcmp (op, "addUser") == 0)
return updateUser(request);
if (strcmp (op, "updateUser") == 0)
return updateUser(request);
if (strcmp (op, "deleteUser") == 0)
return updateUser(request);
if (strcmp (op, "restartServer") == 0)
return restartServer(request);
if (strcmp (op, "startServer") == 0)
return startServer(request);
if (strcmp (op, "stopServer") == 0)
return stopServer(request);
if (strcmp (op, "ping") == 0)
return genSuccess();
if (strcmp (op, "createNameVirtualHost") == 0)
return createNameVirtualHost (request);
if (strcmp (op, "updateVirtualHost") == 0)
return updateVirtualHost (request);
if (strcmp (op, "deleteVirtualHost") == 0)
return deleteVirtualHost (request);
return genError ("Unknown request '%s'", op);
}
catch (SQLException& exception)
{
return genError (exception.getText());
}
catch (AdminException& exception)
{
Element *element = genError (exception.getText());
if (exception.lineNumber)
{
JString loc;
loc.Format ("%s:%d", (const char*) exception.fileName,
exception.lineNumber);
element->addAttribute ("line", loc);
}
return element;
}
}
Element* AdminServer::genError(const char *text, ... )
{
va_list args;
va_start (args, text);
char temp [1024];
if (vsnprintf (temp, sizeof (temp) - 1, text, args) < 0)
temp [sizeof (temp) - 1] = 0;
Element *element = new Element ("Error");
element->addAttribute ("text", temp);
return element;
}
Element* AdminServer::genSuccess()
{
return new Element ("Success");
}
That about 90% of the infrastructure.
>Whatcha got against doing it once in java???? An eclipse plugin wouldUh, 'cause I've used client side Java...
>also see wide use :-)
>
>
>
--
Jim Starkey
Netfrastructure, Inc.
978 526-1376