diff options
author | randomdan <randomdan@localhost> | 2010-06-10 18:18:39 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-06-10 18:18:39 +0000 |
commit | b91a4a2cb097b62daf8a3f74566b4d0b6b42258d (patch) | |
tree | 4b90718a96e8c22b796c0158178a4173fe32c3a5 | |
parent | Initial workings of project2 - renders gentoobrowse homepage (diff) | |
download | project2-b91a4a2cb097b62daf8a3f74566b4d0b6b42258d.tar.bz2 project2-b91a4a2cb097b62daf8a3f74566b4d0b6b42258d.tar.xz project2-b91a4a2cb097b62daf8a3f74566b4d0b6b42258d.zip |
Use xml++ with glib utf8
-rw-r--r-- | project2/Jamfile.jam | 8 | ||||
-rw-r--r-- | project2/envproc.cpp | 50 | ||||
-rw-r--r-- | project2/envproc.h | 5 | ||||
-rw-r--r-- | project2/p2web.cpp | 278 | ||||
-rw-r--r-- | project2/p2webMain.cpp | 5 | ||||
-rw-r--r-- | project2/rdbmsDataSource.cpp | 17 | ||||
-rw-r--r-- | project2/rdbmsDataSource.h | 10 | ||||
-rw-r--r-- | project2/sourceObject.cpp | 5 | ||||
-rw-r--r-- | project2/sourceObject.h | 7 | ||||
-rw-r--r-- | project2/sqlView.cpp | 35 | ||||
-rw-r--r-- | project2/sqlView.h | 15 | ||||
-rw-r--r-- | project2/ustring.h | 9 |
12 files changed, 87 insertions, 357 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 7505f92..c662255 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -1,6 +1,6 @@ -alias libxml2 : : : : - <cflags>"`pkg-config --cflags libxml-2.0`" - <linkflags>"`pkg-config --libs libxml-2.0`" ; +alias libxmlpp : : : : + <cflags>"`pkg-config --cflags libxml++-2.6`" + <linkflags>"`pkg-config --libs libxml++-2.6`" ; lib fcgi : : <name>fcgi ; lib odbc : : <name>odbc ; @@ -11,7 +11,7 @@ exe p2web : rdbmsDataSource.cpp sqlView.cpp envproc.cpp - libxml2 + libxmlpp ../libmisc ../libodbcpp : <include>../libmisc/ diff --git a/project2/envproc.cpp b/project2/envproc.cpp index 0313c0f..f280aa0 100644 --- a/project2/envproc.cpp +++ b/project2/envproc.cpp @@ -2,7 +2,7 @@ #include "rdbmsDataSource.h" #include "sqlView.h" #include <map> -#include <libxml/tree.h> +#include <libxml++/parsers/domparser.h> #include <libxml/xinclude.h> #include <boost/shared_ptr.hpp> #include <boost/any.hpp> @@ -18,12 +18,15 @@ EnvironmentProcessor::init() template <class X, class Y> void -collectAll(std::map<ustring, Y> & objs, xmlNodePtr node, const ustring & name) +collectAll(std::map<std::string, Y> & objs, const xmlpp::Element * node, const Glib::ustring & name) { - if (name == node->name) { + if (!node) { + return; + } + if (name == node->get_name()) { fprintf(stderr, "Found a %s\n", name.c_str()); try { - objs[xmlGetProp(node, BAD_CAST "name")] = Y(new X(node)); + objs[node->get_attribute_value("name").raw()] = Y(new X(node)); fprintf(stderr, "Load succeeded\n"); } catch (const std::exception & e) { @@ -36,43 +39,48 @@ collectAll(std::map<ustring, Y> & objs, xmlNodePtr node, const ustring & name) } } else { - for (xmlNodePtr child = node->children; child; child = child->next) { - collectAll<X, Y>(objs, child, name); + BOOST_FOREACH(xmlpp::Node * child, node->get_children()) { + collectAll<X, Y>(objs, dynamic_cast<const xmlpp::Element *>(child), name); } } } -xmlDocPtr +boost::shared_ptr<xmlpp::Document> EnvironmentProcessor::process() { - xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); - xmlDocPtr pageXDoc = xmlReadFile(("present/" + page + ".xml").c_str(), NULL, XML_PARSE_XINCLUDE); - while (xmlXIncludeProcess(pageXDoc) > 0); - xmlNodePtr root = xmlDocGetRootElement(pageXDoc); + fprintf(stderr, "parsing present .xml\n"); + xmlpp::DomParser present("present/" + page + ".xml"); + fprintf(stderr, "performing xincludes\n"); + while (xmlXIncludeProcessFlags(present.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0); + fprintf(stderr, "getting root\n"); + xmlpp::Element * presentRoot = present.get_document()->get_root_node(); // Collect datasources + fprintf(stderr, "collecting datasources\n"); RdbmsDataSources rdbmsDataSources; - collectAll<_RdbmsDataSource>(rdbmsDataSources, root, BAD_CAST "rdbmsdatasource"); + collectAll<_RdbmsDataSource>(rdbmsDataSources, presentRoot, "rdbmsdatasource"); // Collect views + fprintf(stderr, "collecting sqlviews\n"); SqlViews sqlViews; - collectAll<_SqlView>(sqlViews, root, BAD_CAST "sqlview"); + collectAll<_SqlView>(sqlViews, presentRoot, "sqlview"); // - xmlNodePtr root_node = xmlNewNode(NULL, xmlGetProp(root, BAD_CAST "root")); + boost::shared_ptr<xmlpp::Document> responseDoc = boost::shared_ptr<xmlpp::Document>(new xmlpp::Document("1.0")); + xmlpp::Element * responseRoot = responseDoc->create_root_node(presentRoot->get_attribute_value("root")); try { BOOST_FOREACH(SqlViews::value_type s, sqlViews) { - s.second->execute(rdbmsDataSources, root_node); + s.second->execute(rdbmsDataSources, responseRoot); } } catch (...) { } - xmlDocSetRootElement(doc, root_node); + fprintf(stderr, "done views\n"); char * buf; if (asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", - xmlGetProp(root, BAD_CAST "style")) > 0) { - xmlAddPrevSibling(root_node, - xmlNewDocPI(doc, BAD_CAST "xml-stylesheet", BAD_CAST buf)); + presentRoot->get_attribute_value("style").c_str()) > 0) { + xmlAddPrevSibling(responseRoot->cobj(), + xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf)); } free(buf); - xmlFreeDoc(pageXDoc); - return doc; + fprintf(stderr, "done style pi\n"); + return responseDoc; } diff --git a/project2/envproc.h b/project2/envproc.h index 64e13c1..8d434df 100644 --- a/project2/envproc.h +++ b/project2/envproc.h @@ -2,7 +2,8 @@ #define ENVPROC_H #include <string> -#include <libxml/tree.h> +#include <libxml++/document.h> +#include <boost/shared_ptr.hpp> #include "regexex.h" class EnvironmentProcessor { @@ -16,7 +17,7 @@ class EnvironmentProcessor { { init(); } - virtual xmlDoc * process(); + virtual boost::shared_ptr<xmlpp::Document> process(); private: void init(); diff --git a/project2/p2web.cpp b/project2/p2web.cpp deleted file mode 100644 index 3d1b320..0000000 --- a/project2/p2web.cpp +++ /dev/null @@ -1,278 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <map> -#include <stdlib.h> -#include <libxml/tree.h> -#include "connection.h" -#include "selectcommand.h" -#include "column.h" -#include "smartpointer.h" -#include "dsn.h" -#include "xml.h" -#include "regexex.h" - -template <class X> -class Handle : public X, public IsRefCounted { - public: - template <class P1> - Handle(const P1 & p1) : X(p1) - { - } - Handle() - { - } -}; - -typedef Handle<ODBC::Connection> ConnHandle; -typedef SmartPointer<ConnHandle> ConnHandlePtr; -typedef std::map<int, ConnHandlePtr> ConnectionPool; - -void bindQueryParams(ODBC::Connection & db, ODBC::SelectCommand & sel, int pqid, ODBC::SelectCommand * parent, - const StringSet & elems, const RegMultiMatch & qs); - -void -addQueryResultsToXml(ODBC::Connection & wdb, ConnectionPool cp, xmlNode * root_node, int dsn, const ODBC::String & sql, - const ODBC::String & name, const ODBC::String & recordName, int pqid, ODBC::SelectCommand * parent, - const StringSet & elems, const RegMultiMatch & qs) -{ - typedef std::map<ODBC::String, xmlNode *> Columns; - xmlNode * resultXml = xmlNewChild(root_node, NULL, name.c_str(), NULL); - ODBC::SelectCommand query(*cp[dsn], sql); - bindQueryParams(wdb, query, pqid, parent, elems, qs); - while (query.fetch()) { - Columns columns; - unsigned int cols = query.columnCount(); - xmlNode * record = xmlNewChild(resultXml, NULL, recordName.c_str(), NULL); - for (unsigned int col = 0; col < cols; col += 1) { - const unsigned char * nameattr = query[col].name.c_str(); - unsigned char * name, * attr = NULL; - switch (sscanf((const char *)nameattr, "%a[^_]_%as", &name, &attr)) - { - case 0: - return; // Make me an exception - break; - case 1: - attr = NULL; - break; - } - char * buf = NULL; - query[col].writeToBuf(&buf); - if (buf) { - if (attr) { - if (strcmp((const char *)attr, ".") == 0) { - xmlNewProp(record, name, BAD_CAST buf); - } - else { - Columns::iterator i = columns.find(attr); - if (i != columns.end()) { - xmlNewProp(i->second, name, BAD_CAST buf); - } - } - } - else if (strcmp((const char *)name, "value") == 0) { - xmlNodeAddContent(record, BAD_CAST buf); - } - else { - columns[name] = xmlNewTextChild(record, NULL, name, BAD_CAST buf); - } - free(buf); - } - free(name); - free(attr); - } - ODBC::SelectCommand queries(wdb, - "SELECT d.id AS dsn, q.id AS query, q.sql, q.name, q.recordname, pq.id \ - FROM dsn d, page_query pq, query q \ - WHERE pq.parent = ? \ - AND q.id = pq.query \ - AND d.id = q.dsn"); - queries.bindParamI(0, pqid); - while (queries.fetch()) { - addQueryResultsToXml(wdb, cp, record, queries["dsn"], - queries["sql"], queries["name"], queries["recordname"], queries["id"], &query, elems, qs); - } - } -} - -void -bindQueryParams(ODBC::Connection & db, ODBC::SelectCommand & sel, int pqid, ODBC::SelectCommand * parent, - const StringSet & elems, const RegMultiMatch & qs) -{ - ODBC::SelectCommand params(db, - "SELECT paramidx, source, key \ - FROM page_query_params \ - WHERE pqid = ?"); - params.bindParamI(0, pqid); - while (params.fetch()) { - const char * key = params["key"]; - const char * src = params["source"]; - int idx = params["paramidx"]; - switch (*src) { - case 'v': // Value - sel.bindParamS(idx, key); - break; - case 'u': // URL token - sel.bindParamS(idx, elems[atoi(key)]); - break; - case 's': // Session variable - break; - case 'q': // Query string param - for(RegMultiMatch::const_iterator u = qs.begin(); u != qs.end(); u++) { - if ((*u)[0] == key) { - sel.bindParamS(idx, (*u)[1]); - } - } - break; - case 'p': // Parent column value - if (parent) { - (*parent)[key].rebind(&sel, idx); - } - break; - default: - ; - } - } -} - - -int -main(int, char**) -{ - try { - std::string request_uri(getenv("REQUEST_URI")); - std::string query_string(getenv("QUERY_STRING")); - StringSet elems(regexExtractSet("/([^/?]+)", request_uri.c_str())); - RegMultiMatch params(regexExtractMulti("&?([^=]+)=?([^&]*)", query_string.c_str(), 2)); - xmlDoc * doc = xmlNewDoc(BAD_CAST "1.0"); - xmlNode * root_node = NULL; - ODBC::String fqdn(getenv("HTTP_HOST")); - ODBC::DSN main("dbweb", "dbweb", "dbweb"); - ODBC::Connection db(main); - int pageId = 0; - std::string page(elems.size() > 0 ? elems[0] : "index"); - { - ODBC::SelectCommand pageHeaders(db, - "SELECT p.id, p.name, p.style, p.documentname \ - FROM site s, domainname dn, page p \ - WHERE s.id = dn.site \ - AND p.pattern = ? \ - AND dn.fqdn = ? \ - AND p.site = s.id"); - pageHeaders.bindParamS(0, page); - pageHeaders.bindParamS(1, fqdn); - while (pageHeaders.fetch()) { - pageId = pageHeaders["id"]; - root_node = xmlNewNode(NULL, pageHeaders["documentname"]); - xmlDocSetRootElement(doc, root_node); - if (!pageHeaders["style"].isNull()) { - printf("Content-type: text/xml-xslt\r\n"); - char * buf; - if (asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", - pageHeaders["style"].operator const char *()) > 0) { - xmlAddPrevSibling(root_node, - xmlNewDocPI(doc, BAD_CAST "xml-stylesheet", BAD_CAST buf)); - } - free(buf); - } - else { - printf("Content-type: text/xml\r\n"); - } - xmlNewProp(root_node, BAD_CAST "title", pageHeaders["name"]); - } - } - // These were for debug... but why not pass them on? - xmlNsPtr dbwebns = xmlNewNs(root_node, BAD_CAST "http://dbweb.randomdan.homeip.net/", BAD_CAST "dbweb"); - xmlNewChild(root_node, dbwebns, BAD_CAST "fqdn", fqdn.c_str()); - xmlNewChild(root_node, dbwebns, BAD_CAST "requesturi", BAD_CAST request_uri.c_str()); - // URL elements - xmlNode * uriElems = xmlNewChild(root_node, dbwebns, BAD_CAST "uriElems", NULL); - for(StringSet::const_iterator u = elems.begin(); u != elems.end(); u++) { - xmlNewChild(uriElems, dbwebns, BAD_CAST "uriElem", BAD_CAST u->c_str()); - } - // Parameters - xmlNode * paramsXml = xmlNewChild(root_node, dbwebns, BAD_CAST "params", NULL); - for(RegMultiMatch::const_iterator u = params.begin(); u != params.end(); u++) { - xmlNode * param = xmlNewChild(paramsXml, NULL, BAD_CAST "param", BAD_CAST (*u)[1].c_str()); - xmlNewProp(param, BAD_CAST "name", BAD_CAST (*u)[0].c_str()); - } - ConnectionPool cp; - // Load DSNs -#ifdef DEBUG - xmlNode * dsnsXml = xmlNewChild(root_node, dbwebns, BAD_CAST "DSNs", NULL); -#endif - { - ODBC::SelectCommand dsns(db, - "SELECT DISTINCT d.id AS id, d.connectionstring AS connstr \ - FROM dsn d, page_query pq, query q \ - WHERE pq.page = ? \ - AND q.id = pq.query \ - AND d.id = q.dsn"); - dsns.bindParamI(0, pageId); - while (dsns.fetch()) { - int id = dsns["id"]; - ODBC::String connstr = dsns["connstr"]; -#ifdef DEBUG - xmlNode * dsnXml = xmlNewChild(dsnsXml, NULL, BAD_CAST "DSN", NULL); - xmlNewTextChildf(dsnXml, "id", "%d", id); - xmlNewTextChildf(dsnXml, "connectionstring", "%s", connstr.c_str()); -#endif - cp[id] = new ConnHandle(connstr); - } - } - // Exec queries - { - ODBC::SelectCommand queries(db, - "SELECT d.id AS dsn, q.id AS query, q.sql, q.name, q.recordname, pq.id \ - FROM dsn d, page_query pq, query q \ - WHERE pq.page = ? \ - AND q.id = pq.query \ - AND d.id = q.dsn \ - AND pq.parent IS NULL"); - queries.bindParamI(0, pageId); -#ifdef DEBUG - xmlNode * queriesXml = xmlNewChild(root_node, dbwebns, BAD_CAST "queries", NULL); -#endif - while (queries.fetch()) { -#ifdef DEBUG - int query = queries["query"]; -#endif - int dsn = queries["dsn"]; - ODBC::String sql = queries["sql"]; - ODBC::String name = queries["name"]; - ODBC::String recordName = queries["recordname"]; -#ifdef DEBUG - xmlNode * queryXml = xmlNewChild(queriesXml, NULL, BAD_CAST "query", NULL); - xmlNewTextChildf(queryXml, "query", "%d", query); - xmlNewTextChildf(queryXml, "name", "%s", name.c_str()); - xmlNewTextChildf(queryXml, "dsn", "%d", dsn); - xmlNewTextChildf(queryXml, "sql", "%s", sql.c_str()); -#endif - addQueryResultsToXml(db, cp, root_node, dsn, sql, name, recordName, queries["id"], NULL, elems, params); - } - } - printf("\r\n"); - xmlDocFormatDump(stdout, doc, 1); - xmlFreeDoc(doc); - } - catch (std::exception & e) { - printf("Content-type: text/xml\r\n"); - printf("\r\n"); - xmlDoc * doc = xmlNewDoc(BAD_CAST "1.0"); - xmlNode * root_node = xmlNewNode(NULL, BAD_CAST "error"); - xmlDocSetRootElement(doc, root_node); - xmlNewTextChildf(root_node, "what", "%s", e.what()); - xmlDocFormatDump(stdout, doc, 1); - } - catch (...) { - printf("Content-type: text/xml\r\n"); - printf("\r\n"); - xmlDoc * doc = xmlNewDoc(BAD_CAST "1.0"); - xmlNode * root_node = xmlNewNode(NULL, BAD_CAST "error"); - xmlNewTextChildf(root_node, "what", "Unknown"); - xmlNewTextChildf(root_node, "detail", "Exception thrown does not inherit from std::exception"); - xmlDocSetRootElement(doc, root_node); - xmlDocFormatDump(stdout, doc, 1); - } - return 0; -} - diff --git a/project2/p2webMain.cpp b/project2/p2webMain.cpp index 716495f..e8cef2c 100644 --- a/project2/p2webMain.cpp +++ b/project2/p2webMain.cpp @@ -19,13 +19,12 @@ int main(void) try { EnvironmentProcessor ep(boost::bind(FCGX_GetParam, _1, envp)); - xmlDoc * doc = ep.process(); + boost::shared_ptr<xmlpp::Document> doc = ep.process(); FCGX_FPrintF(_out, "Content-type: text/xml-xslt\r\n\r\n"); xmlOutputBufferPtr out = xmlOutputBufferCreateIO( xmlWrite, NULL, _out, xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8)); - xmlSaveFileTo(out, doc, NULL); - xmlFreeDoc(doc); + xmlSaveFileTo(out, doc->cobj(), NULL); } catch (const std::exception & e) { FCGX_FPrintF(_out, "Content-type: text/plain\r\n\r\n"); diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index f4b3b4e..53a769c 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -1,18 +1,27 @@ #include "rdbmsDataSource.h" #include "xml.h" +#include <libxml++/nodes/textnode.h> -_RdbmsDataSource::_RdbmsDataSource(xmlNodePtr p) : +_RdbmsDataSource::_RdbmsDataSource(const xmlpp::Element * p) : _Project2SourceObject(p), - masterDsn(xmlGetNodeValue<ustring>(p, BAD_CAST "masterdsn", BAD_CAST "")) + masterDsn(dynamic_cast<const xmlpp::Element&>(*p->get_children("masterdsn").front()).get_child_text()->get_content()) { fprintf(stderr, "Created RDBMS Datasource %s (%s)\n", name.c_str(), masterDsn.c_str()); } -_RdbmsDataSource::operator ODBC::Connection &() +ODBC::Connection & +_RdbmsDataSource::getWritable() { if (!database) { - database = boost::shared_ptr<ODBC::Connection>(new ODBC::Connection(masterDsn)); + database = boost::shared_ptr<ODBC::Connection>(new ODBC::Connection(masterDsn.c_str())); } return *database; } +ODBC::Connection & +_RdbmsDataSource::getReadonly() +{ + // For now :) + return getWritable(); +} + diff --git a/project2/rdbmsDataSource.h b/project2/rdbmsDataSource.h index 74ed829..49266e1 100644 --- a/project2/rdbmsDataSource.h +++ b/project2/rdbmsDataSource.h @@ -6,18 +6,18 @@ #include <map> #include "sourceObject.h" #include "connection.h" -#include "ustring.h" class _RdbmsDataSource : public _Project2SourceObject { public: - _RdbmsDataSource(xmlNodePtr p); - operator ODBC::Connection &(); - const ustring masterDsn; + _RdbmsDataSource(const xmlpp::Element * p); + ODBC::Connection & getReadonly(); + ODBC::Connection & getWritable(); + const Glib::ustring masterDsn; private: boost::shared_ptr<ODBC::Connection> database; }; typedef boost::shared_ptr<_RdbmsDataSource> RdbmsDataSource; -typedef std::map<ustring, RdbmsDataSource> RdbmsDataSources; +typedef std::map<std::string, RdbmsDataSource> RdbmsDataSources; #endif diff --git a/project2/sourceObject.cpp b/project2/sourceObject.cpp index a441e77..fc57b91 100644 --- a/project2/sourceObject.cpp +++ b/project2/sourceObject.cpp @@ -1,8 +1,7 @@ #include "sourceObject.h" -_Project2SourceObject::_Project2SourceObject(xmlNodePtr p) : - name(xmlGetProp(p, BAD_CAST "name")) +_Project2SourceObject::_Project2SourceObject(const xmlpp::Element * p) : + name(p->get_attribute_value("name").raw()) { - fprintf(stderr, "Created object %s\n", name.c_str()); } diff --git a/project2/sourceObject.h b/project2/sourceObject.h index d6531ff..fc010d9 100644 --- a/project2/sourceObject.h +++ b/project2/sourceObject.h @@ -1,13 +1,12 @@ #ifndef SOURCEOBJECT_H #define SOURCEOBJECT_H -#include "ustring.h" -#include <libxml/tree.h> +#include <libxml++/nodes/element.h> class _Project2SourceObject { public: - _Project2SourceObject(xmlNodePtr p); - const ustring name; + _Project2SourceObject(const xmlpp::Element * p); + const std::string name; }; #endif diff --git a/project2/sqlView.cpp b/project2/sqlView.cpp index ca1c135..ad88514 100644 --- a/project2/sqlView.cpp +++ b/project2/sqlView.cpp @@ -3,28 +3,29 @@ #include "selectcommand.h" #include "column.h" #include <string.h> +#include <libxml++/nodes/textnode.h> -_SqlView::_SqlView(xmlNodePtr p) : +_SqlView::_SqlView(const xmlpp::Element * p) : _Project2SourceObject(p), - sql(xmlGetNodeValue<ustring>(p, BAD_CAST "sql", BAD_CAST "")), - dataSource(xmlGetProp(p, BAD_CAST "datasource")), - recordName(xmlGetProp(p, BAD_CAST "recordname")) + sql(dynamic_cast<const xmlpp::Element&>(*p->get_children("sql").front()).get_child_text()->get_content()), + dataSource(p->get_attribute_value("datasource")), + recordName(p->get_attribute_value("recordname")) { } -void _SqlView::execute(RdbmsDataSources s, xmlNodePtr par) const +void _SqlView::execute(RdbmsDataSources s, xmlpp::Element * par) const { - typedef std::map<ODBC::String, xmlNode *> Columns; + typedef std::map<ODBC::String, xmlpp::Element *> Columns; fprintf(stderr, "executing\n"); - ODBC::SelectCommand query(*s[dataSource], sql); - xmlNode * set = xmlNewChild(par, NULL, name.c_str(), NULL); + ODBC::SelectCommand query(s[dataSource]->getReadonly(), sql.c_str()); + xmlpp::Element * set = par->add_child(name); while (query.fetch()) { Columns columns; unsigned int cols = query.columnCount(); - xmlNode * record = xmlNewChild(set, NULL, recordName.c_str(), NULL); + xmlpp::Element * record = set->add_child(recordName); for (unsigned int col = 0; col < cols; col += 1) { const unsigned char * nameattr = query[col].name.c_str(); - unsigned char * name, * attr = NULL; + char * name, * attr = NULL; switch (sscanf((const char *)nameattr, "%a[^_]_%as", &name, &attr)) { case 0: @@ -38,21 +39,23 @@ void _SqlView::execute(RdbmsDataSources s, xmlNodePtr par) const query[col].writeToBuf(&buf); if (buf) { if (attr) { - if (strcmp((const char *)attr, ".") == 0) { - xmlNewProp(record, name, BAD_CAST buf); + if (strcmp(attr, ".") == 0) { + record->set_attribute(name, buf); } else { Columns::iterator i = columns.find(attr); if (i != columns.end()) { - xmlNewProp(i->second, name, BAD_CAST buf); + i->second->set_attribute(name, buf); } } } - else if (strcmp((const char *)name, "value") == 0) { - xmlNodeAddContent(record, BAD_CAST buf); + else if (strcmp(name, "value") == 0) { + record->set_child_text(buf); } else { - columns[name] = xmlNewTextChild(record, NULL, name, BAD_CAST buf); + xmlpp::Element * ch = record->add_child(name); + ch->set_child_text(buf); + columns[name] = ch; } free(buf); } diff --git a/project2/sqlView.h b/project2/sqlView.h index 16812d2..b2e7d86 100644 --- a/project2/sqlView.h +++ b/project2/sqlView.h @@ -1,23 +1,22 @@ #ifndef SQLVIEW_H #define SQLVIEW_H -#include <libxml/tree.h> +#include <libxml++/nodes/element.h> #include <boost/shared_ptr.hpp> #include <map> #include "sourceObject.h" -#include "ustring.h" #include "rdbmsDataSource.h" class _SqlView : public _Project2SourceObject { public: - _SqlView(xmlNodePtr p); - void execute(RdbmsDataSources s, xmlNodePtr) const; - const ustring sql; - const ustring dataSource; - const ustring recordName; + _SqlView(const xmlpp::Element * p); + void execute(RdbmsDataSources s, xmlpp::Element *) const; + const Glib::ustring sql; + const Glib::ustring dataSource; + const Glib::ustring recordName; }; typedef boost::shared_ptr<_SqlView> SqlView; -typedef std::map<ustring, SqlView> SqlViews; +typedef std::map<std::string, SqlView> SqlViews; #endif diff --git a/project2/ustring.h b/project2/ustring.h deleted file mode 100644 index cfed0c4..0000000 --- a/project2/ustring.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef USTRING_H -#define USTRING_H - -#include <string> - -typedef std::basic_string<unsigned char> ustring; - -#endif - |