Esempio n. 1
0
bool ZWebDAV::sHandle_PROPFIND(const ZTrail& iPrefix, ZNode iRoot, const ZStreamR& iStreamR, const ZStreamW& iStreamW, const ZTuple& iHeader, const ZTrail& iTrail, const ZTuple& iParam)
	{
	int depth = sGetDepth(iHeader);

	ZRef<ZStrimmerR> theStrimmerR = sMakeStrimmer(iHeader, iStreamR);
	const ZStrimR& theStrimR = theStrimmerR->GetStrimR();

	ZHTTP::Response r;
	r.Set("Date", sAsString_WebDAV(ZTime::sNow()));

	ZNode theNode = iRoot.Trail(iTrail);
	if (!theNode.Exists())
		{
		theStrimR.SkipAll();
		r.Set("Content-Length", 0);
		r.SetResult(404);
		r.Send(iStreamW);
		}
	else
		{		
		ZTuple t = sReadTuple(theStrimR);
		
		ZTuple results;
		if (t.Empty() || t.Has("D:allprop"))
			{
			sHandle_PROPFIND_All(iPrefix, iRoot, theNode, depth, results);
			}
		else
			{
			ZTuple propT = t.GetTuple("D:prop");
			vector<string> thePropNames;
			for (ZTuple::const_iterator i = propT.begin(); i != propT.end(); ++i)
				thePropNames.push_back(propT.NameOf(i));
			sHandle_PROPFIND_Some(iPrefix, iRoot, theNode, depth, thePropNames, results);
			}

		if (const ZLog::S& s = ZLog::S(ZLog::eDebug, "ZWebDAV"))
			{
			s << "PropFind Request:" << t << "\n";
			s << "PropFind Results:" << results << "\n";
			}

		r.SetResult(207, "Multi-Status");
		r.Set("Content-Type", "text/xml; charset=\"utf-8\"");
		r.Set("Transfer-Encoding", "chunked");		
		r.Send(iStreamW);

		ZHTTP::StreamW_Chunked chunkedStream(iStreamW);
		ZStrimW_StreamUTF8 theStrimW(chunkedStream);
		ZStrimW_ML s(false, theStrimW);
		s.PI("xml");
			s.Attr("version", "1.0");
			s.Attr("encoding", "utf-8");
		s.Begin("D:multistatus");
			s.Attr("xmlns:D", "DAV:");
			sWriteAsXML(s, results);
		s.End("D:multistatus");
		}
	return true;
	}
Esempio n. 2
0
bool ZUITextEngine::MenuMessage(const ZMessage& inMessage)
	{
	switch (inMessage.GetInt32("menuCommand"))
		{
		case mcCopy:
		case mcCut:
			{
			size_t selectStart, selectLength;
			this->GetSelection(selectStart, selectLength);
			if (selectLength != 0)
				{
				if (inMessage.GetInt32("menuCommand") == mcCopy || this->IsRangeEditable(selectStart, selectLength))
					{
					ZTuple theTuple = this->GetTuple(selectStart, selectLength);
					ZClipboard::sSet(theTuple);
					if (inMessage.GetInt32("menuCommand") == mcCut)
						this->DeleteText(selectStart, selectLength);
					}
				}
			return true;
			break;
			}
		case mcClear:
			{
			size_t selectStart, selectLength;
			this->GetSelection(selectStart, selectLength);
			if (selectLength != 0 && this->IsRangeEditable(selectStart, selectLength))
				{
				this->DeleteText(selectStart, selectLength);
				return true;
				}
			return true;
			break;
			}
		case mcPaste:
			{
			size_t selectStart, selectLength;
			this->GetSelection(selectStart, selectLength);
			if (this->IsRangeEditable(selectStart, selectLength))
				{
				ZTuple theTuple = ZClipboard::sGet();
				if (theTuple.Has("text/plain"))
					{
					this->ReplaceSelection(theTuple.GetString("text/plain"));
					return true;
					}
				}
			return true;
			break;
			}
		case mcSelectAll:
			{
			this->SetSelection(0, this->GetTextLength());
			return true;
			}
		}
	return false;
	}
Esempio n. 3
0
bool ZUITextEngine::AcceptsDragDrop(const ZDragDropBase& inDragDrop)
	{
	bool gotIt = inDragDrop.GetDragSource() == this;
	for (size_t currentTupleIndex = 0; !gotIt && currentTupleIndex < inDragDrop.CountTuples(); ++currentTupleIndex)
		{
		ZTuple currentTuple = inDragDrop.GetTuple(currentTupleIndex);
		if (currentTuple.Has("text/plain"))
			gotIt = true;
		}
	return gotIt;
	}
Esempio n. 4
0
void ZUITextEngine::HandleDrop(ZPoint inPoint, ZDrop& inDrop)
	{
	if (!this->AcceptsDragDrop(inDrop))
		return;
	if (inDrop.GetDragSource() == this)
		{
		size_t dragOffset = this->PointToOffset(this->FromHost(inPoint));
		size_t selectStart, selectLength;
		this->GetSelection(selectStart, selectLength);

		if (dragOffset < selectStart)
			{
			string selectedText = this->GetText(selectStart, selectLength);
			this->DeleteText(selectStart, selectLength);
			this->InsertText(dragOffset, selectedText);
			this->SetSelection(dragOffset, selectLength);
			}
		else if (dragOffset > selectStart+selectLength)
			{
			string selectedText = this->GetText(selectStart, selectLength);
			this->DeleteText(selectStart, selectLength);
			this->InsertText(dragOffset-selectLength, selectedText);
			this->SetSelection(dragOffset-selectLength, selectLength);
			}				
		}
	else
		{
		size_t dragOffset = this->PointToOffset(inPoint);
		if (!this->IsRangeEditable(dragOffset, 0))
			return;
		for (size_t currentTupleIndex = 0; currentTupleIndex < inDrop.CountTuples(); ++currentTupleIndex)
			{
			ZTuple currentTuple = inDrop.GetTuple(currentTupleIndex);
			if (currentTuple.Has("text/plain"))
				{
				string droppedString = currentTuple.GetString("text/plain");
				this->InsertText(dragOffset, droppedString);
				this->SetSelection(dragOffset, droppedString.size());
				// Return now, so we only drop text from the first tuple that had any
				return;
				}
			}
		}
	}
Esempio n. 5
0
bool ZWebDAV::sHandle_GET(const ZTrail& iPrefix, ZNode iRoot, const ZStreamR&, const ZStreamW& iStreamW, const ZTuple& iHeader, const ZTrail& iTrail, const ZTuple& iParam)
	{
	ZNode theNode = iRoot.Trail(iTrail);

	ZHTTP::Response r;
	r.Set("date", sAsString_WebDAV(ZTime::sNow()));

	if (iHeader.Has("range"))
		{
		if (const ZLog::S& s = ZLog::S(ZLog::eInfo, "ZWebDAV"))
			s << "GET with range:\n" << iHeader;
		}

	if (theNode.Exists())
		{
		r.SetResult(200);
		if (theNode.CanHaveChildren())
			{
			r.Set("Content-Type", "text/html; charset=\"utf-8\"");
			r.Set("Transfer-Encoding", "chunked");
			r.Send(iStreamW);

			ZHTTP::StreamW_Chunked chunkedStream(iStreamW);
			ZStrimW_StreamUTF8 theStrimW(chunkedStream);
			ZStrimW_ML s(false, theStrimW);
			s.Begin("html");
				s.Begin("title");
					s << theNode.Name();
				s.End("title");
				s.Begin("body");
					for (ZNodeIter i = theNode; i; i.Advance())
						{
						s.Begin("p");
							s.Begin("a");
								if (i.Current().CanHaveChildren())
									{
									s.Attr("href", ZHTTP::sEncodeComponent(i.Current().Name()) + "/");
									s << i.Current().Name() << "/";
									}
								else
									{
									s.Attr("href", ZHTTP::sEncodeComponent(i.Current().Name()));
									s << i.Current().Name();
									}
							s.End("a");
						s.End("p");
						}
				s.End("body");
			
			s.End("html");
			}
		else if (ZRef<ZStreamerRPos> theStreamer = theNode.OpenRPos())
			{
			const ZStreamRPos& theStreamRPos = theStreamer->GetStreamRPos();
			uint64 sentSize = theStreamRPos.GetSize();

			if (ZTupleValue rangeParam = iHeader.GetValue("range"))
				{
				vector<pair<size_t, size_t> > ranges;
				if (!ZHTTP::sOrganizeRanges(sentSize, rangeParam, ranges))
					{
					iStreamW.WriteString("HTTP/1.1 406 Unsatisfiable range\r\n\r\n");
					return false;
					}
				r.SetResult(206, "Partial Content");

				r.Set("Content-Range", ZString::sFormat("bytes %d-%d/%d", ranges.front().first, ranges.front().second - 1, sentSize));

				theStreamRPos.SetPosition(ranges.front().first);
				sentSize = ranges.front().second - ranges.front().first;
				}
			else
				{
				r.SetResult(200);
				}
			
			string theMIMEType = "application/octet-stream";
			ZTupleValue theMIMEValue;
			if (theNode.GetProp("MIMEType", theMIMEValue))
				{
				string asString;
				if (theMIMEValue.GetString(asString))
					theMIMEType = asString;
				}
			r.Set("Content-Type", theMIMEType);

			ZTupleValue theValue;
			if (theNode.GetProp("lastModified", theValue))
				{
				if (ZTime theTime = theValue.GetTime())
					r.Set("Last-Modified", sAsString_WebDAV(theTime));
				}

			r.Set("Content-Transfer-Encoding", "binary");
			r.Set("Content-Length", ZString::sFromUInt64(sentSize));

			r.Send(iStreamW);

			iStreamW.CopyFrom(theStreamRPos, sentSize);
			}
		}
	else
		{
		r.SetResult(404);
		r.Send(iStreamW);
		r.Set("Content-Length", 0);
		}
	return true;
	}