diff --git a/rdf/opendir/genopendir.c b/rdf/opendir/genopendir.c index a2e9476f4e4f..287171d52b76 100644 --- a/rdf/opendir/genopendir.c +++ b/rdf/opendir/genopendir.c @@ -22,8 +22,8 @@ #include "rdf.h" #include "gs.h" -void -describeItem (WriteClientProc callBack, void* obj, RDF_Resource u) ; +void describeItem (WriteClientProc callBack, void* obj, RDF_Resource u) ; +void describeItemSimple (WriteClientProc callBack, void* obj, RDF_Resource u) ; RDF_Resource getNodeFromQuery (char* query) { @@ -35,11 +35,44 @@ getNodeFromQuery (char* query) { #define ROW_WIDTH 3 -#define PREFIX "
Search:
" +#define PREFIX "Search:


Personalize
" +void +SortResourceList (RDF_Resource* list, size_t n, char sortType) { + if (sortType == 'd') { + } else { + } +} + +void +listParents(WriteClientProc callBack, void* obj, RDF_Resource node, int depth) { + RDF_Resource narrow = RDF_GetResource("narrow", 1); + RDF_Resource parent = RDF_OnePropSource(0, node, narrow); + RDF_Resource name = RDF_GetResource("name", 1); + char* id = RDF_ResourceID(node); + char* nm = (char*) RDF_OnePropValue(0, node, name, RDF_STRING_TYPE); + char* cnm = strrchr(id, '/'); + char buff[500]; + if (!nm || strchr(nm, '/')) nm = (cnm ? cnm + 1 : id); + if ((depth < 10) && parent) listParents(callBack, obj, parent, depth+1); + sprintf(buff, "%s > ", id, nm); + + (*callBack)(obj, buff); +} + +char +cookiePropValue (char* cookie, char* prop) { + size_t len = strlen(prop); + char* str = strstr(cookie, prop); + if (!str) { + return 0; + } else { + return *(str + len + 1); + } +} void -AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) { +AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query, char* cookie) { char buff[1000]; RDF_Resource narrow = RDF_GetResource("narrow", 1); RDF_Resource link = RDF_GetResource("link", 1); @@ -49,22 +82,28 @@ AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) { RDF_Resource editor = RDF_GetResource("editor", 1); RDF_Resource newsGroup = RDF_GetResource("newsGroup", 1); RDF_Resource node = getNodeFromQuery(query); + char widthc = cookiePropValue(cookie, "cols"); + char sort = cookiePropValue(cookie, "sort"); + size_t rw = (widthc ? ((int)widthc - 48) : 3); + + if (!sort) sort = 'D'; if (node) { RDF_Cursor c = RDF_GetTargets(0, node, narrow, RDF_RESOURCE_TYPE); RDF_Resource u = (RDF_Resource) RDF_NextValue(c); (*callBack)(obj, PREFIX); + listParents(callBack, obj, node, 0); if (u) { - (*callBack)(obj, "
"); + (*callBack)(obj, "

