Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
opendir.c File Reference
#include <sys/types.h>
#include "ONEiiop.h"
#include "rdf.h"

Go to the source code of this file.

Defines

#define PREFIX   "<html><body><a href=\"/\"><center><img src=\"http://directory.mozilla.org/img/opendir.gif\" width=396 height=79 border=\"0\"></center></a>"
#define POSTFIX   "</body><html>"

Functions

int gethostname (char *name, int namelen)
void WriteClient (void *obj, char *buffer)
void AnswerOpenDirQuery (WriteClientProc callBack, void *obj, char *query, char *cookie)
void AnswerSearchQuery (WriteClientProc callBack, void *obj, char *query, char *cookie)
long Run (ServerSession_t obj)
int main (int argc, char **argv)
 The Xalan testcases app.

Define Documentation

#define POSTFIX   "</body><html>"

Definition at line 56 of file opendir.c.

#define PREFIX   "<html><body><a href=\"/\"><center><img src=\"http://directory.mozilla.org/img/opendir.gif\" width=396 height=79 border=\"0\"></center></a>"

Definition at line 54 of file opendir.c.


Function Documentation

void AnswerOpenDirQuery ( WriteClientProc  callBack,
void obj,
char *  query,
char *  cookie 
)

Definition at line 184 of file genopendir.c.

                                                                                    {
  RDF_Resource node = getNodeFromQuery(query);
  size_t n = 0;
  char buff[MAX_TEMPLATE_SIZE];
  char* pbegin = 0;
  char* begin;  
  Init();
  begin = gTemplate;
  while (pbegin = strstr(begin, "&Topic")) {
    memset(buff, '\0', 10000);
    memcpy(buff, begin, pbegin-begin);
    (*callBack)(obj, buff);
    if (startsWith("&TopicName;", pbegin)) {
      outputTopicName(callBack, obj, node);
    } else if (startsWith("&TopicPath;", pbegin)) {
      listParents(callBack, obj, node, 0);
    } else if (startsWith("&TopicSubTopics;", pbegin)) {
      listSubTopics(callBack, obj, node, cookie, gNarrow);
    } else if (startsWith("&TopicItems;", pbegin)) {
      listSubTopics(callBack, obj, node, cookie, gLink);
    } else if (startsWith("&TopicAddURL;", pbegin)) {
      (*callBack)(obj, "http://directory.mozilla.org/cgi-bin/add.cgi?where=");
      (*callBack)(obj, RDF_ResourceID(node));
    } else if (startsWith("&TopicBecomeEditor;", pbegin)) {
      (*callBack)(obj, "http://directory.mozilla.org/cgi-bin/apply.cgi?where=");
      (*callBack)(obj, RDF_ResourceID(node));
    }
    begin = pbegin + (strchr(pbegin, ';') - pbegin) + 1; 

  }
  (*callBack)(obj, begin);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AnswerSearchQuery ( WriteClientProc  callBack,
void obj,
char *  query,
char *  cookie 
)

Definition at line 240 of file genopendir.c.

                                                                                   {
    char      st = cookiePropValue(cookie, "searchTarget");
    RDF_Cursor c = RDFGS_Search(0, query, stToProp(st));
    RDF_Resource topic = RDF_GetResource("Topic", 1);
    RDF_Resource type = RDF_GetResource("type", 1);
    RDF_Resource u ;
    size_t catn = 0;
    size_t itemn = 0;    
    size_t index;
    RDF_Resource* cats = (RDF_Resource*)calloc(MRN+1, sizeof(RDF_Resource));
    RDF_Resource* items =  (RDF_Resource*)calloc(MRN+1, sizeof(RDF_Resource));
    char showDesc = cookiePropValue(cookie, "searchDesc");

    (*callBack)(obj, PREFIX);
    (*callBack)(obj, "<B>Search : ");
    (*callBack)(obj, query);
    (*callBack)(obj, "</B>");

    while ((u = (RDF_Resource) RDFGS_NextValue(c)) && 
           (itemn < MRN-1) && (catn < MRN-1)) {
      if (RDF_HasAssertion(0, u, type, topic, RDF_RESOURCE_TYPE)) {
        cats[catn++] = u;  
      } else {
        items[itemn++] = u;  
      }
    }

    RDFGS_DisposeCursor(c);
    if (catn > 0) {            
      (*callBack)(obj, "<HR><B>Matching Categories :</B><BR>");
      (*callBack)(obj, "<UL>");
      for (index = 0; index < catn ; index++) {
        if (cats[index]) describeCategory(callBack, obj, cats[index]);
      }
      (*callBack)(obj, "</UL>");
    }

    if (itemn > 0) {
      (*callBack)(obj, "<HR><B>Matching Links :</B><BR><UL>");
      for (index = 0; index < itemn ; index++) {
        if (items[index]) {
          if (showDesc == 'n') {
            describeItemSimple(callBack, obj, items[index]);
          } else {
            describeItem(callBack, obj, items[index]);
          }
        } 
      }
      (*callBack)(obj, "</UL>");      
    }

   free(items);
   free(cats);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gethostname ( char *  name,
int  namelen 
)
int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 106 of file opendir.c.

    {
#endif
      char localhost[256];
      char *host;
      RDF_Resource u;
      int n = 2;
      IIOPWebAppService_t obj;
      
      //
       // Normally we expect to see a hostname:port as
             // our one and only argument.  If we are started by
             // the OAD we will see an extra argument which should
             // be ignored.
             // The recommended registration with the OAD should 
       // specify the hostname:port as an argument to the
             // object provider.
             //
             // So try to ferrit out the hostname:port
#ifndef WIN32
             // Easier if we just have a normal main.
                               if (argc > 1){
                                 if (argc == 1)
                                   host = argv[1];
                                 else if (*argv[1] != '-')
                     host = argv[1];

#else
       // Windows command line drops the program name
       // that appears as argv[0].
       // GetCommandLine can be used to retrieve the
       // whole thing.
        n = 1;
       if (lpCmdLine && *lpCmdLine){
              if (*lpCmdLine != '-'){
                     char *sep = strchr(lpCmdLine, ' ');
                     if (sep)
                            *sep = '\0';
                     host = lpCmdLine;
              }
#endif
       }else{
              gethostname(localhost, sizeof(localhost));
              host = localhost;
       }

       //
       // Pass in argc/argv if we have 'em.
#ifndef WIN32
       obj = WAIcreateWebAppService("OpenDir", Run, argc, argv);
#else
       /* obj = WAIcreateWebAppService("OpenDir", Run, 0, 0); */
#endif
/*     WAIregisterService(obj, host); */
        RDF_Initialize();
        printf("RDF Initialized!\n");
        if (argc == 0) {
        char** ans;
        RDF_ReadFile("s1");
        RDF_ReadFile("s2");
              } else {
        while (n < argc) {
           char* name = argv[n++];
             printf("Reading %s\n", name);
             RDF_ReadFile(name);
       }
              }
        printf("done");

       WAIimplIsReady();
    
       return 0;
}

Here is the call graph for this function:

long Run ( ServerSession_t  obj)

Definition at line 59 of file opendir.c.

{
  char* query = (char*) malloc(300);
  char* val;
  char* cookie;
  WAIgetRequestInfo(obj, "QUERY",  &query);  
  WAIgetCookie(obj, &cookie); 

  if (!query) return 0;
  printf("Query = %s. Cookie = %s\n", query, cookie);
  val = strchr(query, '=');
  if (!val) return 0;
  val++;
  *(val -1) = '\0';
  WAIStartResponse(obj);
  /*  WriteClient(obj, PREFIX); */
  
  if (strcmp(query, "browse") == 0) {
    AnswerOpenDirQuery(WriteClient, obj, val, cookie);
  } else if (strcmp(query, "search") == 0) {
    AnswerSearchQuery(WriteClient, obj, val, cookie);
  } else if (strcmp(query, "query") == 0) {
    char** ans = processRDFQuery(val);
    if (ans) {
      int n = 0;
      for (n = 0; ans[n] != 0; n++) {
        WriteClient(obj, ans[n]);
      }
    }
  }
  /*  WriteClient(obj, POSTFIX); */
  return 0;
}

Here is the call graph for this function:

void WriteClient ( void obj,
char *  buffer 
)

Definition at line 46 of file opendir.c.

                                      {
  size_t len = strlen(buffer);
  WAIWriteClient((ServerSession_t)obj, (const unsigned char *) buffer, len);
}

Here is the caller graph for this function: