void HttpRequest_free(HttpRequest *self) { Datum_free(self->uri); Datum_free(self->uriPath); Datum_free(self->post); CHash_free(self->query); Datum_free(self->emptyDatum); free(self); }
int File_remove(File *self) { int result; Datum *cmd = Datum_newWithCString_("rm "); Datum_append_(cmd, self->path); result = File_System(cmd); Datum_free(cmd); return result; }
int File_createDirectory(File *self) { int result; Datum *cmd = Datum_newWithCString_("mkdir -p "); Datum_append_(cmd, self->path); result = File_System(cmd); Datum_free(cmd); return result; }
void PNode_free(PNode *self) { PNode_close(self); Datum_free(self->pid); Datum_free(self->pidPath); Datum_free(self->keyPath); Datum_free(self->sizePath); Datum_free(self->parentPid); if (self->query) { PQuery_free(self->query); self->query = 0x0; } self->yajl = 0x0; free(self); }
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; }
IoObject *IoTagDB_symbolForId(IoTagDB *self, IoObject *locals, IoMessage *m) { /*doc TagDB symbolForId(aNumber) Returns the TagDB symbol for aNumber. */ symbolid_t id = IoMessage_locals_sizetArgAt_(m, locals, 0); Datum *d = TagDB_symbolForId_(DATA(self), id); IoSeq *s = IoSeq_newWithData_length_(IOSTATE, Datum_data(d), Datum_size(d)); Datum_free(d); return s; }
void PNode_removeAtCursor(PNode *self) { Datum *k = PNode_key(self); PDB_willWrite(self->pdb); if (k) { Datum *currentKey = Datum_clone(k); Datum *nextKey = 0x0; PNode_next(self); Datum *nk = PNode_key(self); if (nk) nextKey = Datum_clone(nk); PNode_removeAt_(self, currentKey); //StoreCursor_remove(self->storeCursor); if (nextKey) PNode_jump_(self, nextKey); Datum_free(currentKey); if (nextKey) Datum_free(nextKey); } /* PDB_willWrite(self->pdb); if(StoreCursor_remove(self->storeCursor)) { PNode_decrementSize(self); PNode_jumpToCurrentKey(self); } else { printf("PNode warning: remove failed\n"); } */ }
IoObject *IoTagDB_tagsAtKey(IoTagDB *self, IoObject *locals, IoMessage *m) { /*doc TagDB tagsAtKey(key) Returns the tags for the specified key. */ TagDB *tdb = DATA(self); IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); symbolid_t keyid = TagDB_idForSymbol_size_(tdb, CSTRING(key), IoSeq_rawSize(key)); IoList *tagNames = IoList_new(IOSTATE); Uint64Array *tags = TagDB_tagsAtKey_(tdb, keyid); int i; //printf("IoTagDB_tagsAt self = %p\n", (void *)self); if (!tags) { //printf("IoTagDB_tagsAtKey: no tags found for key\n"); return IONIL(self); } for (i = 0; i < Uint64Array_size(tags); i ++) { uint64_t tagid = Uint64Array_at_(tags, i); Datum *name = TagDB_symbolForId_(tdb, tagid); //printf("tagid %i = %i\n", i, (int)tagid); //printf("name '%s'\n", (char *)name->data); if (!name) { printf("IoTagDB_tagsAtKey: no datum returned for TagDB_symbolForId_\n"); } else { IoList_rawAppend_(tagNames, IoSeq_newWithData_length_(IOSTATE, name->data, name->size)); Datum_free(name); } } //Uint64Array_free(tags); return tagNames; }
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 VertexServer_api_queueExpireTo(VertexServer *self) { PNode *fromNode = PDB_allocNode(self->pdb); PNode *toNode = PDB_allocNode(self->pdb); PNode *itemNode = PDB_allocNode(self->pdb); Datum *toPath = HttpRequest_queryValue_(self->httpRequest, "toPath"); unsigned int itemsExpired = 0; 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); if (PNode_moveToPathIfExists_(toNode, toPath) != 0) { VertexServer_setErrorCString_(self, "to path does not exist: "); VertexServer_appendError_(self, toPath); return -1; } PNode_first(fromNode); { Datum *qTimeKey = Datum_newWithCString_("_qtime"); Datum *k; Datum *qExpireKey = Datum_newWithCString_("_qexpire"); long now = time(NULL); while (k = PNode_key(fromNode)) { Datum *pid = PNode_value(fromNode); Datum *qExpireValue; PNode_setPid_(itemNode, pid); qExpireValue = PNode_at_(itemNode, qExpireKey); if(!qExpireValue) { Log_Printf("WARNING: attempt to expire a node with no _qexpire value\n"); if(PNode_at_(itemNode, qTimeKey) == 0x0) { Log_Printf("WARNING: node also missing _qtime value\n"); } break; } if(qExpireValue == 0x0 || Datum_asLong(qExpireValue) < now) { PNode_removeAtCursor(fromNode); // the remove will go to the next item PNode_key(fromNode); PNode_removeAt_(itemNode, qTimeKey); PNode_removeAt_(itemNode, qExpireKey); PNode_atPut_(toNode, k, pid); PNode_jumpToCurrentKey(fromNode); itemsExpired ++; } else { PNode_next(fromNode); } } Datum_free(qTimeKey); Datum_free(qExpireKey); } yajl_gen_integer(self->yajl, (long)itemsExpired); Datum_appendYajl_(self->result, self->yajl); return 0; }
void File_free(File *self) { Datum_free(self->path); free(self); }