message-utilities.cpp revision 12107abbb78a8201106786c55ec2dda6b2cdab2d
/**
* Message generation utilities
*
* Authors:
* David Yip <yipdw@rose-hulman.edu>
* Jonas Collaros, Stephen Montgomery
*
* Copyright (c) 2004-2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "xml/attribute-record.h"
#include "jabber_whiteboard/defines.h"
#include "jabber_whiteboard/typedefs.h"
#include "jabber_whiteboard/node-utilities.h"
#include "jabber_whiteboard/message-utilities.h"
#include "jabber_whiteboard/node-tracker.h"
#include <iostream>
namespace Inkscape {
namespace Whiteboard {
// This method can be instructed to not build a message string but only collect nodes that _would_ be transmitted
// and subsequently added to the tracker. This can be useful in the case where an Inkboard user is the only one
// in a chatroom and therefore needs to fill out the node tracker, but does not need to build the message string.
// This can be controlled with the only_collect_nodes flag, which will only create pointers to new XML::Nodes
// in the maps referenced by newidsbuf and newnodesbuf. Passing NULL as the message buffer has the same effect.
//
// only_collect_nodes defaults to false because most invocations of this method also use the message string.
void
MessageUtilities::newObjectMessage(Glib::ustring* msgbuf, KeyToNodeMap& newidsbuf, NodeToKeyMap& newnodesbuf, NewChildObjectMessageList& childmsgbuf, XMLNodeTracker* xmt, Inkscape::XML::Node const* node, bool only_collect_nodes, bool collect_children)
{
// Initialize pointers
bool only_add_children = false;
}
}
}
}
}
}
}
// Generate an id for this object and append it onto the list, if
// it's not already in the tracker
} else {
}
} else {
g_warning("Node %p (name %s) is a special node, but it could not be found in the node tracker (possible unexpected duplicate?) Generating unique ID anyway.", node, node->name());
}
only_add_children = true;
}
// If we're only adding children (i.e. this is a special node)
// don't process the given node.
// <MESSAGE_NEWOBJ>
// <MESSAGE_PARENT>
}
// </MESSAGE_NEWOBJ><MESSAGE_CHILD>id</MESSAGE_CHILD>
// <MESSAGE_REF>refid</MESSAGE_REF>
}
// <MESSAGE_NODETYPE>*node.type()</MESSAGE_NODETYPE>
// <MESSAGE_CONTENT>node->content()</MESSAGE_CONTENT>
}
// <MESSAGE_NAME>name</MESSAGE_NAME>
}
// </MESSAGE_NEWOBJ>
// if ID is NULL, then we have a real problem -- we were not able to find a key
// nor generate one. The only thing we can really do here is abort, since we have
// no way to let the other client(s) uniquely identify this object.
/* FIXME: If this indicates a programming bug, then don't request translation with
* _(...): it is most useful in untranslated form so that developers may search for
* it when someone reports it in a bug report (as we want users to do for all bugs,
* as indicated by it being a g_warning string).
*
* Otherwise, if it is not a programming bug but a network error or a bug in the
* remote peer (perhaps running different software) or whatever, then present it in
* an alert box, and avoid use of technical jargon `NULL'.
*/
g_warning(_("ID for new object is NULL even after generation and lookup attempts: the new object will NOT be sent, nor will any of its child objects!"));
return;
} else {
}
// Collect new object's attributes and append them onto the msgbuf
MessageUtilities::objectChangeMessage(msgbuf, xmt, id, g_quark_to_string(attrlist->key), NULL, attrlist->value, false);
}
}
if (!only_collect_nodes) {
}
// Collect any child objects of this new object
for ( Inkscape::XML::Node const *child = node->firstChild(); child != NULL; child = child->next() ) {
MessageUtilities::newObjectMessage(&childbuf, newidsbuf, newnodesbuf, childmsgbuf, xmt, child, only_collect_nodes);
if (!only_collect_nodes) {
// we're recursing down the tree, so we're picking up child nodes first
// and parents afterwards
// childmsgbuf.push_front(childbuf);
}
}
}
}
void
MessageUtilities::objectChangeMessage(ustring* msgbuf, XMLNodeTracker* xmt, std::string const id, gchar const* key, gchar const* oldval, gchar const* newval, bool is_interactive)
{
// Construct message
// <MESSAGE_CHANGE><MESSAGE_ID>id</MESSAGE_ID>
// <MESSAGE_KEY>key</MESSAGE_KEY>
}
// <MESSAGE_OLDVAL>oldval</MESSAGE_OLDVAL>
}
// <MESSAGE_NEWVAL>newval</MESSAGE_NEWVAL>
}
// <MESSAGE_ISINTERACTIVE>is_interactive</MESSAGE_ISINTERACTIVE>
if (is_interactive) {
(*msgbuf) += "true";
} else {
(*msgbuf) += "false";
}
// </MESSAGE_CHANGE>
}
void
MessageUtilities::objectDeleteMessage(Glib::ustring* msgbuf, XMLNodeTracker* xmt, Inkscape::XML::Node const& parent, Inkscape::XML::Node const& child, Inkscape::XML::Node const* prev)
{
/*
gchar const* parentid = NULL;
gchar const* previd = NULL;
gchar const* childid = NULL;
childid = child.attribute("id");
parentid = parent.attribute("id");
if (prev != NULL) {
previd = prev->attribute("id");
}*/
// <MESSAGE_DELETE><MESSAGE_PARENT>parentid</MESSAGE_PARENT>
}
// <MESSAGE_CHILD>childid</MESSAGE_CHILD>
}
// <MESSAGE_REF>previd</MESSAGE_REF>
}
// </MESSAGE_DELETE>
}
}
void
MessageUtilities::contentChangeMessage(Glib::ustring& msgbuf, std::string const nodeid, Util::shared_ptr<char> old_value, Util::shared_ptr<char> new_value)
{
// <MESSAGE_NODECONTENT>
// <MESSAGE_ID>nodeid</MESSAGE_ID>
// <MESSAGE_OLDVAL>old_value</MESSAGE_OLDVAL>
// <MESSAGE_NEWVAL>new_value</MESSAGE_NEWVAL>
// </MESSAGE_NODECONTENT>
}
}
void
MessageUtilities::childOrderChangeMessage(Glib::ustring& msgbuf, std::string const childid, std::string const oldprevid, std::string const newprevid)
{
// <MESSAGE_ORDERCHANGE>
// <MESSAGE_ID>nodeid</MESSAGE_ID>
// <MESSAGE_OLDVAL>oldprevid</MESSAGE_OLDVAL>
/*
msgbuf = msgbuf + "<" + MESSAGE_OLDVAL + ">";
msgbuf += (*oldprevid);
msgbuf = msgbuf + "</" + MESSAGE_OLDVAL + ">";
*/
// <MESSAGE_NEWVAL>newprevid</MESSAGE_NEWVAL>
// </MESSAGE_ORDERCHANGE>
}
}
bool
{
return false;
}
// See if we have a valid start tag, i.e. < ... >. If we do,
// continue; if not, stop and return NULL.
//
// find_first_of returns ULONG_MAX when it cannot find the first
// instance of the given character.
if (startDelim != ULONG_MAX) {
if (endDelim > startDelim) {
// construct end tag (</buf.data>)
return true;
}
}
}
}
}
return false;
}
bool
{
return false;
}
// Read desired tag type out of buffer, and append
// < > to it
searchterm + ">";
// Find ending tag starting at the point at the end of
// the start tag.
return true;
}
}
return false;
}
{
return buf;
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :