Merged branch v0.5-gxs-b1 into trunk (from -r 5351 -> 5995)

This brings a huge amount of goodness into the trunk,
but there is still a big chunk todo before it can be released.

 * GXS Backend.
 * GXS Services:
	- Identities.
	- Circles
	- Photos
	- Wiki
	- GxsForums
	- Posted.
 * SSH no-gui server.

See branch commits for more info.

To switch on GXS stuff, enable CONFIG += gxs
in both libretroshare.pro and retroshare-gui.pro



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5996 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-16 19:17:11 +00:00
commit 069b72e0b2
549 changed files with 111171 additions and 25579 deletions

View file

@ -0,0 +1,137 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "CURLWrapper.h"
#include <string.h>
//static int progressCallback (void *clientp, double /*dltotal*/, double /*dlnow*/, double /*ultotal*/, double /*ulnow*/)
//{
// p3FeedReaderThread *thread = (p3FeedReaderThread*) clientp;
// if (!thread->isRunning()) {
// /* thread was stopped */
// return 1;
// }
// long todo; // show progress in gui
// return 0;
//}
CURLWrapper::CURLWrapper(const std::string &proxy)
{
mCurl = curl_easy_init();
if (mCurl) {
curl_easy_setopt(mCurl, CURLOPT_NOPROGRESS, 0);
// curl_easy_setopt(mCurl, CURLOPT_PROGRESSFUNCTION, progressCallback);
// curl_easy_setopt(mCurl, CURLOPT_PROGRESSDATA, feedReader);
curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(mCurl, CURLOPT_CONNECTTIMEOUT, 60);
curl_easy_setopt(mCurl, CURLOPT_TIMEOUT, 120);
if (!proxy.empty()) {
curl_easy_setopt(mCurl, CURLOPT_PROXY, proxy.c_str());
}
}
}
CURLWrapper::~CURLWrapper()
{
if (mCurl) {
curl_easy_cleanup(mCurl);
}
}
static size_t writeFunctionString (void *ptr, size_t size, size_t nmemb, void *stream)
{
std::string *s = (std::string*) stream;
s->append ((char*) ptr, size * nmemb);
return nmemb * size;
}
CURLcode CURLWrapper::downloadText(const std::string &link, std::string &data)
{
data.clear();
if (!mCurl) {
return CURLE_FAILED_INIT;
}
curl_easy_setopt(mCurl, CURLOPT_URL, link.c_str());
curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, writeFunctionString);
curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, &data);
return curl_easy_perform(mCurl);
}
static size_t writeFunctionBinary (void *ptr, size_t size, size_t nmemb, void *stream)
{
std::vector<unsigned char> *bytes = (std::vector<unsigned char>*) stream;
std::vector<unsigned char> newBytes;
newBytes.resize(size * nmemb);
memcpy(newBytes.data(), ptr, newBytes.size());
bytes->insert(bytes->end(), newBytes.begin(), newBytes.end());
return nmemb * size;
}
CURLcode CURLWrapper::downloadBinary(const std::string &link, std::vector<unsigned char> &data)
{
data.clear();
if (!mCurl) {
return CURLE_FAILED_INIT;
}
curl_easy_setopt(mCurl, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(mCurl, CURLOPT_URL, link.c_str());
curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, writeFunctionBinary);
curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, &data);
return curl_easy_perform(mCurl);
}
long CURLWrapper::longInfo(CURLINFO info)
{
if (!mCurl) {
return 0;
}
long value;
curl_easy_getinfo(mCurl, info, &value);
return value;
}
std::string CURLWrapper::stringInfo(CURLINFO info)
{
if (!mCurl) {
return "";
}
char *value;
curl_easy_getinfo(mCurl, info, &value);
return value ? value : "";
}

View file

