Пример #1
0
int PNode_op_sizes(PNode *self, Datum *d)
{	
	PNode *tmpNode = PDB_allocNode(self->pdb);
	Datum *k;
	PQuery *q = PNode_startQuery(self);
	
	yajl_gen_map_open(self->yajl);
	
	while (k = PQuery_key(q))
	{
		if(!Datum_beginsWithCString_(k, "_"))
		{			
			yajl_gen_datum(self->yajl, PNode_key(self));
		
			PNode_setPid_(tmpNode, PNode_value(self));
			yajl_gen_integer(self->yajl, PNode_size(tmpNode));
		}
		
		if (q) { PQuery_enumerate(q); } else { PNode_next(self); }
	}
	
	yajl_gen_map_close(self->yajl);
	Datum_appendYajl_(d, self->yajl);
	return 0;  
}
Пример #2
0
int PNode_op_rm(PNode *self, Datum *d)
{
	PQuery *q = PNode_startQuery(self);
	Datum *k;
	long size = PNode_size(self);
	long removeCount = 0;
	
	if(!q) PNode_first(self);
	
	while (k = PQuery_key(q))
	{
		PDB_willWrite(self->pdb);
		if(!StoreCursor_remove(self->storeCursor)) break;
		
		// HACK to avoid skipping a step by backing up in the reverse enum direction before calling PQuery_enumerate
		if(PQuery_stepDirection(q) == 1)
		{
			StoreCursor_previous(self->storeCursor);
		}

		removeCount ++;
		//count += PNode_removeAt_(self, k);
		PQuery_enumerate(q);
	}

	PNode_setSize_(self, size - removeCount);
	
	
	yajl_gen_integer(self->yajl, removeCount);
	Datum_appendYajl_(d, self->yajl);
	//Datum_appendLong_(d, removeCount);
	return 0;  
}
Пример #3
0
int PNode_op_pairs(PNode *self, Datum *d)
{	
	PQuery *q = PNode_startQuery(self);
	PNode *tmpNode = PDB_allocNode(self->pdb);
	Datum *k;
	
	yajl_gen_array_open(self->yajl);
	
	while (k = PQuery_key(q))
	{		
		yajl_gen_array_open(self->yajl);

		yajl_gen_datum(self->yajl, k);
					
		if(!Datum_beginsWithCString_(k, "_"))
		{
			PNode_setPid_(tmpNode, PNode_value(self));
			PNode_op_object(tmpNode, d);
		}
		else
		{
			yajl_gen_datum(self->yajl, PNode_value(self));
		}
				
		PQuery_enumerate(q);
		yajl_gen_array_close(self->yajl);
	}
	
	yajl_gen_array_close(self->yajl);
	Datum_appendYajl_(d, self->yajl);
	return 0; 
}
Пример #4
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; 
}
Пример #5
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; 
}
Пример #6
0
int PNode_op_count(PNode *self, Datum *d)
{	
	PQuery *q = PNode_startQuery(self);
	Datum *k;
	long count = 0;
		
	while (k = PQuery_key(q))
	{
		count ++;
		PQuery_enumerate(q);
	}
	
	yajl_gen_integer(self->yajl, count);
	Datum_appendYajl_(d, self->yajl);
	return 0;  
}
Пример #7
0
int PNode_op_keys(PNode *self, Datum *d)
{	
	PQuery *q = PNode_startQuery(self);
	Datum *k;
	
	yajl_gen_array_open(self->yajl);
	
	while (k = PQuery_key(q))
	{
		yajl_gen_datum(self->yajl, k);
		PQuery_enumerate(q);
	}

	yajl_gen_array_close(self->yajl);
	Datum_appendYajl_(d, self->yajl);
	return 0;
}
Пример #8
0
int PNode_op_object(PNode *self, Datum *d)
{
	PQuery *q = PNode_startQuery(self);
	Datum *k;
	
	yajl_gen_map_open(self->yajl);
	
	while (k = PQuery_key(q))
	{
		yajl_gen_datum(self->yajl, k);
		yajl_gen_datum(self->yajl, PNode_value(self));
		PQuery_enumerate(q);
	}
	
	yajl_gen_map_close(self->yajl);
	if(d) Datum_appendYajl_(d, self->yajl);
	return 0;
}
Пример #9
0
int PNode_asHtmlRow(PNode *self, Datum *d)
{	
	PQuery *q = PNode_startQuery(self);
	Datum *k;
	
	Datum_appendCString_(d, "<tr>");
	
	while (k = PQuery_key(q))
	{		
		if(Datum_beginsWithCString_(k, "_"))
		{
			Datum *v = PNode_value(self);
			Datum_appendCString_(d, "<td>");
			if(v) Datum_append_(d, v);
			Datum_appendCString_(d, "</td><td>&nbsp;&nbsp;&nbsp;</td>");
		}

		PQuery_enumerate(q);
	}
	
	Datum_appendCString_(d, "</tr>");
	return 0; 
}
Пример #10
0
int PNode_amSeries(PNode *self, Datum *d)
{	
	PQuery *q = PNode_startQuery(self);
	Datum *k;
	
	Datum_appendCString_(d, "<series>\n");
	
	while (k = PQuery_key(q))
	{		
		//if(Datum_beginsWithCString_(k, "_"))
		{
			Datum_appendCString_(d, "<value xid=\"");
			Datum_append_(d, k);
			Datum_appendCString_(d, "\">");
			Datum_append_(d, k); // convert to more humane date?
			Datum_appendCString_(d, "</value>\n");
		}

		PQuery_enumerate(q);
	}
	
	Datum_appendCString_(d, "</series>\n");
	return 0; 
}
Пример #11
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;
}
Пример #12
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;
}