"); while (u) { int w = 0; (*callBack)(obj, ""); - while ((w < ROW_WIDTH) && u) { + while ((w < rw) && u) { char* nm = (char*) RDF_OnePropValue(0, u, name, RDF_STRING_TYPE); char* id = RDF_ResourceID(u); - if (!nm) nm = strrchr(id, '/') +1; + if (!nm || strchr(nm, '/')) nm = strrchr(id, '/') +1; sprintf(buff, "", - (100 / ROW_WIDTH), id, (nm ? nm : id)); + (100 / rw), id, (nm ? nm : id)); (*callBack)(obj, buff); w++; u = (RDF_Resource) RDF_NextValue(c); @@ -106,7 +145,7 @@ AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) { (*callBack)(obj, "
Editors:"); while (u) { char* id = RDF_ResourceID(u); - sprintf(buff, "%s, ", id); + sprintf(buff, " %s", id); (*callBack)(obj, buff); u = (RDF_Resource) RDF_NextValue(c); } @@ -117,21 +156,111 @@ AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query) { } + +void describeCategory (WriteClientProc callBack, void* obj, RDF_Resource u) { + char buff[1000]; + sprintf(buff, "
  • %s", RDF_ResourceID(u), + RDF_ResourceID(u)); + (*callBack)(obj, buff); +} + +#define MRN 1000 + +char* +xGetMem (size_t n) { + char* ans = (char*) malloc(n); + if (ans) memset(ans, '\0', n); + return ans; +} + + void -AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query) { - RDF_Cursor c = RDFGS_Search(0, query, 0); +xFreeMem(void* item) { + free(item); +} + +RDF_Resource +stToProp (char c) { + if (!c || (c == 'a')) { + return 0; + } else if (c == 'n') { + return RDF_GetResource("name", 1); + } else if (c == 'd') { + return RDF_GetResource("description", 1); + } else return 0; +} + +void +AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query, char* cookie) { + char st = cookiePropValue(cookie, "searchTarget"); + RDF_Cursor c = RDFGS_Search(0, query, stToProp(st)); RDF_Resource name = RDF_GetResource("name", 1); + RDF_Resource topic = RDF_GetResource("Topic", 1); + RDF_Resource type = RDF_GetResource("type", 1); RDF_Resource u ; - (*callBack)(obj, ""); + + RDFGS_DisposeCursor(c); + if (catn > 0) { + (*callBack)(obj, "
    Matching Categories :
    "); + (*callBack)(obj, ""); + } + + if (itemn > 0) { + (*callBack)(obj, "
    Matching Links :
    "); + } + + xFreeMem(items); + xFreeMem(cats); +} + + +void +describeItemSimple (WriteClientProc callBack, void* obj, RDF_Resource u) { + char buff[5000]; + RDF_Resource name = RDF_GetResource("name", 1); + char* nm = (char*) RDF_OnePropValue(0, u, name, RDF_STRING_TYPE); + char* id = RDF_ResourceID(u); + sprintf(buff, "
  • %s", id, (nm ? nm : id)); + (*callBack)(obj, buff); } void describeItem (WriteClientProc callBack, void* obj, RDF_Resource u) { - char buff[1000]; + char buff[5000]; RDF_Resource name = RDF_GetResource("name", 1); RDF_Resource desc = RDF_GetResource("description", 1); char* nm = (char*) RDF_OnePropValue(0, u, name, RDF_STRING_TYPE); @@ -146,3 +275,7 @@ describeItem (WriteClientProc callBack, void* obj, RDF_Resource u) { + + + + diff --git a/rdf/opendir/gs.c b/rdf/opendir/gs.c index adf34bd64fe1..d6116300bfaf 100644 --- a/rdf/opendir/gs.c +++ b/rdf/opendir/gs.c @@ -47,13 +47,21 @@ typedef TrieTargetStruct* TTS; static TNS gRootNode = 0; -void addTarget (RDFT db, TNS node, RDF_Resource label, RDF_Resource targetNode) { - TTS target = (TTS) fgetMem(sizeof(TrieTargetStruct)); - target->next = node->targets; - node->targets = target; - target->label = label; - target->target = targetNode; - target->db = db; +int +addTarget (RDFT db, TNS node, RDF_Resource label, RDF_Resource targetNode) { + TTS target ; + int n = 0; + /* for (target = node->targets; target != null; target = target->next) { + if (target->target == targetNode) return 0; + n++; + } */ + target = (TTS) fgetMem(sizeof(TrieTargetStruct)); + target->next = node->targets; + node->targets = target; + target->label = label; + target->target = targetNode; + target->db = db; + return n; } TNS @@ -74,8 +82,7 @@ findChildOfString (TNS node, char* str) { while (n < size) { char c = str[n++]; node = findChildOfChar(node, c); - if (!node) - return 0; + if (!node) return 0; } return node; } @@ -83,6 +90,7 @@ findChildOfString (TNS node, char* str) { void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resource target) { size_t size = strlen(string); size_t n = 0; + char* stk = 0; TNS prev, next; if (!gRootNode) gRootNode = (TNS) getMem(sizeof(TrieNodeStruct)); prev = gRootNode; @@ -90,7 +98,7 @@ void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resour while (n < size) { char c = string[n++]; if (!wsCharp(c) && (c != '/')) { - char* str = &string[n-1]; + if (!stk) stk = &string[n-1]; next = (TNS) findChildOfChar(prev, c); if (!next) { next = (TNS)fgetMem(sizeof(TrieNodeStruct)); @@ -100,7 +108,8 @@ void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resour } prev = next; } else if (next) { - addTarget(db, next, label, target); + int n = addTarget(db, next, label, target); + stk = 0; prev = gRootNode; next = 0; } @@ -113,12 +122,14 @@ void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resour } void -countChildren (TNS node, size_t *n) { +countChildren (TNS node, size_t *n, size_t *m) { TNS ch; + TTS tg ; if (node->targets) (*n)++; + for (tg = node->targets; tg; tg = tg->next) (*m)++; ch = node->child; while (ch) { - countChildren(ch, n); + countChildren(ch, n, m); ch = ch->next; } } @@ -138,39 +149,62 @@ fillUpChildren (RDF_Cursor c, TNS node) { RDF_Cursor RDFGS_Search (RDFT db, char* searchString, RDF_Resource label) { RDF_Cursor c = (RDF_Cursor) getMem(sizeof(RDF_CursorStruct)); size_t n = 0; + size_t m = 0; c->searchString = searchString; c->s = label; c->db = db; c->pdata = findChildOfString(gRootNode, searchString); - countChildren((TNS)c->pdata, &n); + if (!c->pdata) return c; + countChildren((TNS)c->pdata, &n, &m); + c->pdata2 = (RDF_Resource*) getMem(sizeof(RDF_Resource) * (m+1)); + c->off1 = m; if (n > 0) { c->count = 0; - c->pdata1 = getMem(n+1); + c->pdata1 = getMem(sizeof(TTS) * (n+1)); fillUpChildren(c, (TNS)c->pdata); c->count = 1; } - if (c->pdata) c->pdata = ((TNS)c->pdata)->targets; + if (c->pdata) c->pdata = ((TNS)c->pdata)->targets; + return c; } void RDFGS_DisposeCursor (RDF_Cursor c) { - freeMem(c); + if (c->pdata1) freeMem(c->pdata1); + if (c->pdata2) freeMem(c->pdata2); + freeMem(c); +} + +int +alreadyAdded(RDF_Resource node, RDF_Cursor c) { + int n =0; + while (c->pdata2[n] && (n < c->off)) { + if (c->pdata2[n] == node) return 1; + n++; + } + return 0; } RDF_Resource RDFGS_NextValue (RDF_Cursor c) { - TTS currentTTS = (TTS) c->pdata; - if (!currentTTS) { + if (!c->pdata) { return 0; } else { + TTS currentTTS = (TTS) c->pdata; while (currentTTS) { - if ((!c->s) || (c->s == currentTTS->label)) { - RDF_Resource ans =currentTTS->target; + if (((!c->s) || (c->s == currentTTS->label)) && + (!alreadyAdded(currentTTS->target, c))) { + RDF_Resource ans = currentTTS->target; c->pdata = currentTTS = currentTTS->next; - if (!currentTTS) c->pdata = currentTTS = ((TTS*)c->pdata1)[c->count++]; + if (!currentTTS && (c->pdata1)) { + c->pdata = ((TTS*)c->pdata1)[c->count++]; + } + if (c->off < c->off1) c->pdata2[c->off++] = ans; return ans; - } + } c->pdata = currentTTS = currentTTS->next; - if (!currentTTS) c->pdata = currentTTS = ((TTS*)c->pdata1)[c->count++]; + if (!currentTTS && (c->pdata1)) { + c->pdata = currentTTS = ((TTS*)c->pdata1)[c->count++]; + } } } return 0; diff --git a/rdf/opendir/opendir.c b/rdf/opendir/opendir.c index 677c28846cb3..9783d4e55f55 100644 --- a/rdf/opendir/opendir.c +++ b/rdf/opendir/opendir.c @@ -29,8 +29,8 @@ WriteClient (void* obj, char* buffer) { WAIWriteClient((ServerSession_t)obj, (const unsigned char *) buffer, len); } -void AnswerOpenDirQuery(WriteClientProc callBack, void* obj, char* query); -void AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query) ; +void AnswerOpenDirQuery(WriteClientProc callBack, void* obj, char* query, char* cookie); +void AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query, char* cookie) ; #define PREFIX "
    " @@ -41,9 +41,12 @@ Run(ServerSession_t obj) { char* query = (char*) malloc(300); char* val; + char* cookie; + WAIgetRequestInfo(obj, "QUERY", &query); + WAIgetCookie(obj, &cookie); - WAIgetRequestInfo(obj, "QUERY", &query); if (!query) return 0; + printf("Query = %s. Cookie = %s\n", query, cookie); val = strchr(query, '='); if (!val) return 0; val++; @@ -52,9 +55,9 @@ Run(ServerSession_t obj) WriteClient(obj, PREFIX); if (strcmp(query, "browse") == 0) { - AnswerOpenDirQuery(WriteClient, obj, val); + AnswerOpenDirQuery(WriteClient, obj, val, cookie); } else if (strcmp(query, "search") == 0) { - AnswerSearchQuery(WriteClient, obj, val); + AnswerSearchQuery(WriteClient, obj, val, cookie); } WriteClient(obj, POSTFIX); return 0; @@ -126,7 +129,7 @@ int main(int argc, char **argv) WAIregisterService(obj, host); RDF_Initialize(); printf("RDF Initialized!\n"); - RDF_ReadFile("two_level"); + RDF_ReadFile(argv[2]); printf("done"); diff --git a/rdf/opendir/rdf-int.h b/rdf/opendir/rdf-int.h index 85f92b966e21..9219bbde652f 100644 --- a/rdf/opendir/rdf-int.h +++ b/rdf/opendir/rdf-int.h @@ -78,9 +78,12 @@ typedef struct _RDF_CursorStruct { void *value; void* pdata; void* pdata1; + RDF_Resource* pdata2; int inversep; RDF_ValueType type; - int count; + size_t count; + size_t off; + size_t off1; RDFT db; QueryType queryType; char* searchString; diff --git a/rdf/opendir/rdf.c b/rdf/opendir/rdf.c index b406ae97dfa8..cc5f7e8a1013 100644 --- a/rdf/opendir/rdf.c +++ b/rdf/opendir/rdf.c @@ -58,6 +58,9 @@ int RDF_HasAssertion (RDFT db, RDF_Resource u, RDF_Resource s, return remoteStoreHasAssertion (db, u, s, v, type, 1); } +RDF_Resource RDF_OnePropSource (RDFT db, RDF_Resource u, RDF_Resource s) { + return (RDF_Resource) getSlotValue(db, u, s, RDF_RESOURCE_TYPE, 1, 1); +} void* RDF_OnePropValue (RDFT db, RDF_Resource u, RDF_Resource s, RDF_ValueType type) { return getSlotValue (db, u, s, type, 0, 1); diff --git a/rdf/opendir/rdf.h b/rdf/opendir/rdf.h index 7b70b02c155a..267f5f2ed638 100644 --- a/rdf/opendir/rdf.h +++ b/rdf/opendir/rdf.h @@ -46,6 +46,7 @@ int RDF_Unassert (RDFT db, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueTy int RDF_HasAssertion (RDFT db, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type); void* RDF_OnePropValue (RDFT db, RDF_Resource u, RDF_Resource s, RDF_ValueType type); +RDF_Resource RDF_OnePropSource (RDFT db, RDF_Resource u, RDF_Resource s); RDF_Cursor RDF_GetTargets (RDFT db, RDF_Resource u, RDF_Resource s, RDF_ValueType type); RDF_Cursor RDF_GetSourcess (RDFT db, RDF_Resource u, RDF_Resource s); void* RDF_NextValue (RDF_Cursor c) ;
  • %s