Esempio n. 1
0
int PNode_withId_hasKey_andValue_(PNode *self, Datum *pid, Datum *wk, Datum *wv)
{	
	Datum *value;

	PNode_setPid_(self, pid);
	value = PNode_at_(self, wk);
	return value ? Datum_equals_(value, wv) : 0; 
}
Esempio n. 2
0
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; 
}
Esempio n. 3
0
int PNode_op_values(PNode *self, Datum *d)
{	
	PQuery *q = PNode_startQuery(self);
	PNode *tmpNode = PDB_allocNode(self->pdb);
	Datum *k;
	Datum *attribute = PQuery_attribute(q);
	int hasAttribute = Datum_size(attribute) != 0;
	
	yajl_gen_array_open(self->yajl);
	
	while (k = PQuery_key(q))
	{		
		if(!Datum_beginsWithCString_(k, "_"))
		{
			PNode_setPid_(tmpNode, PNode_value(self));
			
			if(hasAttribute)
			{
				//Datum *a = PQuery_attributeValue(q);
				Datum *a = PNode_at_(tmpNode, attribute);
				
				yajl_gen_array_open(self->yajl);
				yajl_gen_datum(self->yajl, k);
				
				if(a)
				{
					yajl_gen_datum(self->yajl, a);
				}
				else 
				{
					yajl_gen_null(self->yajl);
				}
				
				yajl_gen_array_close(self->yajl);

			}
			else 
			{
				PNode_setPid_(tmpNode, PNode_value(self));
				PNode_op_object(tmpNode, 0x0);
			}
		}
		else
		{
				yajl_gen_datum(self->yajl, PNode_value(self));
		}

		PQuery_enumerate(q);
	}
	
	yajl_gen_array_close(self->yajl);
	Datum_appendYajl_(d, self->yajl);
	return 0; 
}
Esempio n. 4
0
PNode *PNode_nodeAt_(PNode *self, Datum *k)
{	
	Datum *v = PNode_at_(self, k);
	
	if (v)
	{
		PNode *target = PNode_new();
		PNode_setPdb_(target, self->pdb);
		PNode_setPid_(target, v);
		return target;
	}
	
	return 0x0;
}
Esempio n. 5
0
int PNode_removeAt_(PNode *self, Datum *k)
{
	if ((!Datum_isEmpty(k)) && (PNode_at_(self, k) != 0x0))
	{
		if(!PDB_removeAt_(self->pdb, Datum_data(self->keyPath), (int)Datum_size(self->keyPath)))
		{
			printf("PNode_removeAt_ error\n");
			return -1;
		}

		return PNode_decrementSize(self);
	}
	
	return 0;
}
Esempio n. 6
0
int PNode_atCat_(PNode *self, Datum *k, Datum *v)
{
	int hasKey = PNode_at_(self, k) != NULL;

	if (!PDB_at_cat_(self->pdb, 
		Datum_data(self->keyPath), (int)Datum_size(self->keyPath), 
		Datum_data(v), (int)Datum_size(v)))
	{
		printf("PNode_atCat_ error\n");
		return -1;
	}

	if (!hasKey) return PNode_incrementSize(self);
	
	return 0;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
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;
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
int VertexServer_api_read(VertexServer *self)
{
	PNode *node = PDB_allocNode(self->pdb);
	Datum *key = HttpRequest_queryValue_(self->httpRequest, "key");	
	Datum *value;
	
	if (VertexServer_api_setCursorPathOnNode_(self, node)) return 2;

	value = PNode_at_(node, key);

	if (value) 
	{
		yajl_gen_datum(self->yajl, value);
	}
	else
	{
		yajl_gen_null(self->yajl);
	}
	
	Datum_appendYajl_(self->result, self->yajl);
	return 0;
}
Esempio n. 11
0
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;
}