xmlServer.cxx File Reference

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "xmlServer.h"
#include <TROOT.h>
#include <TClass.h>
#include <TDirectory.h>
#include <TKey.h>
#include <TFolder.h>
#include <TSocket.h>
#include <TServerSocket.h>
#include <TThread.h>
#include <TMessage.h>
#include <TObjString.h>
#include <TH1.h>
#include <TCutG.h>
#include <TBufferXML.h>
#include <deque>
#include <map>
#include <string>
Include dependency graph for xmlServer.cxx:

Go to the source code of this file.

Classes

class  XLockRootGuard

Defines

#define THREADRETURN
#define THREADTYPE   void

Functions

static std::string HtmlEncode (const char *s)
static std::string UrlEncode (const char *s)
static int atohex (int a)
static std::string HtmlDecode (const char *s)
static TObject * FollowPath (TObject *container, char *path)
static TObject * FindTopLevelObject (const char *name)
static TObject * TopLevel (char *path, char **opath)
static TObject * FollowPath (char *path)
static void ResetObject (TObject *obj)
static void SendString (TSocket *sock, const char *str)
static void SendHttpReply (TSocket *sock, const char *mimetype, const char *message)
static void SendHttpReply (TSocket *sock, const char *mimetype, const std::string &str)
static std::string HtmlTag (const char *tag, const char *contents)
static std::string HtmlTag (const char *tag, const std::string &contents)
std::string MakeXmlEntry (const TObject *obj)
std::string MakeHtmlEntry (const TObject *obj, const char *path)
static void SendFile (TSocket *sock, const char *filename, const char *mimetype)
static THREADTYPE xroot_server_thread (void *arg)
static THREADTYPE xsocket_listener (void *arg)

Variables

static bool gVerbose = false
static std::deque< std::string > gExports
static std::map< std::string,
std::string > 
gExportNames

Define Documentation

#define THREADRETURN

Definition at line 21 of file xmlServer.cxx.

#define THREADTYPE   void

Definition at line 22 of file xmlServer.cxx.


Function Documentation

static int atohex ( int  a  )  [static]

Definition at line 120 of file xmlServer.cxx.

Referenced by HtmlDecode().

00121 {
00122    if (a>='0' && a<='9')
00123       return a-'0';
00124    if (a>='a' && a<='f')
00125       return a-'a'+10;
00126    if (a>='A' && a<='F')
00127       return a-'A'+10;
00128    return 0;
00129 }

Here is the caller graph for this function:

static TObject* FindTopLevelObject ( const char *  name  )  [static]

Definition at line 201 of file xmlServer.cxx.

Referenced by TopLevel(), and xroot_server_thread().

00202 {
00203    TObject *obj = NULL;
00204    //gROOT->GetListOfFiles()->Print();
00205    obj = gROOT->GetListOfFiles()->FindObject(name);
00206    if (obj)
00207       return obj;
00208    obj = gROOT->FindObjectAny(name);
00209    if (obj)
00210       return obj;
00211    return NULL;
00212 }

Here is the caller graph for this function:

static TObject* FollowPath ( char *  path  )  [static]

Definition at line 260 of file xmlServer.cxx.

References FollowPath(), and TopLevel().

00261 {
00262   if (0)
00263     printf("Follow path [%s]\n", path);
00264 
00265   char *s;
00266   TObject *obj = TopLevel(path, &s);
00267 
00268   if (!obj)
00269     return NULL;
00270 
00271   if (!s)
00272     return obj;
00273 
00274   return FollowPath(obj, s);
00275 }

Here is the call graph for this function:

static TObject* FollowPath ( TObject *  container,
char *  path 
) [static]

Definition at line 156 of file xmlServer.cxx.

References HtmlDecode().

00157 {
00158   if (0)
00159     printf("Follow path [%s] in container %p\n", path, container);
00160 
00161   while (1)
00162     {
00163       while (*path == '/')
00164         path++;
00165 
00166       char* s = strchr(path,'/');
00167 
00168       if (s)
00169         *s = 0;
00170 
00171       TObject *obj = NULL;
00172 
00173       std::string xpath = HtmlDecode(path);
00174       //printf("FindObject %s, decoded [%s]\n", path, xpath.c_str());
00175 
00176       if (container->InheritsFrom(TDirectory::Class()))
00177         obj = ((TDirectory*)container)->FindObject(xpath.c_str());
00178       else if (container->InheritsFrom(TFolder::Class()))
00179         obj = ((TFolder*)container)->FindObject(xpath.c_str());
00180       else if (container->InheritsFrom(TCollection::Class()))
00181         obj = ((TCollection*)container)->FindObject(xpath.c_str());
00182       else
00183         {
00184           fprintf(stderr, "XmlServer: ERROR: Container \'%s\' of type %s is not a TDirectory, TFolder or TCollection\n", container->GetName(), container->IsA()->GetName());
00185           return NULL;
00186         }
00187 
00188       if (!obj)
00189         return NULL;
00190 
00191       if (!s)
00192         return obj;
00193 
00194       container = obj;
00195 
00196       path = s+1;
00197     }
00198   /* NOT REACHED */
00199 }

Here is the call graph for this function:

static std::string HtmlDecode ( const char *  s  )  [static]

Definition at line 131 of file xmlServer.cxx.

References atohex().

Referenced by FollowPath(), TopLevel(), and xroot_server_thread().

00132 {
00133    std::string r;
00134    while (*s) {
00135       if (*s == '%') {
00136          s++;
00137          char c = 0;
00138          c = c*16 + atohex(s[0]);
00139          c = c*16 + atohex(s[1]);
00140          r += c;
00141 
00142          // be careful when incrementing "s" to not overrun the '\0' string terminator!
00143          if (*s)
00144             s++;
00145          if (*s)
00146             s++;
00147       } else {
00148          r += *s++;
00149       }
00150    }
00151    return r;
00152 }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string HtmlEncode ( const char *  s  )  [static]

Definition at line 82 of file xmlServer.cxx.

Referenced by MakeXmlEntry(), and xroot_server_thread().

00083 {
00084    std::string r;
00085    while (*s) {
00086       char c = *s;
00087       if (c == '<') {
00088          r += "&lt;";
00089       } else if (c == '>') {
00090          r += "&gt;";
00091       } else if (c == '&') {
00092          r += "&amp;";
00093       } else {
00094          r += c;
00095       }
00096       s++;
00097    }
00098    return r;
00099 }

Here is the caller graph for this function:

static std::string HtmlTag ( const char *  tag,
const std::string &  contents 
) [static]

Definition at line 351 of file xmlServer.cxx.

00352 {
00353    std::string s;
00354    s += "<";
00355    s += tag;
00356    s += ">";
00357    s += contents;
00358    s += "</";
00359    s += tag;
00360    s += ">";
00361    return s;
00362 }

static std::string HtmlTag ( const char *  tag,
const char *  contents 
) [static]

Definition at line 338 of file xmlServer.cxx.

Referenced by MakeXmlEntry(), and xroot_server_thread().

00339 {
00340    std::string s;
00341    s += "<";
00342    s += tag;
00343    s += ">";
00344    s += contents;
00345    s += "</";
00346    s += tag;
00347    s += ">";
00348    return s;
00349 }

Here is the caller graph for this function:

std::string MakeHtmlEntry ( const TObject *  obj,
const char *  path 
)

Definition at line 398 of file xmlServer.cxx.

References UrlEncode().

Referenced by xroot_server_thread().

00399 {
00400    const char* objname = obj->GetName();
00401    const char* classname = obj->ClassName();
00402    bool isKey = false;
00403 
00404    if (obj->InheritsFrom(TKey::Class())) {
00405       TKey* key = (TKey*)obj;
00406       classname = key->GetClassName();
00407       isKey = true;
00408    }
00409 
00410    std::string s;
00411 
00412    s += "<a href=\"";
00413    s += path; //dir->GetName();
00414    s += "/";
00415    s += UrlEncode(objname);
00416    s += "\">";
00417    s += objname;
00418    s += "</a>\n";
00419    s += " (";
00420    s += classname;
00421    s += ")";
00422    if (isKey)
00423       s += "-KEY";
00424    s += " ";
00425    s += "<a href=\"";
00426    s += path; //dir->GetName();
00427    s += "/";
00428    s += UrlEncode(objname);
00429    s += ".xml";
00430    s += "\">";
00431    s += "XML</a>\n";
00432 
00433    return s;
00434 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string MakeXmlEntry ( const TObject *  obj  ) 

Definition at line 366 of file xmlServer.cxx.

References HtmlEncode(), and HtmlTag().

Referenced by xroot_server_thread().

00367 {
00368    const char* objname = obj->GetName();
00369    const char* classname = obj->ClassName();
00370    bool isSubdir = false;
00371    std::string xkey = "";
00372 
00373    if (obj->InheritsFrom(TKey::Class())) {
00374       TKey* key = (TKey*)obj;
00375       classname = key->GetClassName();
00376       xkey = "<key/>";
00377    }
00378 
00379    const TClass *xclass = TClass::GetClass(classname);
00380 
00381    if (xclass->InheritsFrom(TDirectory::Class()))
00382       isSubdir = true;
00383 
00384    if (xclass->InheritsFrom(TFolder::Class()))
00385       isSubdir = true;
00386 
00387    if (xclass->InheritsFrom(TCollection::Class()))
00388       isSubdir = true;
00389 
00390    //printf("xclass %s, classname %s, subdir %d\n", xclass->GetName(), classname, isSubdir);
00391 
00392    if (isSubdir)
00393       return HtmlTag("subdir", HtmlTag("name", HtmlEncode(objname)) + HtmlTag("class", HtmlEncode(classname)) + xkey) + "\n";
00394    else
00395       return HtmlTag("object", HtmlTag("name", HtmlEncode(objname)) + HtmlTag("class", HtmlEncode(classname)) + xkey) + "\n";
00396 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void ResetObject ( TObject *  obj  )  [static]

Definition at line 279 of file xmlServer.cxx.

References TDirectory::GetList(), and gVerbose.

Referenced by xroot_server_thread().

00280 {
00281   assert(obj!=NULL);
00282 
00283   if (gVerbose)
00284     printf("ResetObject object %p name [%s] type [%s]\n", obj, obj->GetName(), obj->IsA()->GetName());
00285 
00286   if (obj->InheritsFrom(TH1::Class()))
00287     {
00288       ((TH1*)obj)->Reset();
00289     }
00290   else if (obj->InheritsFrom(TDirectory::Class()))
00291     {
00292       TDirectory* dir = (TDirectory*)obj;
00293       TList* objs = dir->GetList();
00294 
00295       TIter next = objs;
00296       while(1)
00297         {
00298           TObject *obj = next();
00299           if (obj == NULL)
00300             break;
00301           ResetObject(obj);
00302         }
00303     }
00304 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void SendFile ( TSocket *  sock,
const char *  filename,
const char *  mimetype 
) [static]

Definition at line 438 of file xmlServer.cxx.

References SendHttpReply().

Referenced by xroot_server_thread().

00439 {
00440    std::string f = filename;
00441    std::string reply;
00442    FILE *fp = fopen(f.c_str(), "r");
00443    if (!fp) {
00444       std::string home = getenv("HOME");
00445       f = home + "/packages/rootana/libXmlServer/" + filename;
00446       fp = fopen(f.c_str(), "r");
00447    }
00448    printf("sending file %s, fp %p\n", f.c_str(), fp);
00449    if (fp) {
00450       while (1) {
00451          char buf[1024+1];
00452          int rd = fread(buf, 1, sizeof(buf)-1, fp);
00453          if (rd <= 0)
00454             break;
00455          buf[rd] = 0;
00456          reply += buf;
00457       }
00458       fclose(fp);
00459    }
00460    SendHttpReply(sock, mimetype, reply);
00461 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void SendHttpReply ( TSocket *  sock,
const char *  mimetype,
const std::string &  str 
) [static]

Definition at line 331 of file xmlServer.cxx.

References SendHttpReply().

00332 {
00333    SendHttpReply(sock, mimetype, str.c_str());
00334 }

Here is the call graph for this function:

static void SendHttpReply ( TSocket *  sock,
const char *  mimetype,
const char *  message 
) [static]

Definition at line 313 of file xmlServer.cxx.

References SendString().

Referenced by SendFile(), SendHttpReply(), and xroot_server_thread().

00314 {
00315    char buf[256];
00316    int len = strlen(message);
00317    SendString(sock, "HTTP/1.1 200 OK\n");
00318    //SendString(sock, "Date: Tue, 15 May 2012 16:50:31 GMT\n");
00319    SendString(sock, "Server: ROOTANA xmlServer\n");
00320    sprintf(buf, "Content-Length: %d\n", len);
00321    SendString(sock, buf);
00322    //Connection: close\n
00323    sprintf(buf, "Content-Type: %s\n", mimetype);
00324    SendString(sock, buf);
00325    //charset=iso-8859-1\n
00326    SendString(sock, "\n");
00327    SendString(sock, message);
00328    printf("XmlServer: Reply content-length %d, content-type %s\n", len, mimetype);
00329 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void SendString ( TSocket *  sock,
const char *  str 
) [static]

Definition at line 308 of file xmlServer.cxx.

Referenced by SendHttpReply().

00309 {
00310    sock->SendRaw(str, strlen(str));
00311 }

Here is the caller graph for this function:

static TObject* TopLevel ( char *  path,
char **  opath 
) [static]

Definition at line 214 of file xmlServer.cxx.

References FindTopLevelObject(), gExportNames, gExports, and HtmlDecode().

Referenced by FollowPath().

00215 {
00216   if (0)
00217     printf("Extract top level object from [%s]\n", path);
00218 
00219   while (*path == '/')
00220     path++;
00221 
00222   char* s = strchr(path,'/');
00223   
00224   if (s)
00225     {
00226       *s = 0;
00227       *opath = s+1;
00228     }
00229   else
00230     {
00231       *opath = NULL;
00232     }
00233 
00234   std::string xpath = HtmlDecode(path);
00235 
00236   TObject *obj = NULL;
00237 
00238   for (unsigned int i=0; i<gExports.size(); i++)
00239     {
00240       const char* ename = gExports[i].c_str();
00241       //printf("Compare [%s] and [%s]\n", xpath.c_str(), ename);
00242       if (strcmp(xpath.c_str(), ename) == 0)
00243         {
00244           const char* xname = gExportNames[ename].c_str();
00245           obj = FindTopLevelObject(xname);
00246           //printf("Lookup of [%s] returned %p\n", xname, obj);
00247           break;
00248         }
00249     }
00250 
00251   if (!obj)
00252     {
00253       fprintf(stderr, "XmlServer: ERROR: Top level object \'%s\' not found in exports list\n", xpath.c_str());
00254       return NULL;
00255     }
00256 
00257   return obj;
00258 }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string UrlEncode ( const char *  s  )  [static]

Definition at line 101 of file xmlServer.cxx.

Referenced by MakeHtmlEntry(), and xroot_server_thread().

00102 {
00103    std::string r;
00104    while (*s) {
00105       char c = *s;
00106       if (isalpha(c)) {
00107          r += c;
00108       } else if (isdigit(c)) {
00109          r += c;
00110       } else {
00111          char buf[16];
00112          sprintf(buf, "%%%02x", c);
00113          r += buf;
00114       }
00115       s++;
00116    }
00117    return r;
00118 }

Here is the caller graph for this function:

static THREADTYPE xroot_server_thread ( void *  arg  )  [static]

Definition at line 465 of file xmlServer.cxx.

References FindTopLevelObject(), FollowPath(), TDirectory::GetList(), TDirectory::GetListOfKeys(), gExportNames, gExports, gVerbose, HtmlDecode(), HtmlEncode(), HtmlTag(), MakeHtmlEntry(), MakeXmlEntry(), ResetObject(), SendFile(), SendHttpReply(), THREADRETURN, XLockRootGuard::Unlock(), and UrlEncode().

Referenced by xsocket_listener().

00469 {
00470    char request[2560];
00471 
00472    TSocket *sock = (TSocket *) arg;
00473    //TMessage message(kMESS_OBJECT);
00474 
00475    do {
00476 
00477       /* close connection if client has disconnected */
00478       int rd = sock->RecvRaw(request, sizeof(request), kDontBlock); // (ESendRecvOptions)-1);
00479       if (rd <= 0)
00480         {
00481           if (gVerbose)
00482             fprintf(stderr, "XmlServer: connection from %s closed\n", sock->GetInetAddress().GetHostName());
00483           sock->Close();
00484           delete sock;
00485           return THREADRETURN;
00486         }
00487 
00488       if (1) {
00489          char *p;
00490          p = strchr(request, '\n');
00491          if (p)
00492             *p = 0;
00493          
00494          p = strchr(request, '\r');
00495          if (p)
00496             *p = 0;
00497       }
00498          
00499       if (gVerbose)
00500         printf("XmlServer: Request [%s] from %s\n", request, sock->GetInetAddress().GetHostName());
00501 
00502       if (0) {} 
00503       else if (strstr(request, "GET / "))
00504         {
00505           // enumerate top level exported directories
00506 
00507           XLockRootGuard lock;
00508           
00509           std::string reply;
00510 
00511           reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00512           reply += HtmlTag("title", "Export list") + "\n";
00513           reply += "</head><body>\n";
00514           reply += HtmlTag("h1", "Export list") + "\n";
00515 
00516           for (unsigned int i=0; i<gExports.size(); i++) {
00517              const char* ename = gExports[i].c_str();
00518              const char* xname = gExportNames[ename].c_str();
00519              
00520              TObject* obj = FindTopLevelObject(xname);
00521              
00522              if (obj) {
00523                 std::string s;
00524                 s += " ";
00525                 s += "<a href=\"";
00526                 s += UrlEncode(ename);
00527                 s += "\">";
00528                 s += ename;
00529                 s += "</a>\n";
00530                 s += "<a href=\"";
00531                 s += UrlEncode(ename);
00532                 s += ".xml";
00533                 s += "\">";
00534                 s += "XML</a>\n";
00535                 reply += HtmlTag("p", s) + "\n";
00536              } else {
00537                 std::string s;
00538                 s += ename;
00539                 s += " (cannot be found. maybe deleted?)\n";
00540                 reply += HtmlTag("p", s) + "\n";
00541              }
00542           }
00543           
00544           lock.Unlock();
00545 
00546           reply += "</body></html>\n";
00547           SendHttpReply(sock, "text/html", reply);
00548         }
00549       //else if (strstr(request, "GET /plot.html "))
00550       //  {
00551       //    SendFile(sock, "plot.html", "text/html");
00552       //  }
00553       else if (strstr(request, "js/jquery.min.js "))
00554         {
00555           SendFile(sock, "jquery.min.js", "text/javascript");
00556         }
00557       else if (strstr(request, "js/highcharts.js "))
00558         {
00559           SendFile(sock, "highcharts.js", "text/javascript");
00560         }
00561       else if (strstr(request, "js/exporting.js "))
00562         {
00563           SendFile(sock, "exporting.js", "text/javascript");
00564         }
00565       else if (strstr(request, "GET /favicon.ico "))
00566         {
00567           std::string reply;
00568 
00569           reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00570           reply += HtmlTag("title", "No favicon") + "\n";
00571           reply += "</head><body>\n";
00572           reply += HtmlTag("h1", "No favicon") + "\n";
00573           reply += HtmlTag("p", "No favicon") + "\n";
00574           reply += "</body></html>\n";
00575           SendHttpReply(sock, "text/html", reply);
00576         }
00577       else if (strstr(request, "GET /index.xml "))
00578         {
00579           // enumerate top level exported directories
00580 
00581           XLockRootGuard lock;
00582 
00583           std::string xml;
00584 
00585           xml += "<xml>\n";
00586           xml += "<dir>\n";
00587           
00588           for (unsigned int i=0; i<gExports.size(); i++)
00589             {
00590               const char* ename = gExports[i].c_str();
00591               const char* xname = gExportNames[ename].c_str();
00592 
00593               TObject* obj = FindTopLevelObject(xname);
00594 
00595               if (!obj) {
00596                  xml += HtmlTag("subdir", HtmlTag("name", HtmlEncode(ename)) + "<deleted/>") + "\n";
00597                  continue;
00598               }
00599 
00600               const char* cname = obj->ClassName();
00601 
00602               xml += HtmlTag("subdir", HtmlTag("name", HtmlEncode(ename)) + HtmlTag("class", HtmlEncode(cname))) + "\n";
00603             }
00604           
00605           lock.Unlock();
00606 
00607           xml += "</dir>\n";
00608           xml += "</xml>\n";
00609 
00610           SendHttpReply(sock, "application/xml", xml);
00611         }
00612       else if (strncmp(request, "GET /", 5) == 0)
00613         {
00614           XLockRootGuard lock;
00615 
00616           char* dirname = request + 5;
00617 
00618           char* x = strstr(dirname, " HTTP");
00619           if (x)
00620              *x = 0;
00621 
00622           bool xmlOutput = false;
00623 
00624           x = strstr(dirname, ".xml");
00625           if (x) {
00626              *x = 0;
00627              xmlOutput = true;
00628           }
00629 
00630           std::string path;
00631           path += "/";
00632           path += dirname;
00633 
00634           std::string xpath = HtmlDecode(dirname);
00635 
00636           //printf("path [%s] dirname [%s] xpath [%s]\n", path.c_str(), dirname, xpath.c_str());
00637 
00638           TObject* obj = FollowPath(dirname);
00639 
00640           if (!obj) {
00641              std::string reply;
00642              std::string buf;
00643              
00644              reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00645 
00646              buf = "Not found ";
00647              buf += xpath;
00648              reply += HtmlTag("title", buf) + "\n";
00649              reply += "</head><body>\n";
00650              reply += HtmlTag("h1", buf) + "\n";
00651              
00652              reply += HtmlTag("p", "Object not found");
00653 
00654              reply += "</body></html>\n";
00655              SendHttpReply(sock, "text/html", reply);
00656 
00657           } else if (obj && obj->InheritsFrom(TDirectory::Class())) {
00658              TDirectory* dir = (TDirectory*)obj;
00659 
00660              std::string reply;
00661              std::string buf;
00662              std::string xml;
00663 
00664              xml += "<xml>\n";
00665              xml += "<dir>\n";
00666              
00667              reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00668 
00669              buf = "Dir ";
00670              buf += xpath;
00671              reply += HtmlTag("title", buf) + "\n";
00672              reply += "</head><body>\n";
00673              reply += HtmlTag("h1", buf) + "\n";
00674 
00675              //printf("Directory %p\n", dir);
00676              //dir->Print();
00677 
00678              std::map<std::string, std::string> alist;
00679 
00680              if (1) {
00681                 TList* keys = dir->GetListOfKeys();
00682 
00683                 //printf("Directory %p keys:\n", dir);
00684                 //keys->Print();
00685              
00686                 TIter next = keys;
00687                 while(1) {
00688                    TObject *obj = next();
00689                    
00690                    //printf("object %p\n", obj);
00691                    
00692                    if (obj == NULL)
00693                       break;
00694 
00695                    std::string a = HtmlTag("p", MakeHtmlEntry(obj, path.c_str())) + "\n";
00696                    //alist[objname] = a;
00697                    reply += a;
00698                    
00699                    xml += MakeXmlEntry(obj);
00700                 }
00701              }
00702 
00703              if (1) {
00704                 TList* objs = dir->GetList();
00705              
00706                 //printf("Directory %p objects:\n", dir);
00707                 //objs->Print();
00708                 
00709                 TIter next = objs;
00710                 while(1)
00711                    {
00712                       TObject *obj = next();
00713                       
00714                       //printf("object %p\n", obj);
00715                       
00716                       if (obj == NULL)
00717                          break;
00718                       
00719                       std::string a = HtmlTag("p", MakeHtmlEntry(obj, path.c_str())) + "\n";
00720                       //alist[objname] = a;
00721                       reply += a;
00722 
00723                       xml += MakeXmlEntry(obj);
00724                    }
00725              }
00726                 
00727              lock.Unlock();
00728              
00729              if (1) {
00730                 std::map<std::string, std::string>::iterator iter = alist.begin();
00731                 for (; iter!=alist.end(); iter++) {
00732                    // iter->first is your key
00733                    // iter->second is it''s value
00734                    reply += iter->second;
00735                 }
00736              }
00737               
00738              reply += "</body></html>\n";
00739 
00740              xml += "</dir></xml>\n";
00741 
00742              if (xmlOutput)
00743                 SendHttpReply(sock, "application/xml", xml);
00744              else
00745                 SendHttpReply(sock, "text/html", reply);
00746              
00747           } else if (obj && obj->InheritsFrom(TFolder::Class())) {
00748              TFolder* folder = (TFolder*)obj;
00749 
00750              //printf("Folder %p\n", folder);
00751              //folder->Print();
00752 
00753              std::string xml;
00754 
00755              xml += "<xml>\n";
00756              xml += "<dir>\n";
00757              
00758              std::string reply;
00759              std::string buf;
00760              
00761              reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00762 
00763              buf = "Folder ";
00764              buf += xpath;
00765              reply += HtmlTag("title", buf) + "\n";
00766              reply += "</head><body>\n";
00767              reply += HtmlTag("h1", buf) + "\n";
00768              
00769              TIterator *iterator = folder->GetListOfFolders()->MakeIterator();
00770              
00771              while (1)
00772                 {
00773                    TNamed *obj = (TNamed*)iterator->Next();
00774                    if (obj == NULL)
00775                       break;
00776                    
00777                    reply += HtmlTag("p", MakeHtmlEntry(obj, path.c_str())) + "\n";
00778                    xml += MakeXmlEntry(obj);
00779                 }
00780              
00781              delete iterator;
00782 
00783              lock.Unlock();
00784 
00785              xml += "</dir></xml>\n";
00786              reply += "</body></html>\n";
00787 
00788              if (xmlOutput)
00789                 SendHttpReply(sock, "application/xml", xml);
00790              else
00791                 SendHttpReply(sock, "text/html", reply);
00792 
00793           } else if (obj && obj->InheritsFrom(TCollection::Class())) {
00794              TCollection* collection = (TCollection*)obj;
00795              
00796              //printf("Collection %p\n", collection);
00797              //collection->Print();
00798              //printf("Entries %d\n", collection->GetEntries());
00799              //printf("IsEmpty %d\n", collection->IsEmpty());
00800              
00801              std::string xml;
00802 
00803              xml += "<xml>\n";
00804              xml += "<dir>\n";
00805              
00806              std::string reply;
00807              std::string buf;
00808              
00809              reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00810 
00811              buf = "Collection ";
00812              buf += xpath;
00813              reply += HtmlTag("title", buf) + "\n";
00814              reply += "</head><body>\n";
00815              reply += HtmlTag("h1", buf) + "\n";
00816              
00817              TIterator *iterator = collection->MakeIterator();
00818              
00819              while (1)
00820                 {
00821                    TNamed *obj = (TNamed*)iterator->Next();
00822                    if (obj == NULL)
00823                       break;
00824                    
00825                    reply += HtmlTag("p", MakeHtmlEntry(obj, path.c_str())) + "\n";
00826                    xml += MakeXmlEntry(obj);
00827                 }
00828              
00829              delete iterator;
00830 
00831              lock.Unlock();
00832              
00833              xml += "</dir></xml>\n";
00834              reply += "</body></html>\n";
00835 
00836              if (xmlOutput)
00837                 SendHttpReply(sock, "application/xml", xml);
00838              else
00839                 SendHttpReply(sock, "text/html", reply);
00840 
00841           } else {
00842              if (xmlOutput) {
00843                 std::string xml;
00844                 xml += "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
00845                 xml += "<xml>\n";
00846                 xml += "<ROOTobject>\n";
00847                 TString msg = TBufferXML::ConvertToXML(obj);
00848                 xml += msg;
00849                 xml += "</ROOTobject>\n";
00850                 xml += "</xml>\n";
00851                 lock.Unlock();
00852                 SendHttpReply(sock, "application/xml", xml);
00853              } else {
00854                 SendFile(sock, "plot.html", "text/html");
00855                 if (0) {
00856                 std::string reply;
00857                 std::string buf;
00858                 
00859                 reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00860                 
00861                 buf = "Object ";
00862                 buf += xpath;
00863                 reply += HtmlTag("title", buf) + "\n";
00864                 reply += "</head><body>\n";
00865                 reply += HtmlTag("h1", buf) + "\n";
00866                 
00867                 reply += HtmlTag("p", obj->GetName());
00868                 reply += HtmlTag("p", obj->ClassName());
00869                 
00870                 reply += "</body></html>\n";
00871                 SendHttpReply(sock, "text/html", reply);
00872                 }
00873              }
00874           }
00875         }
00876 #if 0
00877       else if (strncmp(request, "ResetTH1 ", 9) == 0)
00878         {
00879           XLockRootGuard lock;
00880           
00881           char* path = request + 9;
00882 
00883           if (strlen(path) > 1)
00884             {
00885               TObject *obj = FollowPath(path);
00886 
00887               if (obj)
00888                 ResetObject(obj);
00889             }
00890           else
00891             {
00892               for (unsigned int i=0; i<gExports.size(); i++)
00893                 {
00894                   const char* ename = gExports[i].c_str();
00895                   const char* xname = gExportNames[ename].c_str();
00896 
00897                   TObject* obj = FindTopLevelObject(xname);
00898 
00899                   if (!obj)
00900                     {
00901                       fprintf(stderr, "XmlServer: ResetTH1: Exported name \'%s\' cannot be found!\n", xname);
00902                       continue;
00903                     }
00904 
00905                   ResetObject(obj);
00906                 }
00907             }
00908           
00909           //TObjString s("Success");
00910 
00911           //message.Reset(kMESS_OBJECT);
00912           //message.WriteObject(&s);
00913           lock.Unlock();
00914           //sock->Send(message);
00915 
00916           const char *msg = "Success";
00917           sock->SendRaw(msg, strlen(msg) + 1);
00918         }
00919 #endif
00920       else
00921         {
00922           fprintf(stderr, "XmlServer: Received unknown request \"%s\"\n", request);
00923 
00924           std::string reply;
00925           reply += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n";
00926           reply += HtmlTag("title", "Unknown request") + "\n";
00927           reply += "</head><body>\n";
00928           reply += HtmlTag("h1", "Unknown request") + "\n";
00929           reply += HtmlTag("p", request) + "\n";
00930           reply += "</body></html>\n";
00931           SendHttpReply(sock, "text/html", reply);
00932         }
00933    } while (1);
00934 
00935    return THREADRETURN;
00936 }

Here is the call graph for this function:

Here is the caller graph for this function:

static THREADTYPE xsocket_listener ( void *  arg  )  [static]

Definition at line 940 of file xmlServer.cxx.

References gVerbose, THREADRETURN, and xroot_server_thread().

Referenced by XmlServer::Start().

00941 {
00942   // Server loop listening for incoming network connections on specified port.
00943   // Starts a searver_thread for each connection.
00944 
00945   int port = *(int *) arg;
00946   
00947   fprintf(stderr, "XmlServer: Listening on port %d...\n", port);
00948   TServerSocket *lsock = new TServerSocket(port, kTRUE);
00949   
00950   while (1)
00951     {
00952       TSocket *sock = lsock->Accept();
00953       
00954       if (sock==NULL)
00955         {
00956           fprintf(stderr, "XmlServer: TSocket->Accept() error\n");
00957           break;
00958         }
00959       
00960       if (gVerbose)
00961         fprintf(stderr, "XmlServer: connection from %s\n", sock->GetInetAddress().GetHostName());
00962       
00963 #if 1
00964       TThread *thread = new TThread("XmlServer", xroot_server_thread, sock);
00965       thread->Run();
00966 #else
00967       LPDWORD lpThreadId = 0;
00968       CloseHandle(CreateThread(NULL, 1024, &xroot_server_thread, sock, 0, lpThreadId));
00969 #endif
00970     }
00971   
00972   return THREADRETURN;
00973 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

std::map<std::string,std::string> gExportNames [static]

Definition at line 78 of file xmlServer.cxx.

Referenced by XmlServer::Export(), TopLevel(), and xroot_server_thread().

std::deque<std::string> gExports [static]

Definition at line 77 of file xmlServer.cxx.

Referenced by XmlServer::Export(), TopLevel(), and xroot_server_thread().

bool gVerbose = false [static]

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1