示例#1
0
int PNode_moveToPathCString_(PNode *self, const char *p)
{
	int result;
	Datum *np = Datum_poolNewWithCString_(p);
	result = PNode_moveToPath_(self, np);
	return result;
}
示例#2
0
Datum *Datum_asUriEncoded(Datum *self)
{
	char *k = evhttp_encode_uri(Datum_data(self));
	Datum *d = Datum_poolNewWithCString_(k);
	free(k);
	return d;
}
示例#3
0
Datum *PNode_key(PNode *self)
{
	int size;
	char *ks = StoreCursor_key(self->storeCursor, &size);
      
	//if (ks == 0x0 || size == 0) return 0x0;
	if (ks == 0x0) return 0x0;

	if(Datum_isBeginningOfCString_(self->pidPath, ks)) 
	{
	   const char *subpath = ks + Datum_size(self->pidPath);
	   Datum *key = Datum_poolNewWithCString_(subpath);
	   free(ks);
	   return key;
	}
   
	free(ks);
	return 0x0;
}
示例#4
0
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;
}
示例#5
0
int PNode_createMoveToKeyString_(PNode *self, const char *k)
{
	Datum *key = Datum_poolNewWithCString_(k);
	int r = PNode_createMoveToKey_(self, key);
	return r;
}