mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
More for OpenDir
This commit is contained in:
parent
8edbbe611d
commit
461c2b1e34
@ -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 "<form method=get action=\"OpenDir?\"><B>Search:</B> <input size=25 name=search> <input type=submit value=search><br>"
|
||||
#define PREFIX "<form method=get action=\"OpenDir?\"><B>Search:</B> <input size=25 name=search> <input type=submit value=search><br><BR><BR></form><div align=right><a href=\"/odoptions.html\">Personalize</a></div>"
|
||||
|
||||
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, "<B><a href=\"OpenDir?browse=%s\">%s</a> > </B> ", 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, "<hr><table cellspacing=\"6\" cellpadding=\"6\">");
|
||||
(*callBack)(obj, "<BR><hr><table cellspacing=\"6\" cellpadding=\"6\" width=\"80%\">");
|
||||
while (u) {
|
||||
int w = 0;
|
||||
(*callBack)(obj, "<tr>");
|
||||
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, "<td width=\"%i%\"><li><a href=\"OpenDir?browse=%s\">%s</a></td>",
|
||||
(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, "<hr><b>Editors:</b>");
|
||||
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, "<li><B><a href=\"OpenDir?browse=%s\">%s</a></B>", 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, "<UL>");
|
||||
while (c && (u = (RDF_Resource) RDFGS_NextValue(c))) {
|
||||
describeItem(callBack, obj, u);
|
||||
RDF_Resource* cats = (RDF_Resource*)xGetMem(sizeof(RDF_Resource) * (MRN + 1));
|
||||
RDF_Resource* items = (RDF_Resource*)xGetMem(sizeof(RDF_Resource) * (MRN + 1));;
|
||||
size_t catn = 0;
|
||||
size_t itemn = 0;
|
||||
size_t index;
|
||||
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;
|
||||
}
|
||||
}
|
||||
(*callBack)(obj, "</UL>");
|
||||
|
||||
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>");
|
||||
}
|
||||
|
||||
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, "<li><a href=\"%s\">%s</a>", 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) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 "<html><body><a href=\"/\"><center><img src=\"http://directory.mozilla.org/img/opendir.gif\" width=396 height=79 border=\"0\"></center></a>"
|
||||
|
||||
@ -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");
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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) ;
|
||||
|
Loading…
Reference in New Issue
Block a user