@ -0,0 +1,50 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef CURLWRAPPER
#define CURLWRAPPER
#include <string>
#include <vector>
#include <curl/curl.h>
class CURLWrapper
{
public:
CURLWrapper(const std::string &proxy);
~CURLWrapper();
CURLcode downloadText(const std::string &link, std::string &data);
CURLcode downloadBinary(const std::string &link, std::vector<unsigned char> &data);
long responseCode() { return longInfo(CURLINFO_RESPONSE_CODE); }
std::string contentType() { return stringInfo(CURLINFO_CONTENT_TYPE); }
std::string effectiveUrl() { return stringInfo(CURLINFO_EFFECTIVE_URL); }
protected:
long longInfo(CURLINFO info);
std::string stringInfo(CURLINFO info);
private:
CURL *mCurl;
};
#endif

View file

@ -0,0 +1,75 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <string.h>
#include "HTMLWrapper.h"
#include <libxml/HTMLtree.h>
HTMLWrapper::HTMLWrapper() : XMLWrapper()
{
}
bool HTMLWrapper::readHTML(const char *html, const char *url)
{
cleanup();
mDocument = htmlReadMemory(html, strlen(html), url, "", HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_COMPACT | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS);
if (mDocument) {
return true;
}
return false;
}
bool HTMLWrapper::saveHTML(std::string &html)
{
if (!mDocument) {
return false;
}
xmlChar *newHtml = NULL;
int newHtmlSize = 0;
htmlDocDumpMemoryFormat(mDocument, &newHtml, &newHtmlSize, 0);
if (newHtml) {
convertToString(newHtml, html);
xmlFree(newHtml);
return true;
}
return false;
}
bool HTMLWrapper::createHTML()
{
/* easy way */
return readHTML("<html><body></body></html>", "");
}
xmlNodePtr HTMLWrapper::getBody()
{
xmlNodePtr root = getRootElement();
if (!root) {
return NULL;
}
return findNode(root->children, "body", false);
}

View file

@ -0,0 +1,40 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef HTMLWRAPPER
#define HTMLWRAPPER
#include "XMLWrapper.h"
class HTMLWrapper : public XMLWrapper
{
public:
HTMLWrapper();
bool readHTML(const char *html, const char *url);
bool saveHTML(std::string &html);
bool createHTML();
xmlNodePtr getBody();
};
#endif

View file

@ -0,0 +1,289 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <iostream>
#include <string.h>
#include "XMLWrapper.h"
#include "XPathWrapper.h"
XMLWrapper::XMLWrapper()
{
mDocument = NULL;
mCharEncodingHandler = xmlFindCharEncodingHandler ("UTF8");
if (!mCharEncodingHandler) {
/* no encoding handler found */
std::cerr << "XMLWrapper::XMLWrapper - no encoding handler found" << std::endl;
}
}
XMLWrapper::~XMLWrapper()
{
cleanup();
xmlCharEncCloseFunc(mCharEncodingHandler);
}
XMLWrapper &XMLWrapper::operator=(const XMLWrapper &xml)
{
cleanup();
const xmlDocPtr document = xml.getDocument();
if (document) {
mDocument = xmlCopyDoc(document, 1);
}
return *this;
}
void XMLWrapper::cleanup()
{
if (mDocument) {
xmlFreeDoc(mDocument);
mDocument = NULL;
}
}
bool XMLWrapper::convertToString(const xmlChar *xmlText, std::string &text)
{
bool result = false;
xmlBufferPtr in = xmlBufferCreateStatic((void*) xmlText, xmlStrlen(xmlText));
xmlBufferPtr out = xmlBufferCreate();
int ret = xmlCharEncOutFunc(mCharEncodingHandler, out, in);
if (ret >= 0) {
result = true;
text = (char*) xmlBufferContent(out);
}
xmlBufferFree(in);
xmlBufferFree(out);
return result;
}
bool XMLWrapper::convertFromString(const char *text, xmlChar *&xmlText)
{
bool result = false;
xmlBufferPtr in = xmlBufferCreateStatic((void*) text, strlen(text));
xmlBufferPtr out = xmlBufferCreate();
int ret = xmlCharEncInFunc(mCharEncodingHandler, out, in);
if (ret >= 0) {
result = true;
xmlText = xmlBufferDetach(out);
}
xmlBufferFree(in);
xmlBufferFree(out);
return result;
}
xmlDocPtr XMLWrapper::getDocument() const
{
return mDocument;
}
xmlNodePtr XMLWrapper::getRootElement() const
{
if (mDocument) {
return xmlDocGetRootElement(mDocument);
}
return NULL;
}
bool XMLWrapper::readXML(const char *xml)
{
cleanup();
mDocument = xmlReadDoc(BAD_CAST xml, "", NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_COMPACT | XML_PARSE_NOENT | XML_PARSE_NOCDATA);
if (mDocument) {
return true;
}
return false;
}
bool XMLWrapper::getContent(xmlNodePtr node, std::string &content)
{
content.clear();
if (!node) {
return false;
}
xmlChar *xmlContent = xmlNodeGetContent(node);
if (!xmlContent) {
return true;
}
bool result = convertToString(xmlContent, content);
xmlFree(xmlContent);
return result;
}
bool XMLWrapper::setContent(xmlNodePtr node, const char *content)
{
if (!node) {
return false;
}
xmlChar *xmlContent;
if (!convertFromString(content, xmlContent)) {
return false;
}
xmlNodeSetContent(node, xmlContent);
xmlFree(xmlContent);
return true;
}
std::string XMLWrapper::nodeName(xmlNodePtr node)
{
std::string name;
if (node) {
convertToString(node->name, name);
}
return name;
}
std::string XMLWrapper::attrName(xmlAttrPtr attr)
{
std::string name;
if (attr) {
convertToString(attr->name, name);
}
return name;
}
xmlNodePtr XMLWrapper::findNode(xmlNodePtr node, const char *name, bool children)
{
if (node->name) {
if (xmlStrEqual(node->name, BAD_CAST name)) {
return node;
}
}
xmlNodePtr nodeFound = NULL;
if (children) {
if (node->children) {
nodeFound = findNode(node->children, name, children);
if (nodeFound) {
return nodeFound;
}
}
}
if (node->next) {
nodeFound = findNode(node->next, name, children);
if (nodeFound) {
return nodeFound;
}
}
return NULL;
}
bool XMLWrapper::getChildText(xmlNodePtr node, const char *childName, std::string &text)
{
if (node == NULL || node->children == NULL) {
return false;
}
xmlNodePtr child = findNode(node->children, childName, true);
if (!child) {
return false;
}
if (child->type != XML_ELEMENT_NODE) {
return false;
}
if (!child->children) {
return false;
}
if (child->children->type != XML_TEXT_NODE) {
return false;
}
if (child->children->content) {
return convertToString(child->children->content, text);
}
return true;
}
std::string XMLWrapper::getAttr(xmlNodePtr node, xmlAttrPtr attr)
{
return getAttr(node, (const char*) attr->name);
}
std::string XMLWrapper::getAttr(xmlNodePtr node, const char *name)
{
if (!node || !name) {
return "";
}
std::string value;
xmlChar *xmlValue = xmlGetProp(node, BAD_CAST name);
if (xmlValue) {
convertToString(xmlValue, value);
xmlFree(xmlValue);
}
return value;
}
bool XMLWrapper::setAttr(xmlNodePtr node, const char *name, const char *value)
{
if (!node || !name) {
return false;
}
xmlChar *xmlValue = NULL;
if (!convertFromString(value, xmlValue)) {
return false;
}
xmlAttrPtr xmlAttr = xmlSetProp (node, BAD_CAST name, xmlValue);
xmlFree(xmlValue);
return xmlAttr != NULL;
}
XPathWrapper *XMLWrapper::createXPath()
{
if (mDocument) {
return new XPathWrapper(*this);
}
return NULL;
}

