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; }
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; }
void HttpRequest_parseUri_(HttpRequest *self, const char *uri) { Datum_setCString_(self->uri, uri); int index; Datum *uriDatum = Datum_poolNew(); Datum_setCString_(uriDatum, uri); //if (self->debug) { Log_Printf_("request: %s\n", uri); } CHash_clear(self->query); Datum_setSize_(self->uriPath, 0); index = Datum_from_beforeChar_into_(uriDatum, 1, '?', self->uriPath); Datum_decodeUri(self->uriPath); for (;;) { Datum *key = Datum_poolNew(); Datum *value = Datum_poolNew(); index = Datum_from_beforeChar_into_(uriDatum, index + 1, '=', key); Datum_decodeUri(key); Datum_nullTerminate(key); if (Datum_size(key) == 0) break; index = Datum_from_beforeChar_into_(uriDatum, index + 1, '&', value); Datum_decodeUri(value); Datum_nullTerminate(value); CHash_at_put_(self->query, key, value); if(self->requestParameterCallback) { self->requestParameterCallback(self->delegate, key, value); } if (Datum_size(value) == 0) break; } }
int VertexServer_api_queuePopTo(VertexServer *self) { PNode *fromNode = PDB_allocNode(self->pdb); PNode *toNode = PDB_allocNode(self->pdb); Datum *toPath = HttpRequest_queryValue_(self->httpRequest, "toPath"); long ttl = Datum_asLong(HttpRequest_queryValue_(self->httpRequest, "ttl")); if (PNode_moveToPathIfExists_(fromNode, HttpRequest_uriPath(self->httpRequest)) != 0) { VertexServer_setErrorCString_(self, "from path does not exist: "); VertexServer_appendError_(self, HttpRequest_uriPath(self->httpRequest)); return -1; } PNode_moveToPath_(toNode, toPath); //printf("to pid: %s\n", Datum_data(PNode_pid(toNode))); //printf("from pid: %s\n", Datum_data(PNode_pid(fromNode))); { PQuery *q = PNode_query(fromNode); VertexServer_setupPQuery_(self, q); PNode_startQuery(fromNode); Datum *k = PQuery_key(q); Datum *v = PNode_value(fromNode); if (k) { PNode_atPut_(toNode, k, v); PNode_moveToKey_(toNode, k); // insert queue time { long now = time(NULL); Datum *timeKey = Datum_poolNewWithCString_("_qtime"); Datum *timeValue = Datum_poolNew(); Datum_fromLong_(timeValue, now); PNode_atPut_(toNode, timeKey, timeValue); Datum_setCString_(timeKey, "_qexpire"); Datum_fromLong_(timeValue, now + (ttl == 0 ? 3600 : ttl)); PNode_atPut_(toNode, timeKey, timeValue); } //printf("queueing key %s\n", Datum_data(k)); yajl_gen_datum(self->yajl, k); PNode_removeAt_(fromNode, k); } else { yajl_gen_null(self->yajl); } } Datum_appendYajl_(self->result, self->yajl); return 0; }
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; }