int PNode_moveToPath_createIfAbsent_(PNode *self, Datum *p, int createIfAbsent, int fromRoot) { int r; Datum *cp = Datum_poolNew(); Datum *np = Datum_poolNew(); Datum_copy_(cp, p); if (fromRoot) PNode_setToRoot(self); do { r = Datum_sepOnChars_with_(cp, "/", np); if (!Datum_isEmpty(cp)) { if (createIfAbsent) { PNode_createMoveToKey_(self, cp); } else { if (PNode_moveToKey_(self, cp)) { return -1; } } } Datum_copy_(cp, np); } while(r != -1); return 0; }
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/"); }
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_transaction(VertexServer *self) { Datum *uri = Datum_new(); Datum *post = Datum_new(); int error = 0; int r, result; PDB_commit(self->pdb); Datum_copy_(post, HttpRequest_postData(self->httpRequest)); do { Datum_copy_(uri, post); r = Datum_sepOnChars_with_(uri, "\n", post); if (Datum_size(uri) == 0) { VertexServer_setErrorCString_(self, "empty line in transaction"); error = 1; break; } HttpRequest_parseUri_(self->httpRequest, Datum_data(uri)); error = VertexServer_process(self); Pool_globalPoolFreeRefs(); } while ((r != -1) && (!error)); if (error) { PDB_abort(self->pdb); result = -1; } else { PDB_commit(self->pdb); result = 0; } Datum_free(uri); return result; }
int PNode_createMoveToKey_(PNode *self, Datum *key) { Datum *v = PNode_at_(self, key); if (v) { Datum_copy_(self->parentPid, self->pid); PNode_setPid_(self, v); return 1; } else { PNode *n = PDB_allocNode(self->pdb); PNode_create(n); PNode_atPut_(self, key, PNode_pid(n)); Datum_copy_(self->parentPid, self->pid); PNode_setPid_(self, PNode_pid(n)); } return 0; }
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_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 PNode_moveToKey_(PNode *self, Datum *key) { /* if (Datum_equalsCString_(key, "approved")) { printf("approved"); } */ Datum *v = PNode_at_(self, key); if (v) { Datum_copy_(self->parentPid, self->pid); PNode_setPid_(self, v); return 0; } return -1; }
void PNode_jump_(PNode *self, Datum *k) { Datum_copy_(self->keyPath, self->pidPath); Datum_append_(self->keyPath, k); StoreCursor_jump(self->storeCursor, Datum_data(self->keyPath), (int)Datum_size(self->keyPath)); }
void File_setPath_(File *self, Datum *path) { Datum_copy_(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; }