void PNode_setPathsFromPid(PNode *self) { Datum_copy_(self->sizePath, self->pid); Datum_appendCString_(self->sizePath, "/m/size"); Datum_copy_(self->pidPath, self->pid); Datum_appendCString_(self->pidPath, "/s/"); }
int PNode_amGraphKey_(PNode *self, Datum *title, Datum *graphKey, Datum *d) { PQuery *q = PNode_startQuery(self); PNode *tmpNode = PDB_allocNode(self->pdb); Datum *k; Datum_appendCString_(d, "<graph gid=\""); if(title) Datum_append_(d, title); Datum_appendCString_(d, "-"); Datum_append_(d, graphKey); Datum_appendCString_(d, "\" title=\""); if(title) { Datum_append_(d, title); } else { Datum_append_(d, graphKey); } Datum_appendCString_(d, "\" balloon_text=\"{value} "); if(title) { Datum_append_(d, title); } else { //Datum_appendCString_(d, "-"); Datum_append_(d, graphKey); } Datum_appendCString_(d, "\" bullet=\"round"); Datum_appendCString_(d, "\">\n"); while (k = PQuery_key(q)) { //if(Datum_beginsWithCString_(k, "_")) { Datum *v = PNode_value(self); Datum_appendCString_(d, "<value xid=\""); Datum_append_(d, k); Datum_appendCString_(d, "\">"); if(v) { PNode_setPid_(tmpNode, v); v = PNode_at_(tmpNode, graphKey); if (v) Datum_append_(d, v); } Datum_appendCString_(d, "</value>\n"); } PQuery_enumerate(q); } Datum_appendCString_(d, "</graph>\n"); return 0; }
int VertexServer_api_backup(VertexServer *self) { int result = VertexServer_backup(self); if(result) { Datum_appendCString_(self->result, "backup failed"); } else { Datum_appendCString_(self->result, "backup successful"); } return result; // move to this once backups are integrated with gc //return VertexServer_VertexServer_api_collectGarbage(self); }
Datum *PNode_metaSlotFor_(PNode *self, Datum *key) { Datum *d = Datum_poolNew(); Datum_copy_(d, self->pid); Datum_appendCString_(d, "/m/"); Datum_append_(d, key); return d; }
int VertexServer_api_ampie(VertexServer *self) { Datum *slot1 = HttpRequest_queryValue_(self->httpRequest, "slot1"); //Datum *slot2 = HttpRequest_queryValue_(self->httpRequest, "slot2"); //Datum *slot3 = HttpRequest_queryValue_(self->httpRequest, "slot3"); //Datum *subpath = HttpRequest_queryValue_(self->httpRequest, "subpath"); PNode *node = PDB_allocNode(self->pdb); PQuery *q = PNode_query(node); VertexServer_setupPQuery_(self, q); PNode *tmpNode = PDB_allocNode(self->pdb); Datum *d = self->result; Datum *k; if (PNode_moveToPathIfExists_(node, HttpRequest_uriPath(self->httpRequest)) != 0) { VertexServer_setErrorCString_(self, "path does not exist: "); VertexServer_appendError_(self, HttpRequest_uriPath(self->httpRequest)); return -1; } //PNode_startQuery(node); PNode_first(node); while(k = PNode_key(node)) { PNode_setPid_(tmpNode, PNode_value(node)); Datum *v = PNode_at_(tmpNode, slot1); if(v) { Datum_append_(d, k); Datum_appendCString_(d, ";"); Datum_append_(d, v); Datum_appendCString_(d, "\n"); } PNode_next(node); } HttpResponse_setContentType_(self->httpResponse, "text/plain"); //HttpResponse_setContentType_(self->httpResponse, "text/xml; charset=utf-8"); return 0; }
int File_symbolicallyLinkTo_(File *self, File *other) { int result; Datum *cmd = Datum_newWithCString_("ln -sf "); Datum_append_(cmd, self->path); Datum_appendCString_(cmd, " "); Datum_append_(cmd, File_path(other)); result = File_System(cmd); Datum_free(cmd); return result; }
int File_copyTo_(File *self, File *other) { int result; Datum *cmd = Datum_newWithCString_("cp "); Datum_append_(cmd, self->path); Datum_appendCString_(cmd, " "); Datum_append_(cmd, File_path(other)); result = File_System(cmd); Datum_free(cmd); return result; }
long PNode_nodeSizeAtCursor(PNode *self) { // carefull - this temporarilly hacks the sizePath long size; Datum *otherPid = PNode_value(self); Datum_copy_(self->sizePath, otherPid); Datum_appendCString_(self->sizePath, "/m/size"); size = PNode_size(self); PNode_setPathsFromPid(self); return size; }
int PNode_asHtmlRow(PNode *self, Datum *d) { PQuery *q = PNode_startQuery(self); Datum *k; Datum_appendCString_(d, "<tr>"); while (k = PQuery_key(q)) { if(Datum_beginsWithCString_(k, "_")) { Datum *v = PNode_value(self); Datum_appendCString_(d, "<td>"); if(v) Datum_append_(d, v); Datum_appendCString_(d, "</td><td> </td>"); } PQuery_enumerate(q); } Datum_appendCString_(d, "</tr>"); return 0; }
int PNode_amSeries(PNode *self, Datum *d) { PQuery *q = PNode_startQuery(self); Datum *k; Datum_appendCString_(d, "<series>\n"); while (k = PQuery_key(q)) { //if(Datum_beginsWithCString_(k, "_")) { Datum_appendCString_(d, "<value xid=\""); Datum_append_(d, k); Datum_appendCString_(d, "\">"); Datum_append_(d, k); // convert to more humane date? Datum_appendCString_(d, "</value>\n"); } PQuery_enumerate(q); } Datum_appendCString_(d, "</series>\n"); return 0; }
int PNode_remove(PNode *self) { Datum *k; long removeCount = 0; while ((k = PNode_key(self))) { PDB_willWrite(self->pdb); if(!StoreCursor_remove(self->storeCursor)) break; removeCount ++; } Datum_copy_(self->sizePath, self->pid); Datum_appendCString_(self->sizePath, "/m/size"); PDB_removeAt_(self->pdb, Datum_data(self->sizePath), Datum_size(self->sizePath)); return removeCount; }
int PNode_setSize_(PNode *self, long s) { Datum_copy_(self->sizePath, self->pid); Datum_appendCString_(self->sizePath, "/m/size"); { char ns[128]; snprintf(ns, 127, "%u", (unsigned int)s); //printf("%s <- %s\n", Datum_data(self->sizePath), ns); if(!PDB_at_put_(self->pdb, Datum_data(self->sizePath), (int)Datum_size(self->sizePath), (const void *)ns, (int)strlen(ns))) { return -1; } } return 0; }
Datum *PNode_atCString_(PNode *self, const char *k) { int size; void *v; Datum_copy_(self->keyPath, self->pidPath); Datum_appendCString_(self->keyPath, k); v = PDB_at_(self->pdb, Datum_data(self->keyPath), (int)Datum_size(self->keyPath), &size); if (v != 0x0) { Datum *value = Datum_poolNewWithData_size_(v, size); free(v); return value; } return 0x0; }
int VertexServer_api_view(VertexServer *self) { Datum *before = HttpRequest_queryValue_(self->httpRequest, "before"); Datum *after = HttpRequest_queryValue_(self->httpRequest, "after"); Datum *mode = HttpRequest_queryValue_(self->httpRequest, "mode"); PNode *node = PDB_allocNode(self->pdb); PNode *tmpNode = PDB_allocNode(self->pdb); Datum *d = self->result; int maxCount = 200; if (PNode_moveToPathIfExists_(node, HttpRequest_uriPath(self->httpRequest)) != 0) { VertexServer_setErrorCString_(self, "path does not exist: "); VertexServer_appendError_(self, HttpRequest_uriPath(self->httpRequest)); return -1; } Datum_appendCString_(d, "<!DOCTYPE html>\n"); Datum_appendCString_(d, "<html>\n"); Datum_appendCString_(d, "<head>\n"); Datum_appendCString_(d, "<title>"); Datum_append_(d, HttpRequest_uriPath(self->httpRequest)); Datum_appendCString_(d, "</title>\n"); Datum_appendCString_(d, "<meta charset=\"utf-8\">\n"); Datum_appendCString_(d, "<style>"); Datum_appendCString_(d, "body, td { font-family: Helvetica; font-size: 12px; margin-top:2em; margin-left:2em; }"); Datum_appendCString_(d, ".path { font-weight: normal; }"); Datum_appendCString_(d, ".note { color:#aaaaaa; }"); Datum_appendCString_(d, ".key { color:#000000; }"); Datum_appendCString_(d, ".value { color:#888888; white-space:pre; }"); Datum_appendCString_(d, "a { color: #0000aa; text-decoration: none; }"); Datum_appendCString_(d, "</style>\n"); Datum_appendCString_(d, "</head>\n"); Datum_appendCString_(d, "<body>\n"); /* if(Datum_size(HttpRequest_uriPath(self->httpRequest)) == 0) { Datum_appendCString_(d, "/"); } else { */ Datum_appendCString_(d, "<font class=path>"); Datum_appendCString_(d, "/"); Datum_append_(d, HttpRequest_uriPath(self->httpRequest)); Datum_appendCString_(d, "</font>"); Datum_appendCString_(d, "<br>\n"); //} PNode_first(node); if(Datum_size(before)) { PNode_jump_(node, before); int i; for(i = 0; i < maxCount; i++) { PNode_previous(node); } PNode_next(node); } else if(Datum_size(after)) { PNode_jump_(node, after); } if (Datum_size(after) && PNode_key(node)) { Datum_appendCString_(d, "<a href=/"); Datum_append_(d, HttpRequest_uriPath(self->httpRequest)); Datum_appendCString_(d, "?before="); Datum_append_(d, PNode_key(node)); Datum_appendCString_(d, ">previous</a>"); } Datum_appendCString_(d, "<ul>\n"); Datum_appendCString_(d, "<table cellpadding=0 cellspacing=0 border=0>"); { Datum *k; int count = 0; while ((k = PNode_key(node)) && count < maxCount) { if (Datum_beginsWithCString_(k , "_")) { Datum_appendCString_(d, "<tr>"); Datum_appendCString_(d, "<td align=right style=\"line-height:1.5em\">"); Datum_appendCString_(d, "<font class=key>"); Datum_append_(d, k); Datum_appendCString_(d, "</font>"); Datum_appendCString_(d, " "); Datum_appendCString_(d, "</td>"); Datum_appendCString_(d, "<td>"); Datum_appendCString_(d, " <span class=value>"); Datum_append_(d, PNode_value(node)); Datum_appendCString_(d, "</span>"); Datum_appendCString_(d, "<br>\n"); Datum_appendCString_(d, "</td>"); Datum_appendCString_(d, "</tr>"); } else { if(Datum_equalsCString_(mode, "table")) { PNode_setPid_(tmpNode, PNode_value(node)); PNode_asHtmlRow(tmpNode, d); } else { Datum_appendCString_(d, "<tr>"); Datum_appendCString_(d, "<td align=right>"); Datum_appendCString_(d, "<font class=key>"); Datum_append_(d, k); Datum_appendCString_(d, "</font><br>\n"); Datum_appendCString_(d, "</td>"); Datum_appendCString_(d, "<td style=\"line-height:1.5em\">"); Datum_appendCString_(d, " <a href="); if(Datum_size(HttpRequest_uriPath(self->httpRequest)) != 0) Datum_appendCString_(d, "/"); Datum_append_(d, HttpRequest_uriPath(self->httpRequest)); Datum_appendCString_(d, "/"); Datum_append_(d, k); Datum_appendCString_(d, "> ↠ "); Datum_appendLong_(d, PNode_nodeSizeAtCursor(node)); Datum_appendCString_(d, "</a> "); Datum_appendCString_(d, "<font class=value>"); Datum_appendCString_(d, "</td>"); Datum_appendCString_(d, "</tr>"); } } PNode_next(node); count ++; } } Datum_appendCString_(d, "</table>"); Datum_appendCString_(d, "</ul>\n"); if(PNode_key(node)) { Datum_appendCString_(d, "<a href=/"); Datum_append_(d, HttpRequest_uriPath(self->httpRequest)); Datum_appendCString_(d, "?after="); Datum_append_(d, PNode_key(node)); Datum_appendCString_(d, ">next</a><br>"); } Datum_appendCString_(d, "</body>\n"); Datum_appendCString_(d, "</html>\n"); HttpResponse_setContentType_(self->httpResponse, "text/html; charset=utf-8"); return 0; }
void File_appendToPathCString_(File *self, const char *path) { Datum_appendCString_(self->path, path); }
int VertexServer_api_amchart(VertexServer *self) { Datum *slot1 = HttpRequest_queryValue_(self->httpRequest, "slot1"); //Datum *slot2 = HttpRequest_queryValue_(self->httpRequest, "slot2"); //Datum *slot3 = HttpRequest_queryValue_(self->httpRequest, "slot3"); Datum *subpath = HttpRequest_queryValue_(self->httpRequest, "subpath"); PNode *node = PDB_allocNode(self->pdb); PQuery *q = PNode_query(node); VertexServer_setupPQuery_(self, q); PNode *tmpNode = PDB_allocNode(self->pdb); Datum *d = self->result; Datum *title = 0x0; //int isFirst = 1; if (PNode_moveToPathIfExists_(node, HttpRequest_uriPath(self->httpRequest)) != 0) { VertexServer_setErrorCString_(self, "path does not exist: "); VertexServer_appendError_(self, HttpRequest_uriPath(self->httpRequest)); return -1; } Datum_appendCString_(d, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); Datum_appendCString_(d, "<chart approx_count=\""); // series ----------------- if(Datum_size(subpath)) PNode_moveToPathIfExists_(node, subpath); Datum_appendLong_(d, PNode_size(node)); Datum_appendCString_(d, "\">\n"); PNode_startQuery(node); PNode_amSeries(node, d); PNode_moveToPathIfExists_(node, HttpRequest_uriPath(self->httpRequest)); // series ----------------- Datum_appendCString_(d, "<graphs>\n"); PNode_first(node); if(Datum_size(subpath)) { Datum *k; while(k = PNode_key(node)) { Datum *title = Datum_poolNew(); PNode_setPid_(tmpNode, PNode_value(node)); PNode_moveToSubpathIfExists_(tmpNode, subpath); Datum_encodeUri(k); Datum_copy_(title, k); //Datum_appendCString_(title, "-"); //Datum_append_(title, slot1); PNode_amGraphKey_(tmpNode, title, slot1, d); //printf("graph: %s\n", Datum_data(k)); PNode_next(node); } } else if(Datum_size(slot1)) { char slotKey[64]; int slotNumber = 1; for (;;) { sprintf(slotKey, "slot%i", slotNumber); Datum *slotName = HttpRequest_queryValue_(self->httpRequest, slotKey); if(Datum_size(slotName) == 0) break; PNode_amGraphKey_(node, title, slotName, d); slotNumber ++; } } Datum_appendCString_(d, "</graphs>\n"); Datum_appendCString_(d, "</chart>\n"); HttpResponse_setContentType_(self->httpResponse, "text/xml"); //HttpResponse_setContentType_(self->httpResponse, "text/xml; charset=utf-8"); return 0; }