Example #1
0
int VertexServer_api_write(VertexServer *self)
{
	PNode *node = PDB_allocNode(self->pdb);
	Datum *mode  = HttpRequest_queryValue_(self->httpRequest, "mode");
	Datum *key   = HttpRequest_queryValue_(self->httpRequest, "key");
	Datum *value = HttpRequest_queryValue_(self->httpRequest, "value");
	
	/*
	if(Datum_size(value) == 0)
	{
		value = self->post;
		//VertexServer_setErrorCString_(self, "empty keys not accepted");
		//return -1;
	}
	*/
	
	/*
	if(Datum_size(value) == 0)
	{
		VertexServer_setErrorCString_(self, "empty values not accepted");
		return -1;
	}
	*/

	if (PNode_moveToPathIfExists_(node, HttpRequest_uriPath(self->httpRequest)) != 0) 
	{
		VertexServer_setErrorCString_(self, "write path does not exist: ");
		VertexServer_appendError_(self, HttpRequest_uriPath(self->httpRequest));
		return -1;
	}	
	
	if(Datum_equalsCString_(mode, "append"))
	{
		PNode_atCat_(node, key, value);
	}
	else
	{
		PNode_atPut_(node, key, value);
	}
	
	return 0;
}
Example #2
0
int VertexServer_api_view(VertexServer *self)
{
	Datum *before = HttpRequest_queryValue_(self->httpRequest, "before");
	Datum *after = HttpRequest_queryValue_(self->httpRequest, "after");
	Datum *mode = HttpRequest_queryValue_(self->httpRequest, "mode");
	PNode *node = PDB_allocNode(self->pdb);
	PNode *tmpNode = PDB_allocNode(self->pdb);
	Datum *d = self->result;
	int maxCount = 200;
	
	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, "<!DOCTYPE html>\n");
		Datum_appendCString_(d, "<html>\n");
		Datum_appendCString_(d, "<head>\n");
		Datum_appendCString_(d, "<title>");
		Datum_append_(d, HttpRequest_uriPath(self->httpRequest));
		Datum_appendCString_(d, "</title>\n");
		Datum_appendCString_(d, "<meta charset=\"utf-8\">\n");
		Datum_appendCString_(d, "<style>");
		Datum_appendCString_(d, "body, td { font-family: Helvetica; font-size: 12px; margin-top:2em; margin-left:2em; }");
		Datum_appendCString_(d, ".path { font-weight: normal; }");
		Datum_appendCString_(d, ".note { color:#aaaaaa; }");
		Datum_appendCString_(d, ".key { color:#000000;  }");
		Datum_appendCString_(d, ".value { color:#888888; white-space:pre; }");
		Datum_appendCString_(d, "a { color: #0000aa; text-decoration: none;  }");

		Datum_appendCString_(d, "</style>\n");
		Datum_appendCString_(d, "</head>\n");
		Datum_appendCString_(d, "<body>\n");
	
	/*
	if(Datum_size(HttpRequest_uriPath(self->httpRequest)) == 0)
	{
	Datum_appendCString_(d, "/");
	}
	else
	{
	*/
		Datum_appendCString_(d, "<font class=path>");
		Datum_appendCString_(d, "/");
		Datum_append_(d, HttpRequest_uriPath(self->httpRequest));
		Datum_appendCString_(d, "</font>");
		Datum_appendCString_(d, "<br>\n");
	//}
	
	PNode_first(node);
	
	if(Datum_size(before))
	{
		PNode_jump_(node, before);
		
		int i;
		for(i = 0; i < maxCount; i++)
		{
			PNode_previous(node);
		}
		PNode_next(node);

	}
	else if(Datum_size(after))
	{
		PNode_jump_(node, after);
	}

	if (Datum_size(after) && PNode_key(node))
	{
		Datum_appendCString_(d, "<a href=/");
		Datum_append_(d, HttpRequest_uriPath(self->httpRequest));
		Datum_appendCString_(d, "?before=");
		Datum_append_(d, PNode_key(node));
		Datum_appendCString_(d, ">previous</a>");
	}

	
	Datum_appendCString_(d, "<ul>\n");
	Datum_appendCString_(d, "<table cellpadding=0 cellspacing=0 border=0>");

	{
		Datum *k;
		int count = 0;
		
		while ((k = PNode_key(node)) && count < maxCount)
		{
			
			if (Datum_beginsWithCString_(k , "_"))
			{
				Datum_appendCString_(d, "<tr>");
				Datum_appendCString_(d, "<td align=right style=\"line-height:1.5em\">");
				Datum_appendCString_(d, "<font class=key>");
				Datum_append_(d, k);
				Datum_appendCString_(d, "</font>");
				Datum_appendCString_(d, " ");
				Datum_appendCString_(d, "</td>");
				
				Datum_appendCString_(d, "<td>");
				Datum_appendCString_(d, "&nbsp;&nbsp;<span class=value>");
				Datum_append_(d, PNode_value(node));
				Datum_appendCString_(d, "</span>");
				Datum_appendCString_(d, "<br>\n");
				Datum_appendCString_(d, "</td>");
				Datum_appendCString_(d, "</tr>");
			}
			else
			{
				if(Datum_equalsCString_(mode, "table"))
				{
					PNode_setPid_(tmpNode, PNode_value(node));
					PNode_asHtmlRow(tmpNode, d);
				}
				else 
				{
					Datum_appendCString_(d, "<tr>");
					Datum_appendCString_(d, "<td align=right>");
					Datum_appendCString_(d, "<font class=key>");
					Datum_append_(d, k);
					Datum_appendCString_(d, "</font><br>\n");
					Datum_appendCString_(d, "</td>");
					
					Datum_appendCString_(d, "<td style=\"line-height:1.5em\">");
					Datum_appendCString_(d, "&nbsp;&nbsp;<a href=");
					if(Datum_size(HttpRequest_uriPath(self->httpRequest)) != 0) Datum_appendCString_(d, "/");
					Datum_append_(d, HttpRequest_uriPath(self->httpRequest));
					Datum_appendCString_(d, "/");
					Datum_append_(d, k);
					Datum_appendCString_(d, "> ↠ ");
					Datum_appendLong_(d, PNode_nodeSizeAtCursor(node));
					Datum_appendCString_(d, "</a> ");
					Datum_appendCString_(d, "<font class=value>");
					Datum_appendCString_(d, "</td>");
					Datum_appendCString_(d, "</tr>");
				}
			}
			
			PNode_next(node);
			count ++;
		}
	}
	Datum_appendCString_(d, "</table>");
	Datum_appendCString_(d, "</ul>\n");
	
	if(PNode_key(node))
	{
		Datum_appendCString_(d, "<a href=/");
		Datum_append_(d, HttpRequest_uriPath(self->httpRequest));
		Datum_appendCString_(d, "?after=");
		Datum_append_(d, PNode_key(node));
		Datum_appendCString_(d, ">next</a><br>");
	}
	
	Datum_appendCString_(d, "</body>\n");
	Datum_appendCString_(d, "</html>\n");

	HttpResponse_setContentType_(self->httpResponse, "text/html; charset=utf-8");
	return 0;
}
Example #3
0
int PNode_boolMetaAtCString_(PNode *self, char *k)
{
	DATUM_STACKALLOCATED(key, k);
	Datum *v = PNode_metaAt_(self, key);
	return (!v || !Datum_equalsCString_(v, "n"));
}