View file

@ -0,0 +1,68 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef XMLWRAPPER
#define XMLWRAPPER
#include <string>
#include <libxml/parser.h>
class XPathWrapper;
class XMLWrapper
{
public:
XMLWrapper();
~XMLWrapper();
XMLWrapper &operator=(const XMLWrapper &xml);
void cleanup();
bool readXML(const char *xml);
xmlDocPtr getDocument() const;
xmlNodePtr getRootElement() const;
std::string nodeName(xmlNodePtr node);
std::string attrName(xmlAttrPtr attr);
xmlNodePtr findNode(xmlNodePtr node, const char *name, bool children = false);
bool getChildText(xmlNodePtr node, const char *childName, std::string &text);
bool getContent(xmlNodePtr node, std::string &content);
bool setContent(xmlNodePtr node, const char *content);
std::string getAttr(xmlNodePtr node, xmlAttrPtr attr);
std::string getAttr(xmlNodePtr node, const char *name);
bool setAttr(xmlNodePtr node, const char *name, const char *value);
XPathWrapper *createXPath();
bool convertToString(const xmlChar *xmlText, std::string &text);
bool convertFromString(const char *text, xmlChar *&xmlText);
protected:
xmlDocPtr mDocument;
xmlCharEncodingHandlerPtr mCharEncodingHandler;
};
#endif

View file

@ -0,0 +1,102 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "XPathWrapper.h"
#include "XMLWrapper.h"
XPathWrapper::XPathWrapper(XMLWrapper &xmlWrapper) : mXMLWrapper(xmlWrapper)
{
mContext = NULL;
mResult = NULL;
}
XPathWrapper::~XPathWrapper()
{
cleanup();
}
void XPathWrapper::cleanup()
{
if (mResult) {
xmlXPathFreeObject(mResult);
mResult = NULL;
}
if (mContext) {
xmlXPathFreeContext(mContext);
mContext = NULL;
}
}
bool XPathWrapper::compile(const char *expression)
{
cleanup();
xmlDocPtr document = mXMLWrapper.getDocument();
if (!document) {
return false;
}
mContext = xmlXPathNewContext(document);
if (!mContext) {
cleanup();
return false;
}
xmlChar *xmlExpression = NULL;
if (!mXMLWrapper.convertFromString(expression, xmlExpression)) {
cleanup();
return false;
}
mResult = xmlXPathEvalExpression(xmlExpression, mContext);
xmlFree(xmlExpression);
return true;
}
unsigned int XPathWrapper::count()
{
if (!mResult) {
return 0;
}
if (xmlXPathNodeSetIsEmpty(mResult->nodesetval)) {
return 0;
}
return mResult->nodesetval->nodeNr;
}
xmlNodePtr XPathWrapper::node(unsigned int index)
{
if (!mResult) {
return NULL;
}
if (xmlXPathNodeSetIsEmpty(mResult->nodesetval)) {
return NULL;
}
if (index >= (unsigned int) mResult->nodesetval->nodeNr) {
return NULL;
}
return mResult->nodesetval->nodeTab[index];
}

View file

@ -0,0 +1,51 @@
/****************************************************************
* RetroShare GUI is distributed under the following license:
*
* Copyright (C) 2012 by Thunder
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef XPATHWRAPPER
#define XPATHWRAPPER
#include <libxml/xpath.h>
class XMLWrapper;
class XPathWrapper
{
friend class XMLWrapper;
public:
~XPathWrapper();
void cleanup();
bool compile(const char *expression);
unsigned int count();
xmlNodePtr node(unsigned int index);
protected:
XPathWrapper(XMLWrapper &xmlWrapper);
XMLWrapper &mXMLWrapper;
xmlXPathContextPtr mContext;
xmlXPathObjectPtr mResult;
};
#endif