'std::string'ify most interfaces
authorKlaus Kaempf <kkaempf@suse.de>
Sun, 8 Jan 2006 12:49:15 +0000 (12:49 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Sun, 8 Jan 2006 12:49:15 +0000 (12:49 +0000)
25 files changed:
zypp/solver/detail/Importance.cc
zypp/solver/detail/Importance.h
zypp/solver/temporary/Channel.cc
zypp/solver/temporary/Channel.h
zypp/solver/temporary/Match.cc
zypp/solver/temporary/MultiWorld.cc
zypp/solver/temporary/MultiWorld.h
zypp/solver/temporary/Package.cc
zypp/solver/temporary/PackageUpdate.cc
zypp/solver/temporary/PackageUpdate.h
zypp/solver/temporary/ServiceWorld.h
zypp/solver/temporary/StoreWorld.cc
zypp/solver/temporary/StoreWorld.h
zypp/solver/temporary/Subscription.cc
zypp/solver/temporary/Subscription.h
zypp/solver/temporary/UndumpWorld.cc
zypp/solver/temporary/UndumpWorld.h
zypp/solver/temporary/World.cc
zypp/solver/temporary/World.h
zypp/solver/temporary/XmlNode.cc
zypp/solver/temporary/XmlNode.h
zypp/solver/temporary/XmlParser.cc
zypp/solver/temporary/utils.cc
zypp/solver/temporary/utils.h
zypp/solver/testsuite/deptestomatic.cc

index 178b8d0..8f1f0a3 100644 (file)
@@ -32,104 +32,101 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
-
-      const Importance & Importance::Undefined= Importance("undefined");
-
-      //---------------------------------------------------------------------------
-      string
-      Importance::asString ( void ) const
-      {
-          return toString (*this);
-      }
-
-
-      string
-      Importance::toString ( const Importance & importance )
-      {
-          string res;
-
-          switch (importance.importance()) {
-       case IMPORTANCE_UNDEFINED:      res = "undefined"; break;
-       case IMPORTANCE_INVALID:        res = "invalid"; break;
-       case IMPORTANCE_NECESSARY:      res = "necessary"; break;
-       case IMPORTANCE_URGENT:         res = "urgent"; break;
-       case IMPORTANCE_SUGGESTED:      res = "suggested"; break;
-       case IMPORTANCE_FEATURE:        res = "feature"; break;
-       case IMPORTANCE_MINOR:          res = "minor"; break;
-       default:
-           WAR << "invalid importance "<< importance.importance() << endl;
-           res = "invalid";
-          }
-          return res;
-      }
-
-
-      ostream &
-      Importance::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
-
-
-      ostream&
-      operator<<( ostream& os, const Importance& importance)
-      {
-          return os << importance.asString();
-      }
-
-      //---------------------------------------------------------------------------
-
-      Importance::Importance(const char *importance_str)
-      {
-          _importance = IMPORTANCE_INVALID;
-          if (importance_str != NULL) {
-       switch (*importance_str) {
-           case 'f':
-               if (!strcmp (importance_str, "feature")) {
-                   _importance = IMPORTANCE_FEATURE;
-               }
-           break;
-           case 'm':
-               if (!strcmp (importance_str, "minor")) {
-                   _importance = IMPORTANCE_MINOR;
-               }
-           break;
-           case 'n':
-               if (!strcmp (importance_str, "necessary")) {
-                   _importance = IMPORTANCE_NECESSARY;
-               }
-           break;
-           case 's':
-               if (!strcmp (importance_str, "suggested")) {
-                   _importance = IMPORTANCE_SUGGESTED;
-               }
-           break;
-           case 'u':
-               if (!strcmp (importance_str, "urgent")) {
-                   _importance = IMPORTANCE_URGENT;
-               }
-               else if (!strcmp (importance_str, "undefined")) {
-                   _importance = IMPORTANCE_UNDEFINED;
-               }
-           default:
-           break;
-       }
-          }
-          if (_importance == IMPORTANCE_INVALID)
-             WAR << "invalid importance '"
-                 << (importance_str ? importance_str : "<null>")
-                 << "'" << endl;
-
-      }
-
-
-      Importance::~Importance()
-      {
-      }
-
-      ///////////////////////////////////////////////////////////////////
+using namespace std;
+
+const Importance Importance::Undefined (IMPORTANCE_UNDEFINED);
+const Importance Importance::Invalid (IMPORTANCE_INVALID);
+const Importance Importance::Necessary (IMPORTANCE_NECESSARY);
+const Importance Importance::Urgent (IMPORTANCE_URGENT);
+const Importance Importance::Suggested (IMPORTANCE_SUGGESTED);
+const Importance Importance::Feature (IMPORTANCE_FEATURE);
+const Importance Importance::Minor (IMPORTANCE_MINOR);
+
+//---------------------------------------------------------------------------
+string
+Importance::asString ( void ) const
+{
+    return toString (*this);
+}
+
+
+string
+Importance::toString ( const Importance & importance )
+{
+    string res;
+
+    switch (importance.importance()) {
+       case IMPORTANCE_UNDEFINED:      res = "undefined"; break;
+       case IMPORTANCE_INVALID:        res = "invalid"; break;
+       case IMPORTANCE_NECESSARY:      res = "necessary"; break;
+       case IMPORTANCE_URGENT:         res = "urgent"; break;
+       case IMPORTANCE_SUGGESTED:      res = "suggested"; break;
+       case IMPORTANCE_FEATURE:        res = "feature"; break;
+       case IMPORTANCE_MINOR:          res = "minor"; break;
+       default:
+           WAR << "invalid importance "<< importance.importance() << endl;
+           res = "invalid";
+    }
+    return res;
+}
+
+
+ostream &
+Importance::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
+
+
+ostream&
+operator<<( ostream& os, const Importance& importance)
+{
+    return os << importance.asString();
+}
+
+//---------------------------------------------------------------------------
+
+const Importance
+Importance::parse(const string & str)
+{
+    Importance importance = Invalid;
+    if (str == "feature") {
+       importance = Feature;
+    }
+    else if (str == "minor") {
+       importance = Minor;
+    }
+    else if (str == "necessary") {
+       importance = Necessary;
+    }
+    if (str == "suggested") {
+       importance = Suggested;
+    }
+    if (str == "urgent") {
+       importance = Urgent;
+    }
+    else if (str == "undefined") {
+       importance = Undefined;
+    }
+
+    if (importance == Invalid)
+       WAR << "invalid importance '" << str << "'" << endl;
+
+    return importance;
+}
+
+
+Importance::Importance(importance_t importance)
+    : _importance (importance)
+{
+}
+
+Importance::~Importance()
+{
+}
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 906b742..55b43fb 100644 (file)
@@ -35,67 +35,73 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : Importance
-      /**
-       *
-       **/
-      class Importance {
-
-        private:
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : Importance
+/**
+ *
+ **/
+class Importance {
 
-          typedef enum {
-       IMPORTANCE_INVALID = -1,
+  private:
 
-       IMPORTANCE_NECESSARY,
-       IMPORTANCE_URGENT,
-       IMPORTANCE_SUGGESTED,
-       IMPORTANCE_FEATURE,
-       IMPORTANCE_MINOR,
-       IMPORTANCE_UNDEFINED,
+    typedef enum {
+       IMPORTANCE_INVALID = -1,
 
-       // Not a real importance
-       IMPORTANCE_LAST
-          } importance_t;
+       IMPORTANCE_NECESSARY,
+       IMPORTANCE_URGENT,
+       IMPORTANCE_SUGGESTED,
+       IMPORTANCE_FEATURE,
+       IMPORTANCE_MINOR,
+       IMPORTANCE_UNDEFINED,
 
-          importance_t _importance;
+       // Not a real importance
+       IMPORTANCE_LAST
+    } importance_t;
 
-        private:
-          importance_t importance () const { return _importance; }
+    importance_t _importance;
 
-        public:
+  private:
+    importance_t importance () const { return _importance; }
+    Importance(importance_t importance);
 
-          Importance(const char *importance_str);
-          virtual ~Importance();
+  public:
+    static const Importance parse (const std::string & str);
+    virtual ~Importance();
 
-          static const Importance & Undefined;
+    static const Importance Undefined;
+    static const Importance Invalid;
+    static const Importance Necessary;
+    static const Importance Urgent;
+    static const Importance Suggested;
+    static const Importance Feature;
+    static const Importance Minor;
 
-          // ---------------------------------- I/O
+    // ---------------------------------- I/O
 
-          static std::string toString ( const Importance & importance);
+    static std::string toString ( const Importance & importance);
 
-          virtual std::ostream & dumpOn( std::ostream & str ) const;
+    virtual std::ostream & dumpOn( std::ostream & str ) const;
 
-          friend std::ostream& operator<<( std::ostream&, const Importance & importance);
+    friend std::ostream& operator<<( std::ostream&, const Importance & importance);
 
-          std::string asString ( void ) const;
+    std::string asString ( void ) const;
 
-          // ---------------------------------- accessors
+    // ---------------------------------- accessors
 
-          // equality
-          bool operator==( const Importance & importance) const {
-       return _importance == importance.importance();
-          }
+    // equality
+    bool operator==( const Importance & importance) const {
+       return _importance == importance.importance();
+    }
 
-          // inequality
-          bool operator!=( const Importance & importance) const {
-       return !(*this == importance);
-          }
+    // inequality
+    bool operator!=( const Importance & importance) const {
+       return !(*this == importance);
+    }
 
-      };
+};
 
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 3301873..fe54c01 100644 (file)
@@ -39,391 +39,379 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
-
-      IMPL_PTR_TYPE(Channel);
-
-      //---------------------------------------------------------------------------
-
-      int Channel::_fake_id = 1;
-
-      //---------------------------------------------------------------------------
-
-      string
-      Channel::asString ( void ) const
-      {
-          if (this == NULL) fprintf (stderr, "Channel::asString NULL\n");
-          return toString (*this);
-      }
-
-
-      string
-      Channel::toString ( const Channel & channel )
-      {
-          string res ("<channel '");
-          res += "Type: ";
-          switch (channel.type()) {
-       case CHANNEL_TYPE_ANY: res += "any"; break;
-       case CHANNEL_TYPE_SYSTEM: res += "system"; break;
-       case CHANNEL_TYPE_NONSYSTEM: res += "non-system"; break;
-
-       case CHANNEL_TYPE_UNKNOWN: res += "unknown"; break;
-       case CHANNEL_TYPE_HELIX: res += "helix"; break;
-       case CHANNEL_TYPE_DEBIAN: res += "debian"; break;
-       case CHANNEL_TYPE_APTRPM: res += "apt-rpm"; break;
-       case CHANNEL_TYPE_YAST: res += "yast"; break;
-       case CHANNEL_TYPE_YUM: res += "yum"; break;
-          }
-          res += ", ";
-
-          res += "Id: ";
-          res += channel.id();
-          if (channel.legacyId() != NULL
-       && (*(channel.legacyId()) != 0)) {
-       res += ", LegacyId: ";
-       res += channel.legacyId();
-          }
-          res += ", Name: ";
-          res += channel.name();
-          res += ", Alias: ";
-          res += channel.alias();
-
-          if (channel.description() != NULL) {
-       res += ", Description: ";
-       res += channel.description();
-          }
-
-          res += ", Priority: ";
-          res += str::numstring (channel.priority());
-          res += ", PriorityUnsubscribed: ";
-          res += str::numstring (channel.priorityUnsubscribed());
-
-          if (channel.path() != NULL) {
-       res += ", Path: ";
-       res += channel.path();
-          }
-          if (channel.filePath() != NULL) {
-       res += ", FilePath: ";
-       res += channel.filePath();
-          }
-          if (channel.iconFile() != NULL) {
-       res += ", IconFile: ";
-       res += channel.iconFile();
-          }
-          if (channel.pkginfoFile() != NULL) {
-       res += ", PkginfoFile: ";
-       res += channel.pkginfoFile();
-          }
-       //    list<char *> *_distro_targets; /* List of targets (char *) for this channel */
-
-          res += ", LastUpdate: ";
-          res += str::numstring(channel.lastUpdate());
-
-          if (channel.system()) res += ", System! ";
-          if (channel.hidden()) res += ", Hidden! ";
-          if (channel.immutable()) res += ", Immutable! ";
-
-          return res + "'>";
-      }
-
-
-      ostream &
-      Channel::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
-
-
-      ostream&
-      operator<<( ostream& os, const Channel& channel)
-      {
-          return os << channel.asString();
-      }
-
-      //---------------------------------------------------------------------------
-
-      Channel::Channel(const string & id, const string & name, const string & alias, const string & description)
-          : _world (NULL)
-          , _last_update (0)
-          , _system (false)
-          , _hidden (false)
-          , _immutable (false)
-      {
-          if (id.empty()) {
-       _id = str::form( "fake-id-%d", _fake_id++).c_str();
-          }
-          else {
-       _id = id;
-          }
-
-          if (name.empty()) {
-       _name = "Unnamed Channel";
-          }
-          else {
-       _name = name;
-          }
-
-          if (alias.empty()) {
-       _alias = name;
-          }
-          else {
-       _alias = alias;
-          }
-
-          if (description.empty()) {
-       _description = "No description available.";
-          }
-          else {
-       _description = description;
-          }
-
-          _type = CHANNEL_TYPE_UNKNOWN;
-
-          _priority = -1;
-          _priority_unsubscribed = -1;
+using namespace std;
+
+IMPL_PTR_TYPE(Channel);
+
+//---------------------------------------------------------------------------
+
+int Channel::_fake_id = 1;
+
+//---------------------------------------------------------------------------
+
+string
+Channel::asString ( void ) const
+{
+    if (this == NULL) fprintf (stderr, "Channel::asString NULL\n");
+    return toString (*this);
+}
+
+
+string
+Channel::toString ( const Channel & channel )
+{
+    string res ("<channel '");
+    res += "Type: ";
+    switch (channel.type()) {
+       case CHANNEL_TYPE_ANY: res += "any"; break;
+       case CHANNEL_TYPE_SYSTEM: res += "system"; break;
+       case CHANNEL_TYPE_NONSYSTEM: res += "non-system"; break;
+
+       case CHANNEL_TYPE_UNKNOWN: res += "unknown"; break;
+       case CHANNEL_TYPE_HELIX: res += "helix"; break;
+       case CHANNEL_TYPE_DEBIAN: res += "debian"; break;
+       case CHANNEL_TYPE_APTRPM: res += "apt-rpm"; break;
+       case CHANNEL_TYPE_YAST: res += "yast"; break;
+       case CHANNEL_TYPE_YUM: res += "yum"; break;
+    }
+    res += ", ";
+
+    res += "Id: ";
+    res += channel.id();
+    if (!channel.legacyId().empty()) {
+       res += ", LegacyId: ";
+       res += channel.legacyId();
+    }
+    res += ", Name: ";
+    res += channel.name();
+    res += ", Alias: ";
+    res += channel.alias();
+
+    if (!channel.description().empty()) {
+       res += ", Description: ";
+       res += channel.description();
+    }
+
+    res += ", Priority: ";
+    res += str::numstring (channel.priority());
+    res += ", PriorityUnsubscribed: ";
+    res += str::numstring (channel.priorityUnsubscribed());
+
+    if (!channel.path().empty()) {
+       res += ", Path: ";
+       res += channel.path();
+    }
+    if (!channel.filePath().empty()) {
+       res += ", FilePath: ";
+       res += channel.filePath();
+    }
+    if (!channel.iconFile().empty()) {
+       res += ", IconFile: ";
+       res += channel.iconFile();
+    }
+    if (!channel.pkginfoFile().empty()) {
+       res += ", PkginfoFile: ";
+       res += channel.pkginfoFile();
+    }
+       //    list<char *> *_distro_targets; /* List of targets (char *) for this channel */
+
+    res += ", LastUpdate: ";
+    res += str::numstring(channel.lastUpdate());
+
+    if (channel.system()) res += ", System! ";
+    if (channel.hidden()) res += ", Hidden! ";
+    if (channel.immutable()) res += ", Immutable! ";
+
+    return res + "'>";
+}
+
+
+ostream &
+Channel::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
+
+
+ostream&
+operator<<( ostream& os, const Channel& channel)
+{
+    return os << channel.asString();
+}
+
+//---------------------------------------------------------------------------
+
+Channel::Channel(const string & id, const string & name, const string & alias, const string & description)
+    : _world (NULL)
+    , _last_update (0)
+    , _system (false)
+    , _hidden (false)
+    , _immutable (false)
+{
+    if (id.empty()) {
+       _id = str::form( "fake-id-%d", _fake_id++).c_str();
+    }
+    else {
+       _id = id;
+    }
+
+    if (name.empty()) {
+       _name = "Unnamed Channel";
+    }
+    else {
+       _name = name;
+    }
+
+    if (alias.empty()) {
+       _alias = name;
+    }
+    else {
+       _alias = alias;
+    }
+
+    if (description.empty()) {
+       _description = "No description available.";
+    }
+    else {
+       _description = description;
+    }
+
+    _type = CHANNEL_TYPE_UNKNOWN;
+
+    _priority = -1;
+    _priority_unsubscribed = -1;
 
          _DBG("RC_SPEW") << "Channel() [" << this << "] (" << asString() << ")" << endl ;
-      }
+}
 
 
-      Channel::Channel (const XmlNode_Ptr node, int *subscribed, World_Ptr world)
-          : _world (world)
-          , _last_update (0)
-          , _system (false)
-          , _hidden (false)
-          , _immutable (false)
-      {
-          static unsigned int dummy_id = 0xdeadbeef;
-          const char *subscribed_str;
-          const char *priority_str;
-          const char *priority_unsubscribed_str;
+Channel::Channel (const XmlNode_Ptr node, int *subscribed, World_Ptr world)
+    : _world (world)
+    , _last_update (0)
+    , _system (false)
+    , _hidden (false)
+    , _immutable (false)
+{
+    static unsigned int dummy_id = 0xdeadbeef;
 
-          _name = node->getProp ("name");
-          _alias = node->getProp ("alias");
+    _name = node->getProp ("name");
+    _alias = node->getProp ("alias");
 
-          _id = node->getProp ("id");
-          if (_id.empty()) {
-       char *temp;
-       asprintf (&temp, "dummy:%d", dummy_id);
-       _id = temp;
-       ++dummy_id;
-          }
+    _id = node->getProp ("id");
+    if (_id.empty()) {
+       char *temp;
+       asprintf (&temp, "dummy:%d", dummy_id);
+       _id = temp;
+       ++dummy_id;
+    }
 
-          subscribed_str = node->getProp ("subscribed");
-          *subscribed = subscribed_str ? atoi (subscribed_str) : 0;
+    *subscribed = node->getIntValueDefault ("subscribed", 0);
 
-          priority_str = node->getProp ("priority_base");
-          priority_unsubscribed_str = node->getProp ("priority_unsubd");
-
-          _priority = priority_str ? atoi (priority_str) : 0;
-          _priority_unsubscribed = priority_unsubscribed_str ? atoi (priority_unsubscribed_str) : 0;
+    _priority = node->getIntValueDefault ("priority_base", 0);
+    _priority_unsubscribed = node->getIntValueDefault ("priority_unsubd", 0);
 
-          free ((void *)subscribed_str);
-          free ((void *)priority_str);
-          free ((void *)priority_unsubscribed_str);
+    _DBG("RC_SPEW") << "Channel(xml) [" << this << "] (" << asString() << ")" << endl;
+}
 
-         _DBG("RC_SPEW") << "Channel(xml) [" << this << "] (" << asString() << ")" << endl;
-      }
 
+Channel::~Channel()
+{
+}
 
-      Channel::~Channel()
-      {
-      }
 
+#if 0
+xmlNode *
+rc_channel_to_xml_node (RCChannel *channel)
+{
+    xmlNode *node;
+    char tmp[128];
 
-      #if 0
-      xmlNode *
-      rc_channel_to_xml_node (RCChannel *channel)
-      {
-          xmlNode *node;
-          char tmp[128];
+    g_return_val_if_fail (channel != NULL, NULL);
 
-          g_return_val_if_fail (channel != NULL, NULL);
+    node = xmlNewNode (NULL, "channel");
 
-          node = xmlNewNode (NULL, "channel");
+    xmlNewProp (node, "id", rc_channel_get_id (channel));
 
-          xmlNewProp (node, "id", rc_channel_get_id (channel));
+    xmlNewProp (node, "name", rc_channel_get_name (channel));
 
-          xmlNewProp (node, "name", rc_channel_get_name (channel));
+    if (rc_channel_get_alias (channel))
+       xmlNewProp (node, "alias", rc_channel_get_alias (channel));
 
-          if (rc_channel_get_alias (channel))
-       xmlNewProp (node, "alias", rc_channel_get_alias (channel));
-
-          sprintf (tmp, "%d", rc_channel_is_subscribed (channel) ? 1 : 0);
-          xmlNewProp (node, "subscribed", tmp);
-
-          sprintf (tmp, "%d", rc_channel_get_priority (channel, true));
-          xmlNewProp (node, "priority_base", tmp);
-
-          sprintf (tmp, "%d", rc_channel_get_priority (channel, false));
-          xmlNewProp (node, "priority_unsubd", tmp);
+    sprintf (tmp, "%d", rc_channel_is_subscribed (channel) ? 1 : 0);
+    xmlNewProp (node, "subscribed", tmp);
 
-          return node;
-      }
-      #endif
-
-
-      bool
-      Channel::isSubscribed (void) const
-      {
-          if (_world == NULL)
-       fprintf (stderr, "Channel::isSubscribed() without world\n");
-          return _world->isSubscribed (this);
-      }
-
-
-      void
-      Channel::setSubscription (bool subscribed)
-      {
-          if (_world == NULL)
-       fprintf (stderr, "Channel::setSubscription() without world\n");
-          _world->setSubscription (this, subscribed);
-      }
-
-
-      int
-      Channel::priorityParse (const char *priority_cptr) const
-      {
-      #define DEFAULT_CHANNEL_PRIORITY 1600
-
-          typedef struct {
-       const char *str;
-       int priority;
-           } ChannelPriorityPair;
-
-          ChannelPriorityPair channel_priority_table[] = {
-       { "private",     6400 },
-       { "ximian",      3200 },
-       { "distro",      1600 },
-       { "third_party",  800 },
-       { "preview",      400 },
-       { "untested",     200 },
-       { "snapshot",     100 },
-       { NULL,             0 }
-          };
+    sprintf (tmp, "%d", rc_channel_get_priority (channel, true));
+    xmlNewProp (node, "priority_base", tmp);
 
-          const char *c;
-          int i;
-          bool is_numeric = true;
+    sprintf (tmp, "%d", rc_channel_get_priority (channel, false));
+    xmlNewProp (node, "priority_unsubd", tmp);
 
-          if (priority_cptr && *priority_cptr) {
-       c = priority_cptr;
-       while (*c && is_numeric) {
-           if (! isdigit (*c))
-               is_numeric = false;
-           c++;
-       }
-       if (is_numeric) {
-           return atoi (priority_cptr);
-       }
+    return node;
+}
+#endif
+
+
+bool
+Channel::isSubscribed (void) const
+{
+    if (_world == NULL)
+       fprintf (stderr, "Channel::isSubscribed() without world\n");
+    return _world->isSubscribed (this);
+}
+
+
+void
+Channel::setSubscription (bool subscribed)
+{
+    if (_world == NULL)
+       fprintf (stderr, "Channel::setSubscription() without world\n");
+    _world->setSubscription (this, subscribed);
+}
+
+
+int
+Channel::priorityParse (const string & priority_str) const
+{
+#define DEFAULT_CHANNEL_PRIORITY 1600
+
+    typedef struct {
+       const char *str;
+       int priority;
+     } ChannelPriorityPair;
 
-       for (i=0; channel_priority_table[i].str != NULL; ++i) {
-           if (! strcasecmp (channel_priority_table[i].str, priority_cptr))
-               return channel_priority_table[i].priority;
-       }
+    ChannelPriorityPair channel_priority_table[] = {
+       { "private",     6400 },
+       { "ximian",      3200 },
+       { "distro",      1600 },
+       { "third_party",  800 },
+       { "preview",      400 },
+       { "untested",     200 },
+       { "snapshot",     100 },
+       { NULL,             0 }
+    };
 
-          }
-
-          return DEFAULT_CHANNEL_PRIORITY;
-      }
-
-
-      bool
-      Channel::isWildcard (void) const
-      {
-          return _type == CHANNEL_TYPE_SYSTEM
-       || _type == CHANNEL_TYPE_NONSYSTEM
-       || _type == CHANNEL_TYPE_ANY;
-      }
+    const char *c;
+    int i;
+    bool is_numeric = true;
 
+    if (!priority_str.empty()) {
+       c = priority_str.c_str();
+       while (*c && is_numeric) {
+           if (! isdigit (*c))
+               is_numeric = false;
+           c++;
+       }
+       if (is_numeric) {
+           return atoi (priority_str.c_str());
+       }
 
-      bool
-      Channel::equals (const Channel & channel) const
-      {
-          return equals (&channel);
-      }
-
-      bool
-      Channel::equals (Channel_constPtr channel) const
-      {
-          if (_type == CHANNEL_TYPE_ANY
-       || channel->_type == CHANNEL_TYPE_ANY) {
-       return true;
-          }
-
-          if (isWildcard () && channel->isWildcard ()) {
-       return this == channel;
-          }
-
-          /* So at this point we know that between a and b there is
-             at most one wildcard. */
-
-          if (_type == CHANNEL_TYPE_SYSTEM) {
-       return channel->system();
-          }
-          else if (_type == CHANNEL_TYPE_NONSYSTEM) {
-       return !channel->system();
-          }
-
-          if (channel->_type == CHANNEL_TYPE_SYSTEM) {
-       return system();
-          }
-          else if (channel->_type == CHANNEL_TYPE_NONSYSTEM) {
-       return !system();
-          }
-
-          return hasEqualId (channel);
-      }
-
-
-      bool
-      Channel::hasEqualId (const Channel & channel) const
-      {
-          return hasEqualId (&channel);
-      }
-
-
-      bool
-      Channel::hasEqualId (Channel_constPtr channel) const
-      {
-          return (channel->id () == _id);
-      }
-
-
-      void
-      Channel::setPriorities (int subscribed_priority, int unsubscribed_priority)
-      {
-          if (immutable()) return;
-
-          _priority = subscribed_priority;
-          _priority_unsubscribed = unsubscribed_priority;
-      }
-
-
-      int
-      Channel::getPriority(bool is_subscribed) const
-      {
-      #define UNSUBSCRIBED_CHANNEL_ADJUSTMENT(x) ((x)/2)
-
-          int priority;
-
-          priority = _priority;
-          if (priority <= 0)
-       priority = DEFAULT_CHANNEL_PRIORITY;
-
-          if (!is_subscribed) {
-       if (_priority_unsubscribed > 0) {
-           priority = _priority_unsubscribed;
-       } else {
-           priority = UNSUBSCRIBED_CHANNEL_ADJUSTMENT (priority);
-       }
-          }
+       for (i=0; channel_priority_table[i].str != NULL; ++i) {
+           if (! strcasecmp (channel_priority_table[i].str, priority_str.c_str()))
+               return channel_priority_table[i].priority;
+       }
 
-          return priority;
-      }
+    }
 
-      ///////////////////////////////////////////////////////////////////
+    return DEFAULT_CHANNEL_PRIORITY;
+}
+
+
+bool
+Channel::isWildcard (void) const
+{
+    return _type == CHANNEL_TYPE_SYSTEM
+       || _type == CHANNEL_TYPE_NONSYSTEM
+       || _type == CHANNEL_TYPE_ANY;
+}
+
+
+bool
+Channel::equals (const Channel & channel) const
+{
+    return equals (&channel);
+}
+
+bool
+Channel::equals (Channel_constPtr channel) const
+{
+    if (_type == CHANNEL_TYPE_ANY
+       || channel->_type == CHANNEL_TYPE_ANY) {
+       return true;
+    }
+
+    if (isWildcard () && channel->isWildcard ()) {
+       return this == channel;
+    }
+
+    /* So at this point we know that between a and b there is
+       at most one wildcard. */
+
+    if (_type == CHANNEL_TYPE_SYSTEM) {
+       return channel->system();
+    }
+    else if (_type == CHANNEL_TYPE_NONSYSTEM) {
+       return !channel->system();
+    }
+
+    if (channel->_type == CHANNEL_TYPE_SYSTEM) {
+       return system();
+    }
+    else if (channel->_type == CHANNEL_TYPE_NONSYSTEM) {
+       return !system();
+    }
+
+    return hasEqualId (channel);
+}
+
+
+bool
+Channel::hasEqualId (const Channel & channel) const
+{
+    return hasEqualId (&channel);
+}
+
+
+bool
+Channel::hasEqualId (Channel_constPtr channel) const
+{
+    return (channel->id () == _id);
+}
+
+
+void
+Channel::setPriorities (int subscribed_priority, int unsubscribed_priority)
+{
+    if (immutable()) return;
+
+    _priority = subscribed_priority;
+    _priority_unsubscribed = unsubscribed_priority;
+}
+
+
+int
+Channel::getPriority(bool is_subscribed) const
+{
+#define UNSUBSCRIBED_CHANNEL_ADJUSTMENT(x) ((x)/2)
+
+    int priority;
+
+    priority = _priority;
+    if (priority <= 0)
+       priority = DEFAULT_CHANNEL_PRIORITY;
+
+    if (!is_subscribed) {
+       if (_priority_unsubscribed > 0) {
+           priority = _priority_unsubscribed;
+       } else {
+           priority = UNSUBSCRIBED_CHANNEL_ADJUSTMENT (priority);
+       }
+    }
+
+    return priority;
+}
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 64efa3d..a668360 100644 (file)
@@ -47,170 +47,170 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      typedef std::list<Channel_Ptr> ChannelList;
+typedef std::list<Channel_Ptr> ChannelList;
 
-      typedef bool (*ChannelFn) (Channel_constPtr channel, void *data);
-      typedef bool (*ChannelAndSubscribedFn) (Channel_Ptr channel, bool flag, void *data);
+typedef bool (*ChannelFn) (Channel_constPtr channel, void *data);
+typedef bool (*ChannelAndSubscribedFn) (Channel_Ptr channel, bool flag, void *data);
 
-      typedef enum {
+typedef enum {
 
-          CHANNEL_TYPE_ANY = 0,
-          CHANNEL_TYPE_SYSTEM,
-          CHANNEL_TYPE_NONSYSTEM,
+    CHANNEL_TYPE_ANY = 0,
+    CHANNEL_TYPE_SYSTEM,
+    CHANNEL_TYPE_NONSYSTEM,
 
-          CHANNEL_TYPE_UNKNOWN,
-          CHANNEL_TYPE_HELIX,
-          CHANNEL_TYPE_DEBIAN,
-          CHANNEL_TYPE_APTRPM,
-          CHANNEL_TYPE_YAST,
-          CHANNEL_TYPE_YUM
+    CHANNEL_TYPE_UNKNOWN,
+    CHANNEL_TYPE_HELIX,
+    CHANNEL_TYPE_DEBIAN,
+    CHANNEL_TYPE_APTRPM,
+    CHANNEL_TYPE_YAST,
+    CHANNEL_TYPE_YUM
 
-      } ChannelType;
+} ChannelType;
 
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
 
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : Channel
-      /**
      *
      **/
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : Channel
+/**
+ *
+ **/
 
-      class Channel : public base::ReferenceCounted, private base::NonCopyable {
+class Channel : public base::ReferenceCounted, private base::NonCopyable {
 
 
-        private:
-          ChannelType _type;
+  private:
+    ChannelType _type;
 
-          static int _fake_id;
+    static int _fake_id;
 
-          World_Ptr _world;
+    World_Ptr _world;
 
-          std::string _id;
-          std::string _legacy_id;                      // Old ID for RCE servers
+    std::string _id;
+    std::string _legacy_id;                    // Old ID for RCE servers
 
-          std::string _name;
-          std::string _alias;
-          std::string _description;
-                                       // priority if channel is...
-          int _priority;                       // subscribed
-          int _priority_unsubscribed;          // unsubscribed
+    std::string _name;
+    std::string _alias;
+    std::string _description;
+                                       // priority if channel is...
+    int _priority;                     // subscribed
+    int _priority_unsubscribed;                // unsubscribed
 
-          std::string _path;
-          std::string _file_path;
-          std::string _icon_file;
-          std::string _pkginfo_file;
+    std::string _path;
+    std::string _file_path;
+    std::string _icon_file;
+    std::string _pkginfo_file;
 
-      //    std::list<std::string > *_distro_targets; /* List of targets (std::string ) for this channel */
+//    std::list<std::string > *_distro_targets; /* List of targets (std::string ) for this channel */
 
-          time_t _last_update;
+    time_t _last_update;
 
-          bool _system;
-          bool _hidden;
-          bool _immutable;
+    bool _system;
+    bool _hidden;
+    bool _immutable;
 
-        public:
+  public:
 
-          Channel (ChannelType type) : _type (type), _world(NULL) {}
+    Channel (ChannelType type) : _type (type), _world(NULL) {}
 
-          Channel(const std::string & id = "", const std::string & name = "", const std::string & alias = "", const std::string & description = "");
-          Channel(const XmlNode_Ptr node, int *subscribed, World_Ptr world);           //RCChannel *rc_channel_from_xml_node (xmlNode *channel_node);
+    Channel(const std::string & id = "", const std::string & name = "", const std::string & alias = "", const std::string & description = "");
+    Channel(const XmlNode_Ptr node, int *subscribed, World_Ptr world);         //RCChannel *rc_channel_from_xml_node (xmlNode *channel_node);
 
-          virtual ~Channel();
+    virtual ~Channel();
 
-          // ---------------------------------- I/O
+    // ---------------------------------- I/O
 
-          const XmlNode_Ptr asXmlNode (void) const;            // rc_channel_to_xml_node
+    const XmlNode_Ptr asXmlNode (void) const;          // rc_channel_to_xml_node
 
-          static std::string toString ( const Channel & edition );
+    static std::string toString ( const Channel & edition );
 
-          virtual std::ostream & dumpOn( std::ostream & str ) const;
+    virtual std::ostream & dumpOn( std::ostream & str ) const;
 
-          friend std::ostream& operator<<( std::ostream&, const Channel& );
+    friend std::ostream& operator<<( std::ostream&, const Channel& );
 
-          std::string asString ( void ) const;
+    std::string asString ( void ) const;
 
-          // ---------------------------------- accessors
+    // ---------------------------------- accessors
 
-          ChannelType type(void) const { return _type; }
-          void setType (ChannelType type) { _type = type; }
+    ChannelType type(void) const { return _type; }
+    void setType (ChannelType type) { _type = type; }
 
-          const char *id (void) const { return _id.c_str(); }
-          void setId (const char *id) { _id = std::string (id); }
+    std::string id (void) const { return _id; }
+    void setId (const std::string & id) { _id = id; }
 
-          World_Ptr world (void) const { return _world; }
-          void setWorld (World_Ptr world) { _world = world; }
+    World_Ptr world (void) const { return _world; }
+    void setWorld (World_Ptr world) { _world = world; }
 
-          const char *legacyId (void) const { return _legacy_id.c_str(); }                     // Old ID for RCE servers
-          void setLegacyId (const char *legacy_id) { _legacy_id = std::string (legacy_id); }
+    std::string legacyId (void) const { return _legacy_id; }                   // Old ID for RCE servers
+    void setLegacyId (const std::string & legacy_id) { _legacy_id = legacy_id; }
 
-          const char * name (void) const { return _name.c_str(); }
-          void setName (const char *name) { _name = std::string (name); }
+    std::string name (void) const { return _name; }
+    void setName (const std::string & name) { _name = name; }
 
-          const char *alias (void) const { return _alias.c_str(); }
-          void setAlias (const char *alias) { _alias = std::string (alias); }
+    std::string alias (void) const { return _alias; }
+    void setAlias (const std::string & alias) { _alias = alias; }
 
-          const char *description (void) const { return _description.c_str(); }
-          void setDescription (const char *description) { _description = std::string (description); }
+    std::string description (void) const { return _description; }
+    void setDescription (const std::string & description) { _description = description; }
 
-          int priority (void) const { return _priority; }
-          void setPriority (int priority) { _priority = priority; }
+    int priority (void) const { return _priority; }
+    void setPriority (int priority) { _priority = priority; }
 
-          int priorityUnsubscribed (void) const { return _priority_unsubscribed; }
-          void setPriorityUnsubscribed (int priority_unsubscribed) { _priority_unsubscribed = priority_unsubscribed; }
+    int priorityUnsubscribed (void) const { return _priority_unsubscribed; }
+    void setPriorityUnsubscribed (int priority_unsubscribed) { _priority_unsubscribed = priority_unsubscribed; }
 
-          const char *path (void) const { return _path.c_str(); }
-          void setPath (const char *path) { _path = std::string (path); }
+    std::string path (void) const { return _path; }
+    void setPath (const std::string & path) { _path = path; }
 
-          const char *filePath (void) const { return _file_path.c_str(); }
-          void setFilePath (const char *file_path) { _file_path = std::string (file_path); }
+    std::string filePath (void) const { return _file_path; }
+    void setFilePath (const std::string file_path) { _file_path = file_path; }
 
-          const char *iconFile (void) const { return _icon_file.c_str(); }
-          void setIconFile (const char *icon_file) { _icon_file = std::string (icon_file); }
+    std::string iconFile (void) const { return _icon_file; }
+    void setIconFile (const std::string icon_file) { _icon_file = icon_file; }
 
-          const char *pkginfoFile (void) const { return _pkginfo_file.c_str(); }
-          void setPkginfoFile (const char *pkginfo_file) { _pkginfo_file = std::string (pkginfo_file); }
+    std::string pkginfoFile (void) const { return _pkginfo_file; }
+    void setPkginfoFile (const std::string & pkginfo_file) { _pkginfo_file = pkginfo_file; }
 
-      //    const std::list<char *> *distroTargets (void) const { return _distro_targets; }
-      //    void setDistroTargets (const std::list<char *> *distro_targets) { _distro_targets = distro_targets; }
+//    const std::list<char *> *distroTargets (void) const { return _distro_targets; }
+//    void setDistroTargets (const std::list<char *> *distro_targets) { _distro_targets = distro_targets; }
 
-          time_t lastUpdate (void) const { return _last_update; }
-          void setLastUpdate (time_t last_update) { _last_update = last_update; }
+    time_t lastUpdate (void) const { return _last_update; }
+    void setLastUpdate (time_t last_update) { _last_update = last_update; }
 
-          bool system (void) const { return _system; }
-          void setSystem (bool system) { _system = system; }
-          bool hidden (void) const { return _hidden; }
-          void setHidden (bool hidden) { _hidden = hidden; }
-          bool immutable (void) const { return _immutable; }
-          void setImmutable (bool immutable) { _immutable = immutable; }
+    bool system (void) const { return _system; }
+    void setSystem (bool system) { _system = system; }
+    bool hidden (void) const { return _hidden; }
+    void setHidden (bool hidden) { _hidden = hidden; }
+    bool immutable (void) const { return _immutable; }
+    void setImmutable (bool immutable) { _immutable = immutable; }
 
-          //-----------------------------------------------------------------------
+    //-----------------------------------------------------------------------
 
-          bool isWildcard (void) const;
+    bool isWildcard (void) const;
 
-          virtual bool equals (const Channel & channel) const;
-          virtual bool equals (Channel_constPtr channel) const;
-          bool hasEqualId (const Channel & channel) const;
-          bool hasEqualId (Channel_constPtr channel) const;
+    virtual bool equals (const Channel & channel) const;
+    virtual bool equals (Channel_constPtr channel) const;
+    bool hasEqualId (const Channel & channel) const;
+    bool hasEqualId (Channel_constPtr channel) const;
 
-       //RCResItemSList *rc_channel_get_resItems (RCChannel *channel);
+       //RCResItemSList *rc_channel_get_resItems (RCChannel *channel);
 
-          // Distro target functions
+    // Distro target functions
 
-          void addDistroTarget (const char *target);
-          bool hasDistroTarget (const char *target) const;
+    void addDistroTarget (const std::string & target);
+    bool hasDistroTarget (const std::string & target) const;
 
-          // Subscription management
+    // Subscription management
 
-          bool isSubscribed (void) const;
-          void setSubscription (bool subscribed);
+    bool isSubscribed (void) const;
+    void setSubscription (bool subscribed);
 
-          int priorityParse (const char *priority_cptr) const;
-          void setPriorities (int subd_priority, int unsubd_priority);
-          int getPriority (bool is_subscribed) const;
-      };
+    int priorityParse (const std::string & priority_cptr) const;
+    void setPriorities (int subd_priority, int unsubd_priority);
+    int getPriority (bool is_subscribed) const;
+};
 
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 1169c89..d321014 100644 (file)
@@ -37,144 +37,144 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
+using namespace std;
 
-      IMPL_PTR_TYPE(Match);
+IMPL_PTR_TYPE(Match);
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      string
-      Match::asString ( void ) const
-      {
-          return toString (*this);
-      }
+string
+Match::asString ( void ) const
+{
+    return toString (*this);
+}
 
 
-      string
-      Match::toString ( const Match & lock )
-      {
-          return "<lock/>";
-      }
+string
+Match::toString ( const Match & lock )
+{
+    return "<lock/>";
+}
 
 
-      ostream &
-      Match::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
+ostream &
+Match::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
 
 
-      ostream&
-      operator<<( ostream& os, const Match& edition)
-      {
-          return os << edition.asString();
-      }
+ostream&
+operator<<( ostream& os, const Match& edition)
+{
+    return os << edition.asString();
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      Match::Match()
-          : _importance (Importance::Undefined)
-      {
-      }
+Match::Match()
+    : _importance (Importance::Undefined)
+{
+}
 
-      Match::Match (XmlNode_Ptr node)
-          : _importance (Importance::Undefined)
-      {
-      }
+Match::Match (XmlNode_Ptr node)
+    : _importance (Importance::Undefined)
+{
+}
 
-      Match::~Match()
-      {
-      }
+Match::~Match()
+{
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      XmlNode_Ptr
-      Match::asXmlNode (void) const
-      {
-          return new XmlNode("match");
-      }
+XmlNode_Ptr
+Match::asXmlNode (void) const
+{
+    return new XmlNode("match");
+}
 
 
-      // equality
-      bool
-      Match::equals ( const Match & lock ) const {
+// equality
+bool
+Match::equals ( const Match & lock ) const {
 
-          // Check the name glob
+    // Check the name glob
 
-          if ((_name_glob.empty()) ^ (lock._name_glob.empty()))
-       return false;
-          if (_name_glob != lock._name_glob)
-       return false;
+    if ((_name_glob.empty()) ^ (lock._name_glob.empty()))
+       return false;
+    if (_name_glob != lock._name_glob)
+       return false;
 
-          // Check the channel
+    // Check the channel
 
-          if ((_channel_id.empty()) ^ (lock._channel_id.empty()))
-       return false;
-          if (_channel_id != lock._channel_id)
-       return false;
+    if ((_channel_id.empty()) ^ (lock._channel_id.empty()))
+       return false;
+    if (_channel_id != lock._channel_id)
+       return false;
 
-          // Check the importance
+    // Check the importance
 
-          if (_importance != lock._importance
-       || _importance_gteq != lock._importance_gteq)
-          {
-       return false;
-          }
+    if (_importance != lock._importance
+       || _importance_gteq != lock._importance_gteq)
+    {
+       return false;
+    }
 
-          // Check the dep
-          if ( _dependency != lock._dependency)
-              return false;
+    // Check the dep
+    if ( _dependency != lock._dependency)
+        return false;
 
-          return true;
-      }
+    return true;
+}
 
 
-      bool
-      Match::test (ResItem_constPtr resItem, World_Ptr world) const
-      {
-          string name;
-          Channel_constPtr channel = resItem->channel ();
+bool
+Match::test (ResItem_constPtr resItem, World_Ptr world) const
+{
+    string name;
+    Channel_constPtr channel = resItem->channel ();
 
-          if (channel != NULL && !_channel_id.empty()) {
-              if (! channel->hasEqualId (_channel_id)) {
-                  return false;
-              }
-          }
+    if (channel != NULL && !_channel_id.empty()) {
+        if (! channel->hasEqualId (_channel_id)) {
+            return false;
+        }
+    }
 
-          name = resItem->name ();
+    name = resItem->name ();
 
-          // FIXME, implement regexp
+    // FIXME, implement regexp
 #if 0
-          if (match->_pattern_spec
-              && ! g_pattern_match_string (match->pattern_spec, name)) {
-              return false;
-          }
+    if (match->_pattern_spec
+        && ! g_pattern_match_string (match->pattern_spec, name)) {
+        return false;
+    }
 #endif
 
-          /* FIXME: ResItems don't have ResItemUpdate right now */
-          /*   if (match->importance != RC_IMPORTANCE_INVALID && */
-          /*     !rc_resItem_is_installed (resItem)) { */
-          /*     RCResItemUpdate *up = rc_resItem_get_latest_update (pkg); */
-          /*     if (up) { */
-          /*             if (match->importance_gteq ? up->importance > match->importance */
-          /*                     : up->importance < match->importance) */
-          /*                     return FALSE; */
-          /*     } */
-          /*   } */
-          CapFactory  factory;
-          Capability dependency;
-          bool check = false;
-
-          dependency = factory.parse ( resItem->kind(),
-                                       resItem->name(),
-                                       Rel::EQ,
-                                       resItem->edition());
+    /* FIXME: ResItems don't have ResItemUpdate right now */
+    /*   if (match->importance != RC_IMPORTANCE_INVALID && */
+    /*           !rc_resItem_is_installed (resItem)) { */
+    /*           RCResItemUpdate *up = rc_resItem_get_latest_update (pkg); */
+    /*           if (up) { */
+    /*                   if (match->importance_gteq ? up->importance > match->importance */
+    /*                           : up->importance < match->importance) */
+    /*                           return FALSE; */
+    /*           } */
+    /*   } */
+    CapFactory  factory;
+    Capability dependency;
+    bool check = false;
+
+    dependency = factory.parse ( resItem->kind(),
+                                 resItem->name(),
+                                 Rel::EQ,
+                                 resItem->edition());
 //          check = _dependency.matches (dependency);
-          return check;
-      }
+    return check;
+}
 
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 9ea1034..e889531 100644 (file)
@@ -33,637 +33,636 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
+using namespace std;
 
-      //===========================================================================
+//===========================================================================
 
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : SubWorldInfo
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : SubWorldInfo
 
-      class SubWorldInfo {
+class SubWorldInfo {
 
-        private:
-          World_Ptr _subworld;
-          World_Ptr _refreshed_subworld;
+  private:
+    World_Ptr _subworld;
+    World_Ptr _refreshed_subworld;
 
-          bool _refreshed_ready;
+    bool _refreshed_ready;
 
-          unsigned int _changed_resItems_id;
-          unsigned int _changed_channels_id;
-          unsigned int _changed_subscriptions_id;
-          unsigned int _changed_locks_id;
+    unsigned int _changed_resItems_id;
+    unsigned int _changed_channels_id;
+    unsigned int _changed_subscriptions_id;
+    unsigned int _changed_locks_id;
 
-        public:
+  public:
 
-          SubWorldInfo (World_Ptr subworld, MultiWorld_Ptr multiworld);
-          virtual ~SubWorldInfo();
+    SubWorldInfo (World_Ptr subworld, MultiWorld_Ptr multiworld);
+    virtual ~SubWorldInfo();
 
-          // ---------------------------------- I/O
+    // ---------------------------------- I/O
 
-          static std::string toString (const SubWorldInfo & subworldinfo);
+    static std::string toString (const SubWorldInfo & subworldinfo);
 
-          virtual std::ostream & dumpOn(std::ostream & str ) const;
+    virtual std::ostream & dumpOn(std::ostream & str ) const;
 
-          friend std::ostream& operator<<(std::ostream&, const SubWorldInfo & subworldinfo);
+    friend std::ostream& operator<<(std::ostream&, const SubWorldInfo & subworldinfo);
 
-          std::string asString (void ) const;
+    std::string asString (void ) const;
 
-          // ---------------------------------- accessors
+    // ---------------------------------- accessors
 
-          World_Ptr subworld () const { return _subworld; }
+    World_Ptr subworld () const { return _subworld; }
 
-          // ---------------------------------- methods
+    // ---------------------------------- methods
 
-      };
+};
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      string
-      SubWorldInfo::asString ( void ) const
-      {
-          return toString (*this);
-      }
+string
+SubWorldInfo::asString ( void ) const
+{
+    return toString (*this);
+}
 
 
-      string
-      SubWorldInfo::toString ( const SubWorldInfo & subworldinfo )
-      {
-          return "<subworldinfo/>";
-      }
+string
+SubWorldInfo::toString ( const SubWorldInfo & subworldinfo )
+{
+    return "<subworldinfo/>";
+}
 
 
-      ostream &
-      SubWorldInfo::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
+ostream &
+SubWorldInfo::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
 
 
-      ostream&
-      operator<<( ostream& os, const SubWorldInfo & subworldinfo)
-      {
-          return os << subworldinfo.asString();
-      }
+ostream&
+operator<<( ostream& os, const SubWorldInfo & subworldinfo)
+{
+    return os << subworldinfo.asString();
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      SubWorldInfo::SubWorldInfo (World_Ptr subworld, MultiWorld_Ptr multiworld)
-          : _subworld (subworld)
-          , _changed_resItems_id (0)
-          , _changed_channels_id (0)
-          , _changed_subscriptions_id (0)
-          , _changed_locks_id (0)
+SubWorldInfo::SubWorldInfo (World_Ptr subworld, MultiWorld_Ptr multiworld)
+    : _subworld (subworld)
+    , _changed_resItems_id (0)
+    , _changed_channels_id (0)
+    , _changed_subscriptions_id (0)
+    , _changed_locks_id (0)
 
-      {
-      #if 0
-          _changed_resItems_id =
-              g_signal_connect (G_OBJECT (subworld),
-                                "changed_resItems",
-                                (GCallback) changed_resItems_cb,
-                                world);
+{
+#if 0
+    _changed_resItems_id =
+        g_signal_connect (G_OBJECT (subworld),
+                          "changed_resItems",
+                          (GCallback) changed_resItems_cb,
+                          world);
 
-          _changed_channels_id =
-              g_signal_connect (G_OBJECT (subworld),
-                                "changed_channels",
-                                (GCallback) changed_channels_cb,
-                                world);
+    _changed_channels_id =
+        g_signal_connect (G_OBJECT (subworld),
+                          "changed_channels",
+                          (GCallback) changed_channels_cb,
+                          world);
 
-          _changed_subscriptions_id =
-              g_signal_connect (G_OBJECT (subworld),
-                                "changed_subscriptions",
-                                (GCallback) changed_subscriptions_cb,
-                                world);
+    _changed_subscriptions_id =
+        g_signal_connect (G_OBJECT (subworld),
+                          "changed_subscriptions",
+                          (GCallback) changed_subscriptions_cb,
+                          world);
 
-          _changed_locks_id =
-              g_signal_connect (G_OBJECT (subworld),
-                                "changed_locks",
-                                (GCallback) changed_locks_cb,
-                                world);
-      #endif
-      }
+    _changed_locks_id =
+        g_signal_connect (G_OBJECT (subworld),
+                          "changed_locks",
+                          (GCallback) changed_locks_cb,
+                          world);
+#endif
+}
 
 
-      SubWorldInfo::~SubWorldInfo()
-      {
-      }
+SubWorldInfo::~SubWorldInfo()
+{
+}
 
 
-      //===========================================================================
+//===========================================================================
 
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : NameConflictInfo
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : NameConflictInfo
 
-      class NameConflictInfo {
+class NameConflictInfo {
 
-        private:
-          int _depth;
-          MultiWorld_Ptr _multiworld;
-          World_Ptr _subworld;
-          const char *_name;
+  private:
+    int _depth;
+    MultiWorld_Ptr _multiworld;
+    World_Ptr _subworld;
+    string _name;
 
-        public:
-          NameConflictInfo(int depth, MultiWorld_Ptr multiworld, World_Ptr subworld, const char *name);
-          virtual ~NameConflictInfo();
+  public:
+    NameConflictInfo(int depth, MultiWorld_Ptr multiworld, World_Ptr subworld, const string & name);
+    virtual ~NameConflictInfo();
 
-          // ---------------------------------- I/O
+    // ---------------------------------- I/O
 
-          static std::string toString (const NameConflictInfo & nameconflictinfo);
+    static std::string toString (const NameConflictInfo & nameconflictinfo);
 
-          virtual std::ostream & dumpOn(std::ostream & str ) const;
+    virtual std::ostream & dumpOn(std::ostream & str ) const;
 
-          friend std::ostream& operator<<(std::ostream&, const NameConflictInfo & nameconflictinfo);
+    friend std::ostream& operator<<(std::ostream&, const NameConflictInfo & nameconflictinfo);
 
-          std::string asString (void ) const;
+    std::string asString (void ) const;
 
-          // ---------------------------------- accessors
+    // ---------------------------------- accessors
 
-          int depth () const { return _depth; }
-          MultiWorld_Ptr multiworld () const { return _multiworld; }
-          World_Ptr subworld () const { return _subworld; }
-          const char *name () const { return _name; }
-          void setName (const char *name) { free((void *)_name); _name = strdup (name); }
+    int depth () const { return _depth; }
+    MultiWorld_Ptr multiworld () const { return _multiworld; }
+    World_Ptr subworld () const { return _subworld; }
+    string name () const { return _name; }
+    void setName (const string & name) { _name = name; }
 
-          // ---------------------------------- methods
+    // ---------------------------------- methods
 
-          void incDepth (void) { _depth++; }
-      };
+    void incDepth (void) { _depth++; }
+};
 
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      string
-      NameConflictInfo::asString ( void ) const
-      {
-          return toString (*this);
-      }
+string
+NameConflictInfo::asString ( void ) const
+{
+    return toString (*this);
+}
 
 
-      string
-      NameConflictInfo::toString ( const NameConflictInfo & subworldinfo )
-      {
-          return "<nameconflictinfo/>";
-      }
+string
+NameConflictInfo::toString ( const NameConflictInfo & subworldinfo )
+{
+    return "<nameconflictinfo/>";
+}
 
 
-      ostream &
-      NameConflictInfo::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
+ostream &
+NameConflictInfo::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
 
 
-      ostream&
-      operator<<( ostream& os, const NameConflictInfo & subworldinfo)
-      {
-          return os << subworldinfo.asString();
-      }
+ostream&
+operator<<( ostream& os, const NameConflictInfo & subworldinfo)
+{
+    return os << subworldinfo.asString();
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      NameConflictInfo::NameConflictInfo (int depth, MultiWorld_Ptr multiworld, World_Ptr subworld, const char *name)
-          : _depth (depth)
-          , _multiworld (multiworld)
-          , _subworld (subworld)
-          , _name (strdup (name))
-      {
-      }
+NameConflictInfo::NameConflictInfo (int depth, MultiWorld_Ptr multiworld, World_Ptr subworld, const string & name)
+    : _depth (depth)
+    , _multiworld (multiworld)
+    , _subworld (subworld)
+    , _name (name)
+{
+}
 
 
-      NameConflictInfo::~NameConflictInfo()
-      {
-          free ((void *)_name);
-      }
+NameConflictInfo::~NameConflictInfo()
+{
+}
 
 
-      //===========================================================================
+//===========================================================================
 
-      IMPL_PTR_TYPE(MultiWorld);
+IMPL_PTR_TYPE(MultiWorld);
 
-      string
-      MultiWorld::asString ( void ) const
-      {
-          return toString (*this);
-      }
+string
+MultiWorld::asString ( void ) const
+{
+    return toString (*this);
+}
 
 
-      string
-      MultiWorld::toString ( const MultiWorld & world )
-      {
-          return "<undumpworld/>";
-      }
+string
+MultiWorld::toString ( const MultiWorld & world )
+{
+    return "<undumpworld/>";
+}
 
 
-      ostream &
-      MultiWorld::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
+ostream &
+MultiWorld::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
 
 
-      ostream&
-      operator<<( ostream& os, const MultiWorld & world)
-      {
-          return os << world.asString();
-      }
+ostream&
+operator<<( ostream& os, const MultiWorld & world)
+{
+    return os << world.asString();
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      MultiWorld::MultiWorld ()
-          : World (MULTI_WORLD)
-      {
-      }
+MultiWorld::MultiWorld ()
+    : World (MULTI_WORLD)
+{
+}
 
 
-      MultiWorld::~MultiWorld()
-      {
-      }
+MultiWorld::~MultiWorld()
+{
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      class ForeachByTypeInfo {
-          public:
-       WorldType type;
-       WorldFn callback;
-       NameConflictInfo *name_conflict_info;
+class ForeachByTypeInfo {
+    public:
+       WorldType type;
+       WorldFn callback;
+       NameConflictInfo *name_conflict_info;
 
-       int count;
-      };
+       int count;
+};
 
 
-      int
-      MultiWorld::foreachSubworld (WorldFn callback, void *user_data)
-      {
-          if (callback == NULL) return -1;
+int
+MultiWorld::foreachSubworld (WorldFn callback, void *user_data)
+{
+    if (callback == NULL) return -1;
 
-          /* Make a copy of subworlds for case where user callback is
-             running main loop and a refresh starts at that time. */
+    /* Make a copy of subworlds for case where user callback is
+       running main loop and a refresh starts at that time. */
 
-          WorldList copied_subworlds;
+    WorldList copied_subworlds;
 
-          for (SubWorldInfoList::iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       copied_subworlds.push_front ((*iter)->subworld());
-          }
+    for (SubWorldInfoList::iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       copied_subworlds.push_front ((*iter)->subworld());
+    }
 
-          int count = 0;
+    int count = 0;
 
-          for (WorldList::const_iterator iter = copied_subworlds.begin(); iter != copied_subworlds.end(); iter++) {
-              if (! callback (*iter, user_data)) {
-                  count = -1;
-                  break;
-              } else
-                  ++count;
-          }
+    for (WorldList::const_iterator iter = copied_subworlds.begin(); iter != copied_subworlds.end(); iter++) {
+        if (! callback (*iter, user_data)) {
+            count = -1;
+            break;
+        } else
+            ++count;
+    }
 
-          return count;
-      }
+    return count;
+}
 
 
-      static bool
-      foreach_by_type_cb (World_constPtr subworld, void *user_data)
-      {
-          ForeachByTypeInfo *info = (ForeachByTypeInfo *)user_data;
+static bool
+foreach_by_type_cb (World_constPtr subworld, void *user_data)
+{
+    ForeachByTypeInfo *info = (ForeachByTypeInfo *)user_data;
 
-          if ((subworld->type() != info->type)
-              || info->callback == NULL)
-          {
-       return true;
-          }
+    if ((subworld->type() != info->type)
+        || info->callback == NULL)
+    {
+       return true;
+    }
 
-          if (! info->callback (subworld, info->name_conflict_info)) {
-       info->count = -1;
-       return false;
-          } else {
-       ++info->count;
-       return true;
-          }
-      }
+    if (! info->callback (subworld, info->name_conflict_info)) {
+       info->count = -1;
+       return false;
+    } else {
+       ++info->count;
+       return true;
+    }
+}
 
 
-      int
-      MultiWorld::foreachSubworldByType (WorldType type, WorldFn callback, NameConflictInfo *name_conflict_info)
-      {
-          ForeachByTypeInfo info;
+int
+MultiWorld::foreachSubworldByType (WorldType type, WorldFn callback, NameConflictInfo *name_conflict_info)
+{
+    ForeachByTypeInfo info;
 
-          info.type = type;
-          info.callback = callback;
-          info.name_conflict_info = name_conflict_info;
-          info.count = 0;
+    info.type = type;
+    info.callback = callback;
+    info.name_conflict_info = name_conflict_info;
+    info.count = 0;
 
-          foreachSubworld (foreach_by_type_cb, (void *)(&info));
+    foreachSubworld (foreach_by_type_cb, (void *)(&info));
 
-          return info.count;
-      }
+    return info.count;
+}
 
-      //---------------------------------------------------------------------------
-      // subworld
+//---------------------------------------------------------------------------
+// subworld
 
-      static bool
-      service_name_conflict_cb (World_constPtr world, void *user_data)
-      {
-          ServiceWorld_constPtr service = dynamic_pointer_cast<const ServiceWorld>(world);
-          if (service == NULL) {
-       fprintf (stderr, "OOPS: service_name_conflict_cb: world is no service\n");
-       abort();
-          }
-
-          NameConflictInfo *info = (NameConflictInfo *)user_data;
-          if (!strcasecmp (service->name(), info->name())) {
-       info->incDepth();
-       ServiceWorld_Ptr infoservice = dynamic_pointer_cast<ServiceWorld>(info->subworld());
-       if (infoservice == NULL) {
-           fprintf (stderr, "OOPS: service_name_conflict_cb: info->subworld is no service\n");
-           abort();
-       }
-              info->setName (str::form ("%s (%d)", infoservice->name(), info->depth()).c_str());
-       info->multiworld()->foreachSubworldByType (SERVICE_WORLD, service_name_conflict_cb, info);
-              return false;
-          }
-
-          return true;
-      }
-
-
-      void
-      MultiWorld::addSubworld (World_Ptr subworld)
-      {
-          if (subworld == NULL) return;
-
-          /*
-           * If we're adding a service, make sure that the name of the service
-           * doesn't conflict with any other.
-           */
-          ServiceWorld_Ptr service = dynamic_pointer_cast<ServiceWorld>(subworld);                     // service will be NULL if subworld is not a ServiceWorld
-
-          if (service != NULL) {
-       NameConflictInfo conflict_info (0, this, subworld, service->name());
-
-       foreachSubworldByType (SERVICE_WORLD, service_name_conflict_cb, &conflict_info);
-
-       service->setName (conflict_info.name());
-          }
-
-          SubWorldInfo *subworld_info = new SubWorldInfo (subworld, this);
-
-          _subworlds.push_back (subworld_info);
-
-      //    g_signal_emit (multi, signals[SUBWORLD_ADDED], 0, subworld);
-
-          return;
-      }
-
-
-      void
-      MultiWorld::removeSubworld (World_Ptr subworld)
-      {
-          if (subworld == NULL) return;
-
-          for (SubWorldInfoList::iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       if ((*iter)->subworld() == subworld) {
-           _subworlds.erase (iter);
-      //           g_signal_emit (multi, signals[SUBWORLD_REMOVED], 0, subworld);
-           return;
-       }
-          }
-          return;
-      }
-
-
-      //---------------------------------------------------------------------------
-      // channels
-
-      ChannelList
-      MultiWorld::channels () const
-      {
-          ChannelList cl;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       cl = (*iter)->subworld()->channels();
-      //FIXME  cl.merge ((*iter)->subworld()->channels());
-          }
-          return cl;
-      }
-
-
-      bool
-      MultiWorld::containsChannel (Channel_constPtr channel) const
-      {
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       if ((*iter)->subworld()->containsChannel(channel))
-           return true;
-          }
-          return false;
-      }
-
-
-      Channel_Ptr
-      MultiWorld::getChannelByName (const char *channel_name) const
-      {
-          Channel_Ptr channel;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       channel = (*iter)->subworld()->getChannelByName(channel_name);
-       if (channel != NULL)
-           return channel;
-          }
-          return NULL;
-      }
-
-
-      Channel_Ptr
-      MultiWorld::getChannelByAlias (const char *alias) const
-      {
-          Channel_Ptr channel;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       channel = (*iter)->subworld()->getChannelByAlias(alias);
-       if (channel != NULL)
-           return channel;
-          }
-          return NULL;
-      }
-
-
-      Channel_Ptr
-      MultiWorld::getChannelById (const char *channel_id) const
-      {
-          Channel_Ptr channel;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       channel = (*iter)->subworld()->getChannelById(channel_id);
-       if (channel != NULL)
-           return channel;
-          }
-          return NULL;
-      }
-
-
-      int
-      MultiWorld::foreachChannel (ChannelFn fn, void *data) const
-      {
-          int count = 0;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       int this_count;
-       this_count = (*iter)->subworld()->foreachChannel(fn, data);
-       if (this_count < 0)
-           return -1;
-       count += this_count;
-          }
-          return count;
-      }
-
-
-      //---------------------------------------------------------------------------
-      // Single resItem queries
-
-      ResItem_constPtr
-      MultiWorld::findInstalledResItem (ResItem_constPtr resItem)
-      {
-          ResItem_constPtr installed;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       installed = (*iter)->subworld()->findInstalledResItem(resItem);
-       if (installed != NULL)
-           return installed;
-          }
-          return NULL;
-      }
-
-
-      ResItem_constPtr
-      MultiWorld::findResItem (Channel_constPtr channel, const char *name) const
-      {
-          ResItem_constPtr resItem;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       resItem = (*iter)->subworld()->findResItem(channel, name);
-       if (resItem != NULL)
-           return resItem;
-          }
-          return NULL;
-      }
-
-
-      ResItem_constPtr
-      MultiWorld::findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const
-      {
-          ResItem_constPtr resItem;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       resItem = (*iter)->subworld()->findResItemWithConstraint(channel, name, constraint, is_and);
-       if (resItem != NULL)
-           return resItem;
-          }
-          return NULL;
-      }
-
-
-      Channel_Ptr
-      MultiWorld::guessResItemChannel (ResItem_constPtr resItem) const
-      {
-          Channel_Ptr channel;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       channel = (*iter)->subworld()->guessResItemChannel(resItem);
-       if (channel != NULL)
-           return channel;
-          }
-          return NULL;
-      }
-
-      //---------------------------------------------------------------------------
-      // iterate over resItems
-
-      int
-      MultiWorld::foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data)
-      {
-          return foreachResItemByName ("", channel, fn, data);
-      }
-
-
-      int
-      MultiWorld::foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data)
-      {
-          int count = 0;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       int this_count;
-       this_count = (*iter)->subworld()->foreachResItemByName(name, channel, fn, data);
-       if (this_count < 0)
-           return -1;
-       count += this_count;
-          }
-          return count;
-      }
-
-
-      int
-      MultiWorld::foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data)
-      {
-          fprintf (stderr, "MultiWorld::foreachResItemByMatch not implemented\n");
-          return 0;
-      }
-
-
-      //-----------------------------------------------------------------------------
-      // iterater over resItems with dependency
-
-      int
-      MultiWorld::foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *data)
-      {
-          int count = 0;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       int this_count;
-       this_count = (*iter)->subworld()->foreachProvidingResItem (dep, fn, data);
-       if (this_count < 0)
-           return -1;
-       count += this_count;
-          }
-          return count;
-      }
-
-      int
-      MultiWorld::foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *data)
-      {
-          int count = 0;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       int this_count;
-       this_count = (*iter)->subworld()->foreachRequiringResItem (dep, fn, data);
-       if (this_count < 0)
-           return -1;
-       count += this_count;
-          }
-          return count;
-      }
-
-      int
-      MultiWorld::foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *data)
-      {
-          int count = 0;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       int this_count;
-       this_count = (*iter)->subworld()->foreachConflictingResItem (dep, fn, data);
-       if (this_count < 0)
-           return -1;
-       count += this_count;
-          }
-          return count;
-      }
-
-
-      //-----------------------------------------------------------------------------
-      // iterater over resItems with locks
-
-      int
-      MultiWorld::foreachLock (MatchFn fn, void *data) const
-      {
-          int count = 0;
-          for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
-       int this_count;
-       this_count = (*iter)->subworld()->foreachLock(fn, data);
-       if (this_count < 0)
-           return -1;
-       count += this_count;
-          }
-          return count;
-      }
-
-      ///////////////////////////////////////////////////////////////////
+static bool
+service_name_conflict_cb (World_constPtr world, void *user_data)
+{
+    ServiceWorld_constPtr service = dynamic_pointer_cast<const ServiceWorld>(world);
+    if (service == NULL) {
+       fprintf (stderr, "OOPS: service_name_conflict_cb: world is no service\n");
+       abort();
+    }
+
+    NameConflictInfo *info = (NameConflictInfo *)user_data;
+    if (service->name() == info->name()) {
+       info->incDepth();
+       ServiceWorld_Ptr infoservice = dynamic_pointer_cast<ServiceWorld>(info->subworld());
+       if (infoservice == NULL) {
+           fprintf (stderr, "OOPS: service_name_conflict_cb: info->subworld is no service\n");
+           abort();
+       }
+        info->setName (str::form ("%s (%d)", infoservice->name().c_str(), info->depth()).c_str());
+       info->multiworld()->foreachSubworldByType (SERVICE_WORLD, service_name_conflict_cb, info);
+        return false;
+    }
+
+    return true;
+}
+
+
+void
+MultiWorld::addSubworld (World_Ptr subworld)
+{
+    if (subworld == NULL) return;
+
+    /*
+     * If we're adding a service, make sure that the name of the service
+     * doesn't conflict with any other.
+     */
+    ServiceWorld_Ptr service = dynamic_pointer_cast<ServiceWorld>(subworld);                   // service will be NULL if subworld is not a ServiceWorld
+
+    if (service != NULL) {
+       NameConflictInfo conflict_info (0, this, subworld, service->name());
+
+       foreachSubworldByType (SERVICE_WORLD, service_name_conflict_cb, &conflict_info);
+
+       service->setName (conflict_info.name());
+    }
+
+    SubWorldInfo *subworld_info = new SubWorldInfo (subworld, this);
+
+    _subworlds.push_back (subworld_info);
+
+//    g_signal_emit (multi, signals[SUBWORLD_ADDED], 0, subworld);
+
+    return;
+}
+
+
+void
+MultiWorld::removeSubworld (World_Ptr subworld)
+{
+    if (subworld == NULL) return;
+
+    for (SubWorldInfoList::iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       if ((*iter)->subworld() == subworld) {
+           _subworlds.erase (iter);
+//         g_signal_emit (multi, signals[SUBWORLD_REMOVED], 0, subworld);
+           return;
+       }
+    }
+    return;
+}
+
+
+//---------------------------------------------------------------------------
+// channels
+
+ChannelList
+MultiWorld::channels () const
+{
+    ChannelList cl;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       cl = (*iter)->subworld()->channels();
+//FIXME        cl.merge ((*iter)->subworld()->channels());
+    }
+    return cl;
+}
+
+
+bool
+MultiWorld::containsChannel (Channel_constPtr channel) const
+{
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       if ((*iter)->subworld()->containsChannel(channel))
+           return true;
+    }
+    return false;
+}
+
+
+Channel_Ptr
+MultiWorld::getChannelByName (const string & channel_name) const
+{
+    Channel_Ptr channel;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       channel = (*iter)->subworld()->getChannelByName(channel_name);
+       if (channel != NULL)
+           return channel;
+    }
+    return NULL;
+}
+
+
+Channel_Ptr
+MultiWorld::getChannelByAlias (const string & alias) const
+{
+    Channel_Ptr channel;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       channel = (*iter)->subworld()->getChannelByAlias(alias);
+       if (channel != NULL)
+           return channel;
+    }
+    return NULL;
+}
+
+
+Channel_Ptr
+MultiWorld::getChannelById (const string & channel_id) const
+{
+    Channel_Ptr channel;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       channel = (*iter)->subworld()->getChannelById(channel_id);
+       if (channel != NULL)
+           return channel;
+    }
+    return NULL;
+}
+
+
+int
+MultiWorld::foreachChannel (ChannelFn fn, void *data) const
+{
+    int count = 0;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       int this_count;
+       this_count = (*iter)->subworld()->foreachChannel(fn, data);
+       if (this_count < 0)
+           return -1;
+       count += this_count;
+    }
+    return count;
+}
+
+
+//---------------------------------------------------------------------------
+// Single resItem queries
+
+ResItem_constPtr
+MultiWorld::findInstalledResItem (ResItem_constPtr resItem)
+{
+    ResItem_constPtr installed;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       installed = (*iter)->subworld()->findInstalledResItem(resItem);
+       if (installed != NULL)
+           return installed;
+    }
+    return NULL;
+}
+
+
+ResItem_constPtr
+MultiWorld::findResItem (Channel_constPtr channel, const string & name) const
+{
+    ResItem_constPtr resItem;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       resItem = (*iter)->subworld()->findResItem(channel, name);
+       if (resItem != NULL)
+           return resItem;
+    }
+    return NULL;
+}
+
+
+ResItem_constPtr
+MultiWorld::findResItemWithConstraint (Channel_constPtr channel, const string & name, const Capability & constraint, bool is_and) const
+{
+    ResItem_constPtr resItem;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       resItem = (*iter)->subworld()->findResItemWithConstraint(channel, name, constraint, is_and);
+       if (resItem != NULL)
+           return resItem;
+    }
+    return NULL;
+}
+
+
+Channel_Ptr
+MultiWorld::guessResItemChannel (ResItem_constPtr resItem) const
+{
+    Channel_Ptr channel;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       channel = (*iter)->subworld()->guessResItemChannel(resItem);
+       if (channel != NULL)
+           return channel;
+    }
+    return NULL;
+}
+
+//---------------------------------------------------------------------------
+// iterate over resItems
+
+int
+MultiWorld::foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data)
+{
+    return foreachResItemByName ("", channel, fn, data);
+}
+
+
+int
+MultiWorld::foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data)
+{
+    int count = 0;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       int this_count;
+       this_count = (*iter)->subworld()->foreachResItemByName(name, channel, fn, data);
+       if (this_count < 0)
+           return -1;
+       count += this_count;
+    }
+    return count;
+}
+
+
+int
+MultiWorld::foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data)
+{
+    fprintf (stderr, "MultiWorld::foreachResItemByMatch not implemented\n");
+    return 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// iterater over resItems with dependency
+
+int
+MultiWorld::foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *data)
+{
+    int count = 0;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       int this_count;
+       this_count = (*iter)->subworld()->foreachProvidingResItem (dep, fn, data);
+       if (this_count < 0)
+           return -1;
+       count += this_count;
+    }
+    return count;
+}
+
+int
+MultiWorld::foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *data)
+{
+    int count = 0;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       int this_count;
+       this_count = (*iter)->subworld()->foreachRequiringResItem (dep, fn, data);
+       if (this_count < 0)
+           return -1;
+       count += this_count;
+    }
+    return count;
+}
+
+int
+MultiWorld::foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *data)
+{
+    int count = 0;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       int this_count;
+       this_count = (*iter)->subworld()->foreachConflictingResItem (dep, fn, data);
+       if (this_count < 0)
+           return -1;
+       count += this_count;
+    }
+    return count;
+}
+
+
+//-----------------------------------------------------------------------------
+// iterater over resItems with locks
+
+int
+MultiWorld::foreachLock (MatchFn fn, void *data) const
+{
+    int count = 0;
+    for (SubWorldInfoList::const_iterator iter = _subworlds.begin(); iter != _subworlds.end(); iter++) {
+       int this_count;
+       this_count = (*iter)->subworld()->foreachLock(fn, data);
+       if (this_count < 0)
+           return -1;
+       count += this_count;
+    }
+    return count;
+}
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index a2a6b6f..b741ad7 100644 (file)
@@ -55,80 +55,80 @@ typedef std::list <SubWorldInfo *> SubWorldInfoList;
 class MultiWorld : public World {
     
 
-        private:
-      
-          SubWorldInfoList _subworlds;
-      
-          Pending_Ptr _multi_pending;
-          PendingList _subworld_pendings;
-      
-          void (*_subworld_added)   (World_Ptr subworld);
-          void (*_subworld_removed) (World_Ptr subworld);
-      
-        public:
-      
-          MultiWorld ();
-          MultiWorld (XmlNode_Ptr node);
-          MultiWorld (const char *filename);
-          virtual ~MultiWorld();
-      
-          // ---------------------------------- I/O
-      
-          static std::string toString (const MultiWorld & section);
-      
-          virtual std::ostream & dumpOn(std::ostream & str ) const;
-      
-          friend std::ostream& operator<<(std::ostream&, const MultiWorld & section);
-      
-          std::string asString (void ) const;
-      
-          // ---------------------------------- accessors
-      
-          void addSubworld (World_Ptr subworld);
-          void removeSubworld (World_Ptr subworld);
-      
-          // ---------------------------------- methods
-      
-          virtual ChannelList channels () const;
-          virtual bool containsChannel (Channel_constPtr channel) const;
-          virtual Channel_Ptr getChannelByName (const char *channel_name) const;
-          virtual Channel_Ptr getChannelByAlias (const char *alias) const;
-          virtual Channel_Ptr getChannelById (const char *channel_id) const;
-          virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const;
-          virtual int foreachChannel (ChannelFn fn, void *data) const;
-      
-          int foreachSubworld (WorldFn callback, void *user_data);
-          int foreachSubworldByType (WorldType type, WorldFn callback, NameConflictInfo *info);
-          WorldList getSubworlds ();
-          ServiceWorld_Ptr lookupService (const char *url);
-          ServiceWorld_Ptr lookupServiceById (const char *id);
-          bool mountService (const char *url, void *error);                    // GError **error);
-      
-          // Single resItem queries
-      
-          virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem);
-          virtual ResItem_constPtr findResItem (Channel_constPtr channel, const char *name) const;
-          virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const;
-      
-          // Iterate over resItems
-      
-          virtual int foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data);
-          virtual int foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data);
-          virtual int foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data);
-      
-          // Iterate across provides or requirement
-      
-          virtual int foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *data);
-          virtual int foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *data);
-          virtual int foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *data);
-      
-          // locks
-      
-          virtual int foreachLock (MatchFn fn, void *data) const;
-      
-      };
-          
-      ///////////////////////////////////////////////////////////////////
+  private:
+
+    SubWorldInfoList _subworlds;
+
+    Pending_Ptr _multi_pending;
+    PendingList _subworld_pendings;
+
+    void (*_subworld_added)   (World_Ptr subworld);
+    void (*_subworld_removed) (World_Ptr subworld);
+
+  public:
+
+    MultiWorld ();
+    MultiWorld (XmlNode_Ptr node);
+    MultiWorld (const std::string & filename);
+    virtual ~MultiWorld();
+
+    // ---------------------------------- I/O
+
+    static std::string toString (const MultiWorld & section);
+
+    virtual std::ostream & dumpOn(std::ostream & str ) const;
+
+    friend std::ostream& operator<<(std::ostream&, const MultiWorld & section);
+
+    std::string asString (void ) const;
+
+    // ---------------------------------- accessors
+
+    void addSubworld (World_Ptr subworld);
+    void removeSubworld (World_Ptr subworld);
+
+    // ---------------------------------- methods
+
+    virtual ChannelList channels () const;
+    virtual bool containsChannel (Channel_constPtr channel) const;
+    virtual Channel_Ptr getChannelByName (const std::string & channel_name) const;
+    virtual Channel_Ptr getChannelByAlias (const std::string & alias) const;
+    virtual Channel_Ptr getChannelById (const std::string & channel_id) const;
+    virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const;
+    virtual int foreachChannel (ChannelFn fn, void *data) const;
+
+    int foreachSubworld (WorldFn callback, void *user_data);
+    int foreachSubworldByType (WorldType type, WorldFn callback, NameConflictInfo *info);
+    WorldList getSubworlds ();
+    ServiceWorld_Ptr lookupService (const std::string & url);
+    ServiceWorld_Ptr lookupServiceById (const std::string & id);
+    bool mountService (const std::string & url, void *error);                  // GError **error);
+
+    // Single resItem queries
+
+    virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem);
+    virtual ResItem_constPtr findResItem (Channel_constPtr channel, const std::string & name) const;
+    virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const std::string & name, const Capability & constraint, bool is_and) const;
+
+    // Iterate over resItems
+
+    virtual int foreachResItem (Channel_Ptr channel, CResItemFn fn, void *data);
+    virtual int foreachResItemByName (const std::string & name, Channel_Ptr channel, CResItemFn fn, void *data);
+    virtual int foreachResItemByMatch (Match_constPtr match, CResItemFn fn, void *data);
+
+    // Iterate across provides or requirement
+
+    virtual int foreachProvidingResItem (const Capability & dep, ResItemAndDepFn fn, void *data);
+    virtual int foreachRequiringResItem (const Capability & dep, ResItemAndDepFn fn, void *data);
+    virtual int foreachConflictingResItem (const Capability & dep, ResItemAndDepFn fn, void *data);
+
+    // locks
+
+    virtual int foreachLock (MatchFn fn, void *data) const;
+
+};
+    
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 0f00943..b0404c4 100644 (file)
@@ -59,7 +59,7 @@ struct DepTable {
 
 static Capability
 parseXmlDep (XmlNode_constPtr node) {
-    const char *tmp;
+    string tmp;
     string epoch,version,release,name = "";
     Arch arch = Arch_noarch;
     Rel relation;
@@ -71,16 +71,16 @@ parseXmlDep (XmlNode_constPtr node) {
     }
 
     name = node->getProp ("name");
-    tmp = node->getProp ("op", NULL);
-    if (tmp) {
+    tmp = node->getProp ("op");
+    if (!tmp.empty()) {
         relation = Rel(tmp);
         epoch = node->getIntValueDefault ("epoch", Edition::noepoch);
         version = node->getProp ("version");
         release = node->getProp ("release");
     }
 
-    tmp = node->getProp ("arch", NULL);
-    if (tmp) {
+    tmp = node->getProp ("arch");
+    if (!tmp.empty()) {
         arch = Arch(node->getProp ("arch"));
     } else {
         arch =  Arch();
@@ -143,14 +143,13 @@ extract_dep_info (XmlNode_constPtr iter, struct DepTable & dep_table)
     } else if (iter->equals("conflicts")) {
        XmlNode_Ptr iter2;
        bool all_are_obs = false, this_is_obs = false;
-       const char *obs;
+       string obs;
 
        iter2 = iter->children();
 
-       obs = iter->getProp ("obsoletes", NULL);
-       if (obs) {
+       obs = iter->getProp ("obsoletes");
+       if (!obs.empty()) {
            all_are_obs = true;
-           free ((void *)obs);
        }
 
        while (iter2) {
@@ -164,10 +163,9 @@ extract_dep_info (XmlNode_constPtr iter, struct DepTable & dep_table)
 
            if (! all_are_obs) {
                this_is_obs = false;
-               obs = iter2->getProp ("obsoletes", NULL);
-               if (obs) {
+               obs = iter2->getProp ("obsoletes");
+               if (!obs.empty()) {
                    this_is_obs = true;
-                   free ((void *)obs);
                }
            }
 
@@ -352,20 +350,16 @@ Package::Package (XmlNode_constPtr node, Channel_constPtr channel)
         bool extracted_deps = false;
 
         if (iter->equals("name")) {                    name = iter->getContent();
-        } else if (iter->equals("epoch")) {            epoch = atoi (iter->getContent());
+        } else if (iter->equals("epoch")) {            epoch = atoi (iter->getContent().c_str());
         } else if (iter->equals("version")) {          version = iter->getContent();
         } else if (iter->equals("release")) {          release = iter->getContent();
-        } else if (iter->equals("summary")) {          _summary = strdup (iter->getContent());
-        } else if (iter->equals("description")) {      _description = strdup (iter->getContent());
+        } else if (iter->equals("summary")) {          _summary = iter->getContent();
+        } else if (iter->equals("description")) {      _description = iter->getContent();
         } else if (iter->equals("arch")) {             arch = Arch(iter->getContent());
         } else if (iter->equals("filesize")) {
-            const char *tmp = iter->getContent();
-            setFileSize (tmp && *tmp ? atoi (tmp) : 0);
-            free ((void *)tmp);
+            setFileSize (iter->getIntValueDefault("filesize", 0));
         } else if (iter->equals("installedsize")) {
-            const char *tmp = iter->getContent();
-            setInstalledSize (tmp && *tmp ? atoi (tmp) : 0);
-            free ((void *)tmp);
+            setInstalledSize (iter->getIntValueDefault("installedsize", 0));
         } else if (iter->equals("install_only")) {     _install_only = true;
         } else if (iter->equals("package_set")) {      _package_set = true;
         } else if (iter->equals("history")) {
index 5f7324c..68d68ca 100644 (file)
@@ -38,203 +38,190 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
+using namespace std;
 
-      IMPL_PTR_TYPE(PackageUpdate);
+IMPL_PTR_TYPE(PackageUpdate);
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      string
-      PackageUpdate::asString ( bool full ) const
-      {
-          return toString (*this);
-      }
+string
+PackageUpdate::asString ( bool full ) const
+{
+    return toString (*this);
+}
 
 
-      string
-      PackageUpdate::toString ( const PackageUpdate & package_update, bool full )
-      {
-          string ret;
-          ret += ((const Spec &)package_update).asString(full);
+string
+PackageUpdate::toString ( const PackageUpdate & package_update, bool full )
+{
+    string ret;
+    ret += ((const Spec &)package_update).asString(full);
 
-          return ret;
-      }
+    return ret;
+}
 
 
-      ostream &
-      PackageUpdate::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
-
-
-      ostream&
-      operator<<( ostream& os, const PackageUpdate& package_update)
-      {
-          return os << package_update.asString();
-      }
-
-
-      const XmlNode_Ptr
-      PackageUpdate::asXmlNode (void) const
-      {
-          XmlNode_Ptr update_node = new XmlNode("update");
-          string tmp;
-
-          if (hasEpoch()) {
-       tmp = str::form("%d", epoch());
-       update_node->addTextChild ("epoch", tmp.c_str());
-          }
-
-          update_node->addTextChild ("version", version().c_str());
+ostream &
+PackageUpdate::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
 
-          if (!release().empty()) {
-       update_node->addTextChild ("release", release().c_str());
-          }
-
-          if (_package_url && *_package_url) {
-       update_node->addTextChild ("filename", basename (strdup (_package_url)));
-          }
-
-          tmp = str::form ("%ld", (unsigned long)_package_size);
-          update_node->addTextChild ("filesize", tmp.c_str());
-
-          tmp = str::form ("%ld", (unsigned long)_installed_size);
-          update_node->addTextChild ("installedsize", tmp.c_str());
-
-          if (_signature_url) {
-       update_node->addTextChild ("signaturename", _signature_url);
-
-       tmp = str::form ("%ld", (unsigned long)_signature_size);
-       update_node->addTextChild ("signaturesize", tmp.c_str());
-          }
-
-          if (_md5sum) {
-       update_node->addTextChild ("md5sum", _md5sum);
-          }
-
-          update_node->addTextChild ("importance", _importance->asString().c_str());
-
-          update_node->addTextChild ("description", _description);
-
-          if (_hid) {
-       tmp = str::form ("%d", _hid);
-       update_node->addTextChild ("hid", tmp.c_str());
-          }
-
-          if (_license) {
-       update_node->addTextChild ("license", _license);
-          }
-
-          return update_node;
-      }
-
-      //---------------------------------------------------------------------------
-
-      PackageUpdate::PackageUpdate (const string & name)
-          : Spec (ResTraits<zypp::Package>::kind, name)
-          , _package (NULL)
-          , _package_url (NULL)
-          , _package_size (0)
-          , _installed_size (0)
-          , _signature_url (NULL)
-          , _signature_size (0)
-          , _md5sum (NULL)
-          , _importance (NULL)
-          , _hid (0)
-          , _description (NULL)
-          , _license (NULL)
-          , _parent (NULL)
-      {
-      }
-
-
-      PackageUpdate::PackageUpdate (XmlNode_constPtr node, Package_Ptr package)
-          : Spec (ResTraits<zypp::Package>::kind, package->name())
-          , _package (NULL)
-          , _package_url (NULL)
-          , _package_size (0)
-          , _installed_size (0)
-          , _signature_url (NULL)
-          , _signature_size (0)
-          , _md5sum (NULL)
-          , _importance (NULL)
-          , _hid (0)
-          , _description (NULL)
-          , _license (NULL)
-          , _parent (NULL)
-      {
-          Channel_constPtr channel;
-          const char *url_prefix = NULL;
-
-          if (node == NULL) {
-       fprintf (stderr, "PackageUpdate::PackageUpdate(NULL)\n");
-       exit (1);
-          }
-
-          /* Make sure this is an update node */
-          if (strcasecmp (node->name(), "update")) {
-       fprintf (stderr, "PackageUpdate::PackageUpdate() wrong node (%s)\n", node->name());
-       exit (1);
-          }
-
-          channel = package->channel();
-
-          _package = package;
-
-          if (channel) {
-       url_prefix = channel->filePath();
-          }
-
-          XmlNode_Ptr iter = node->children();
-
-          while (iter) {
-       if (iter->equals ("epoch")) {                   setEpoch (iter->getUnsignedIntContentDefault (0));
-       } else if (iter->equals ("version")) {          setVersion (iter->getContent());
-       } else if (iter->equals ("release")) {          setRelease (iter->getContent());
-       } else if (iter->equals ("arch")) {             setArch (iter->getContent());
-       } else if (iter->equals ("filename")) {
-           const char *tmp = iter->getContent();
-           if (url_prefix) {
-               _package_url = maybe_merge_paths (url_prefix, tmp);
-           } else {
-               _package_url = strdup (tmp);
-           }
-       } else if (iter->equals ("filesize")) {         _package_size = iter->getUnsignedIntContentDefault (0);
-       } else if (iter->equals ("installedsize")) {    _installed_size = iter->getUnsignedIntContentDefault (0);
-       } else if (iter->equals ("signaturename")) {
-           const char *tmp = iter->getContent();
-           if (url_prefix) {
-               _signature_url = maybe_merge_paths (url_prefix, tmp);
-           } else {
-               _signature_url = strdup (tmp);
-           }
-       } else if (iter->equals ("signaturesize")) {    _signature_size = iter->getUnsignedIntContentDefault (0);
-       } else if (iter->equals ("md5sum")) {           _md5sum = iter->getContent();
-       } else if (iter->equals ("importance")) {       _importance = new Importance (iter->getContent());
-       } else if (iter->equals ("description")) {      _description = iter->getContent();
-       } else if (iter->equals ("hid")) {              _hid = iter->getUnsignedIntContentDefault (0);
-       } else if (iter->equals ("license")) {          _license = iter->getContent();
-       }
-
-       iter = iter->next();
-          }
-      }
-
-
-      PackageUpdate::~PackageUpdate()
-      {
-          if (_package != NULL) _package = NULL;
-          if (_package_url != NULL) free ((void *)_package_url);
-          if (_signature_url != NULL) free ((void *)_signature_url);
-          if (_md5sum != NULL) free ((void *)_md5sum);
-          if (_description != NULL) free ((void *)_description);
-          if (_license != NULL) free ((void *)_license);
-          if (_parent != NULL) _parent = NULL;
-      }
-
-      ///////////////////////////////////////////////////////////////////
+
+ostream&
+operator<<( ostream& os, const PackageUpdate& package_update)
+{
+    return os << package_update.asString();
+}
+
+
+const XmlNode_Ptr
+PackageUpdate::asXmlNode (void) const
+{
+    XmlNode_Ptr update_node = new XmlNode("update");
+    string tmp;
+
+    if (hasEpoch()) {
+       tmp = str::form("%d", epoch());
+       update_node->addTextChild ("epoch", tmp);
+    }
+
+    update_node->addTextChild ("version", version());
+
+    if (!release().empty()) {
+       update_node->addTextChild ("release", release());
+    }
+
+    if (!_package_url.empty()) {
+       char * u = strdup (_package_url.c_str());
+       update_node->addTextChild ("filename", basename (u));           // HACK: basename expects 'char *', c_str() delivers 'const char *'
+       free (u);
+    }
+
+    tmp = str::form ("%ld", (unsigned long)_package_size);
+    update_node->addTextChild ("filesize", tmp.c_str());
+
+    tmp = str::form ("%ld", (unsigned long)_installed_size);
+    update_node->addTextChild ("installedsize", tmp);
+
+    if (!_signature_url.empty()) {
+       update_node->addTextChild ("signaturename", _signature_url);
+
+       tmp = str::form ("%ld", (unsigned long)_signature_size);
+       update_node->addTextChild ("signaturesize", tmp);
+    }
+
+    if (!_md5sum.empty()) {
+       update_node->addTextChild ("md5sum", _md5sum);
+    }
+
+    update_node->addTextChild ("importance", _importance.asString());
+
+    update_node->addTextChild ("description", _description);
+
+    if (_hid) {
+       tmp = str::form ("%d", _hid);
+       update_node->addTextChild ("hid", tmp);
+    }
+
+    if (!_license.empty()) {
+       update_node->addTextChild ("license", _license);
+    }
+
+    return update_node;
+}
+
+//---------------------------------------------------------------------------
+
+PackageUpdate::PackageUpdate (const string & name)
+    : Spec (ResTraits<zypp::Package>::kind, name)
+    , _package (NULL)
+    , _package_size (0)
+    , _installed_size (0)
+    , _signature_size (0)
+    , _importance (Importance::Undefined)
+    , _hid (0)
+    , _parent (NULL)
+{
+}
+
+
+PackageUpdate::PackageUpdate (XmlNode_constPtr node, Package_Ptr package)
+    : Spec (ResTraits<zypp::Package>::kind, package->name())
+    , _package (NULL)
+    , _package_size (0)
+    , _installed_size (0)
+    , _signature_size (0)
+    , _importance (Importance::Undefined)
+    , _hid (0)
+    , _parent (NULL)
+{
+    Channel_constPtr channel;
+    string url_prefix;
+
+    if (node == NULL) {
+       fprintf (stderr, "PackageUpdate::PackageUpdate(NULL)\n");
+       exit (1);
+    }
+
+    /* Make sure this is an update node */
+    if (!node->equals("update")) {
+       fprintf (stderr, "PackageUpdate::PackageUpdate() wrong node (%s)\n", node->name().c_str());
+       exit (1);
+    }
+
+    channel = package->channel();
+
+    _package = package;
+
+    if (channel) {
+       url_prefix = channel->filePath();
+    }
+
+    XmlNode_Ptr iter = node->children();
+
+    while (iter) {
+       if (iter->equals ("epoch")) {                   setEpoch (iter->getUnsignedIntContentDefault (0));
+       } else if (iter->equals ("version")) {          setVersion (iter->getContent());
+       } else if (iter->equals ("release")) {          setRelease (iter->getContent());
+       } else if (iter->equals ("arch")) {             setArch (iter->getContent());
+       } else if (iter->equals ("filename")) {
+           string tmp = iter->getContent();
+           if (!url_prefix.empty()) {
+               _package_url = maybe_merge_paths (url_prefix, tmp);
+           } else {
+               _package_url = tmp;
+           }
+       } else if (iter->equals ("filesize")) {         _package_size = iter->getUnsignedIntContentDefault (0);
+       } else if (iter->equals ("installedsize")) {    _installed_size = iter->getUnsignedIntContentDefault (0);
+       } else if (iter->equals ("signaturename")) {
+           string tmp = iter->getContent();
+           if (!url_prefix.empty()) {
+               _signature_url = maybe_merge_paths (url_prefix, tmp);
+           } else {
+               _signature_url = tmp;
+           }
+       } else if (iter->equals ("signaturesize")) {    _signature_size = iter->getUnsignedIntContentDefault (0);
+       } else if (iter->equals ("md5sum")) {           _md5sum = iter->getContent();
+       } else if (iter->equals ("importance")) {       _importance = Importance::parse (iter->getContent());
+       } else if (iter->equals ("description")) {      _description = iter->getContent();
+       } else if (iter->equals ("hid")) {              _hid = iter->getUnsignedIntContentDefault (0);
+       } else if (iter->equals ("license")) {          _license = iter->getContent();
+       }
+
+       iter = iter->next();
+    }
+}
+
+
+PackageUpdate::~PackageUpdate()
+{
+    if (_package != NULL) _package = NULL;
+    if (_parent != NULL) _parent = NULL;
+}
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 428e151..537d98f 100644 (file)
@@ -35,7 +35,7 @@
 #include "zypp/solver/temporary/XmlNode.h"
 
 /////////////////////////////////////////////////////////////////////////
-namespace zypp 
+namespace zypp
 { ///////////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////////
   namespace solver
@@ -52,94 +52,94 @@ namespace zypp
  **/
 
 class PackageUpdate : public Spec {
-          
-      
-        private:
-          Package_Ptr _package;
-      
-          const char *_package_url;
-          size_t _package_size;
-          size_t _installed_size;
-      
-          const char *_signature_url;
-          size_t _signature_size;
-      
-          const char *_md5sum;
-      
-          const Importance *_importance;
-      
-          unsigned int _hid;
-      
-          const char *_description;
-      
-          const char *_license;
-      
-          // refers to the parent package for SuSE patch RPMs
-          Package_constPtr _parent;
-      
-        public:
-      
-          PackageUpdate(const std::string & name);
-          PackageUpdate(XmlNode_constPtr node, Package_Ptr package);
-      
-          virtual ~PackageUpdate();
-      
-          // ---------------------------------- I/O
-      
-          const XmlNode_Ptr asXmlNode (void) const;
-      
-          static std::string toString ( const PackageUpdate & packageupdate, bool full = false );
-      
-          virtual std::ostream & dumpOn( std::ostream & str ) const;
-      
-          friend std::ostream& operator<<( std::ostream&, const PackageUpdate& );
-      
-          std::string asString ( bool full = false ) const;
-      
-          // ---------------------------------- accessors
-      
-          Package_constPtr package() const { return _package; }
-          void setPackage (Package_Ptr package) { _package = package; }
-      
-          const char *packageUrl() const { return _package_url; }
-          void setPackageUrl (const char *package_url) { _package_url = package_url; }
-      
-          size_t packageSize() const { return _package_size; }
-          void setPackageSize (size_t package_size) { _package_size = package_size; }
-      
-          size_t installedSize() const { return _installed_size; }
-          void setInstalledSize (size_t installed_size ) { _installed_size = installed_size; }
-      
-          const char *description() const { return _description; }
-          void setDescription(const char *description) { _description = strdup (description); }
-      
-          const char *signatureUrl() const { return _signature_url; }
-          void setSignatureUrl (const char *signature_url) { _signature_url = signature_url; }
-      
-          size_t signatureSize() const { return _signature_size; }
-          void setSignatureSize (size_t signature_size) { _signature_size = signature_size; }
-      
-          const char *md5sum() const { return _md5sum; }
-          void setMd5sum (const char *md5sum) { _md5sum = md5sum; }
-      
-          const Importance *importance() const { return _importance; }
-          void setImportance (const Importance *importance) { _importance = importance; }
-      
-          unsigned int hid() const { return _hid; }
-          void setHid (unsigned int hid) { _hid = hid; }
-      
-          const char *license() const { return _license; }
-          void setLicense (const char *license) { _license = license; }
-      
-          // refers to the parent package for SuSE patch RPMs
-          Package_constPtr parent() const { return _parent; }
-          void setParent (Package_constPtr parent) { _parent = parent; }
-      
-          // ---------------------------------- methods
-      
-      };
-
-      ///////////////////////////////////////////////////////////////////
+
+
+  private:
+    Package_Ptr _package;
+
+    std::string _package_url;
+    size_t _package_size;
+    size_t _installed_size;
+
+    std::string _signature_url;
+    size_t _signature_size;
+
+    std::string _md5sum;
+
+    Importance _importance;
+
+    unsigned int _hid;
+
+    std::string _description;
+
+    std::string _license;
+
+    // refers to the parent package for SuSE patch RPMs
+    Package_constPtr _parent;
+
+  public:
+
+    PackageUpdate(const std::string & name);
+    PackageUpdate(XmlNode_constPtr node, Package_Ptr package);
+
+    virtual ~PackageUpdate();
+
+    // ---------------------------------- I/O
+
+    const XmlNode_Ptr asXmlNode (void) const;
+
+    static std::string toString ( const PackageUpdate & packageupdate, bool full = false );
+
+    virtual std::ostream & dumpOn( std::ostream & str ) const;
+
+    friend std::ostream& operator<<( std::ostream&, const PackageUpdate& );
+
+    std::string asString ( bool full = false ) const;
+
+    // ---------------------------------- accessors
+
+    Package_constPtr package() const { return _package; }
+    void setPackage (Package_Ptr package) { _package = package; }
+
+    const std::string packageUrl() const { return _package_url; }
+    void setPackageUrl (const std::string & package_url) { _package_url = package_url; }
+
+    size_t packageSize() const { return _package_size; }
+    void setPackageSize (size_t package_size) { _package_size = package_size; }
+
+    size_t installedSize() const { return _installed_size; }
+    void setInstalledSize (size_t installed_size ) { _installed_size = installed_size; }
+
+    const std::string description() const { return _description; }
+    void setDescription(const std::string & description) { _description = description; }
+
+    const std::string signatureUrl() const { return _signature_url; }
+    void setSignatureUrl (const std::string & signature_url) { _signature_url = signature_url; }
+
+    size_t signatureSize() const { return _signature_size; }
+    void setSignatureSize (size_t signature_size) { _signature_size = signature_size; }
+
+    const std::string md5sum() const { return _md5sum; }
+    void setMd5sum (const std::string & md5sum) { _md5sum = md5sum; }
+
+    const Importance importance() const { return _importance; }
+    void setImportance (const Importance & importance) { _importance = importance; }
+
+    unsigned int hid() const { return _hid; }
+    void setHid (unsigned int hid) { _hid = hid; }
+
+    const std::string license() const { return _license; }
+    void setLicense (const std::string & license) { _license = license; }
+
+    // refers to the parent package for SuSE patch RPMs
+    Package_constPtr parent() const { return _parent; }
+    void setParent (Package_constPtr parent) { _parent = parent; }
+
+    // ---------------------------------- methods
+
+};
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 82af58d..c3a0ec1 100644 (file)
@@ -39,56 +39,56 @@ namespace zypp
     /////////////////////////////////////////////////////////////////////
     namespace detail
     { ///////////////////////////////////////////////////////////////////
-      
-      typedef bool (*ServiceWorldAssembleFn) (ServiceWorld_Ptr service, void *error);  // GError **error
-      
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : ServiceWorld
-      
-      class ServiceWorld : public StoreWorld {
-          
-      
-        private:
-      
-          char *_url;
-          char *_name;
-          char *_unique_id;
-      
-          bool _is_sticky;             // if true, can't be unmounted
-          bool _is_invisible;          // ... to users
-          bool _is_unsaved;            // Never save into the services.xml file
-          bool _is_singleton;          // only one such service at a time.  FIXME: broken
-      
-          ServiceWorldAssembleFn _assemble_fn;
-      
-        public:
-      
-          ServiceWorld ();
-          virtual ~ServiceWorld();
-      
-          // ---------------------------------- I/O
-      
-          static std::string toString (const ServiceWorld & section);
-      
-          virtual std::ostream & dumpOn(std::ostream & str ) const;
-      
-          friend std::ostream& operator<<(std::ostream&, const ServiceWorld & section);
-      
-          std::string asString (void ) const;
-      
-          // ---------------------------------- accessors
-      
-          char *url () const { return _url; }
-          char *name () const { return _name; }
-          void setName (const char *name) { _name = strdup (name); }
-          char *unique_id () const { return _unique_id; }
-      
-          // ---------------------------------- methods
-      
-      };
-        
-      ///////////////////////////////////////////////////////////////////
+
+typedef bool (*ServiceWorldAssembleFn) (ServiceWorld_Ptr service, void *error);        // GError **error
+
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : ServiceWorld
+
+class ServiceWorld : public StoreWorld {
+    
+
+  private:
+
+    std::string _url;
+    std::string _name;
+    std::string _unique_id;
+
+    bool _is_sticky;           // if true, can't be unmounted
+    bool _is_invisible;                // ... to users
+    bool _is_unsaved;          // Never save into the services.xml file
+    bool _is_singleton;                // only one such service at a time.  FIXME: broken
+
+    ServiceWorldAssembleFn _assemble_fn;
+
+  public:
+
+    ServiceWorld ();
+    virtual ~ServiceWorld();
+
+    // ---------------------------------- I/O
+
+    static std::string toString (const ServiceWorld & section);
+
+    virtual std::ostream & dumpOn(std::ostream & str ) const;
+
+    friend std::ostream& operator<<(std::ostream&, const ServiceWorld & section);
+
+    std::string asString (void ) const;
+
+    // ---------------------------------- accessors
+
+    std::string url () const { return _url; }
+    std::string name () const { return _name; }
+    void setName (const std::string & name) { _name = name; }
+    std::string unique_id () const { return _unique_id; }
+
+    // ---------------------------------- methods
+
+};
+  
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 9cf0c09..6677664 100644 (file)
@@ -97,7 +97,7 @@ bool
 StoreWorld::addResItem (ResItem_constPtr resItem)
 {
     ResItemAndDependency_Ptr r_and_d;
-    const char *package_name;
+    string package_name;
     Channel_constPtr channel;
     bool actually_added_package = false;
 
@@ -349,7 +349,7 @@ StoreWorld::findInstalledResItem (ResItem_constPtr resItem)
 //
 
 ResItem_constPtr
-StoreWorld::findResItem (Channel_constPtr channel, const char *name) const
+StoreWorld::findResItem (Channel_constPtr channel, const string & name) const
 {
     syncConditional (channel);
     for (ResItemTable::const_iterator pos = _resItems_by_name.lower_bound(name); pos != _resItems_by_name.upper_bound(name); pos++) {
@@ -363,7 +363,7 @@ StoreWorld::findResItem (Channel_constPtr channel, const char *name) const
 
 
 ResItem_constPtr
-StoreWorld::findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const
+StoreWorld::findResItemWithConstraint (Channel_constPtr channel, const string & name, const Capability & constraint, bool is_and) const
 {
        fprintf (stderr, "StoreWorld::findResItemWithConstraint() not implemented\n");
     return 0;
@@ -658,15 +658,14 @@ StoreWorld::containsChannel (Channel_constPtr channel) const
 
 
 Channel_Ptr
-StoreWorld::getChannelByName (const char *channel_name) const
+StoreWorld::getChannelByName (const string & channel_name) const
 {
-    if (channel_name == NULL
-       || *channel_name == 0) {
+    if (channel_name.empty()) {
        return NULL;
     }
 
     for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) {
-       if (strcasecmp ((*iter)->name(), channel_name) == 0) {
+       if ((*iter)->name() == channel_name) {
            return *iter;
        }
     }
@@ -675,15 +674,14 @@ StoreWorld::getChannelByName (const char *channel_name) const
 
 
 Channel_Ptr
-StoreWorld::getChannelByAlias (const char *alias) const
+StoreWorld::getChannelByAlias (const string & alias) const
 {
-    if (alias == NULL
-       || *alias == 0) {
+    if (alias.empty()) {
        return NULL;
     }
 
     for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) {
-       if (strcasecmp ((*iter)->alias(), alias) == 0) {
+       if ((*iter)->alias() == alias) {
            return *iter;
        }
     }
@@ -692,15 +690,14 @@ StoreWorld::getChannelByAlias (const char *alias) const
 
 
 Channel_Ptr
-StoreWorld::getChannelById (const char *channel_id) const
+StoreWorld::getChannelById (const string & channel_id) const
 {
-    if (channel_id == NULL
-       || *channel_id  == 0) {
+    if (channel_id.empty()) {
        return NULL;
     }
 
     for (ChannelList::const_iterator iter = _channels.begin(); iter != _channels.end(); iter++) {
-       if (strcasecmp ((*iter)->id(), channel_id) == 0) {
+       if ((*iter)->id() == channel_id) {
            return *iter;
        }
     }
index 7d91668..2afdede 100644 (file)
@@ -112,17 +112,17 @@ class StoreWorld : public World {
 
     virtual bool containsChannel (Channel_constPtr channel) const;
 
-    virtual Channel_Ptr getChannelByName (const char *channel_name) const;
-    virtual Channel_Ptr getChannelByAlias (const char *alias) const;
-    virtual Channel_Ptr getChannelById (const char *channel_id) const;
+    virtual Channel_Ptr getChannelByName (const std::string & channel_name) const;
+    virtual Channel_Ptr getChannelByAlias (const std::string & alias) const;
+    virtual Channel_Ptr getChannelById (const std::string & channel_id) const;
 
     virtual int foreachChannel (ChannelFn fn, void *data) const;
 
     // Single resItem queries
 
     virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem);
-    virtual ResItem_constPtr findResItem (Channel_constPtr channel, const char *name) const;
-    virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability & constraint, bool is_and) const;
+    virtual ResItem_constPtr findResItem (Channel_constPtr channel, const std::string & name) const;
+    virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const std::string & name, const Capability & constraint, bool is_and) const;
     virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const;
 
 };
index e1de4b6..3d8dc82 100644 (file)
@@ -39,361 +39,358 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
+using namespace std;
 
-      #define SUBSCRIPTION_PATH "/var/adm/zypp"
-      #define OLD_SUBSCRIPTION_PATH "/var/lib/rcd"
-      #define SUBSCRIPTION_NAME "/subscriptions.xml"
+#define SUBSCRIPTION_PATH "/var/adm/zypp"
+#define OLD_SUBSCRIPTION_PATH "/var/lib/rcd"
+#define SUBSCRIPTION_NAME "/subscriptions.xml"
 
-      #define DEFAULT_SUBSCRIPTION_FILE SUBSCRIPTION_PATH SUBSCRIPTION_NAME
-      #define OLD_SUBSCRIPTION_FILE OLD_SUBSCRIPTION_PATH SUBSCRIPTION_NAME
+#define DEFAULT_SUBSCRIPTION_FILE SUBSCRIPTION_PATH SUBSCRIPTION_NAME
+#define OLD_SUBSCRIPTION_FILE OLD_SUBSCRIPTION_PATH SUBSCRIPTION_NAME
 
-      /* Old subscriptions expire in 60 days */
-      #define OLD_SUBSCRIPTION_EXPIRATION 60*24*60*60
+/* Old subscriptions expire in 60 days */
+#define OLD_SUBSCRIPTION_EXPIRATION 60*24*60*60
 
-      SubscriptionList Subscription::subscriptions;
-      bool Subscription::subscriptions_changed = false;
-      const char *Subscription::subscription_file = DEFAULT_SUBSCRIPTION_FILE;
+SubscriptionList Subscription::subscriptions;
+bool Subscription::subscriptions_changed = false;
+string Subscription::subscription_file = DEFAULT_SUBSCRIPTION_FILE;
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
-      string
-      Subscription::asString ( void ) const
-      {
-          return toString (*this);
-      }
+string
+Subscription::asString ( void ) const
+{
+    return toString (*this);
+}
 
 
-      string
-      Subscription::toString ( const Subscription & s)
-      {
-          return "<subscription/>";
-      }
+string
+Subscription::toString ( const Subscription & s)
+{
+    return "<subscription/>";
+}
 
-      ostream &
-      Subscription::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
+ostream &
+Subscription::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
 
 
-      ostream&
-      operator<<( ostream& os, const Subscription & s)
-      {
-          return os << s.asString();
-      }
+ostream&
+operator<<( ostream& os, const Subscription & s)
+{
+    return os << s.asString();
+}
 
-      //---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
 
 
-      void
-      Subscription::save (void)
-      {
-          xmlDoc *doc;
-          xmlNode *root;
-          char buf[64];
-          time_t now;
-          int save_retval;
+void
+Subscription::save (void)
+{
+    xmlDoc *doc;
+    xmlNode *root;
+    char buf[64];
+    time_t now;
+    int save_retval;
 
-          if (! subscriptions_changed)
-       return;
+    if (! subscriptions_changed)
+       return;
 
-          time (&now);
+    time (&now);
 
-          root = xmlNewNode (NULL, (const xmlChar*)"subscriptions");
-          xmlNewProp (root, (const xmlChar*)"version", (const xmlChar*)"2.0");
+    root = xmlNewNode (NULL, (const xmlChar*)"subscriptions");
+    xmlNewProp (root, (const xmlChar*)"version", (const xmlChar*)"2.0");
 
-          doc = xmlNewDoc ((const xmlChar*)"1.0");
-          xmlDocSetRootElement (doc, root);
+    doc = xmlNewDoc ((const xmlChar*)"1.0");
+    xmlDocSetRootElement (doc, root);
 
-          for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) {
-       xmlNode *sub_node;
+    for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) {
+       xmlNode *sub_node;
 
-       Subscription *sub = *iter;
+       Subscription *sub = *iter;
 
-       /* Drop "old" (i.e. imported from 1.x) subscriptions that
-          we haven't seen for a while. */
-       if (sub->_old) {
-           double elapsed = difftime (now, sub->_last_seen);
-           if (elapsed > OLD_SUBSCRIPTION_EXPIRATION)
-               continue;
-       }
+       /* Drop "old" (i.e. imported from 1.x) subscriptions that
+          we haven't seen for a while. */
+       if (sub->_old) {
+           double elapsed = difftime (now, sub->_last_seen);
+           if (elapsed > OLD_SUBSCRIPTION_EXPIRATION)
+               continue;
+       }
 
-       sub_node = xmlNewChild (root, NULL, (const xmlChar*)"channel", NULL);
+       sub_node = xmlNewChild (root, NULL, (const xmlChar*)"channel", NULL);
 
-       xmlNewProp (sub_node, (const xmlChar*)"id", (const xmlChar*)(sub->_channel_id.c_str()));
+       xmlNewProp (sub_node, (const xmlChar*)"id", (const xmlChar*)(sub->_channel_id.c_str()));
 
-       snprintf (buf, sizeof (buf), "%ld", (long) sub->_last_seen);
-       xmlNewProp (sub_node, (const xmlChar*)"last_seen", (const xmlChar*)buf);
+       snprintf (buf, sizeof (buf), "%ld", (long) sub->_last_seen);
+       xmlNewProp (sub_node, (const xmlChar*)"last_seen", (const xmlChar*)buf);
 
-       if (sub->_old)
-           xmlNewProp (sub_node, (const xmlChar*)"old", (const xmlChar*)"1");
-          }
+       if (sub->_old)
+           xmlNewProp (sub_node, (const xmlChar*)"old", (const xmlChar*)"1");
+    }
 
-          save_retval = xmlSaveFile (subscription_file, doc);
-          xmlFreeDoc (doc);
+    save_retval = xmlSaveFile (subscription_file.c_str(), doc);
+    xmlFreeDoc (doc);
 
-          if (save_retval > 0) {
-       /* Writing out the subscription file succeeded. */
-       subscriptions_changed = false;
-          } else {
+    if (save_retval > 0) {
+       /* Writing out the subscription file succeeded. */
+       subscriptions_changed = false;
+    } else {
              WAR << "Unable to save subscription data to '"
                  << subscription_file << "'" << endl;
              WAR << "Subscription will not be saved!" << endl;
-          }
-      }
+    }
+}
 
 
-      void
-      Subscription::load_old_subscriptions (void)
-      {
-          static bool tried_to_do_this_already = false;
-          xmlDoc *doc;
-          XmlNode_Ptr node;
+void
+Subscription::load_old_subscriptions (void)
+{
+    static bool tried_to_do_this_already = false;
+    xmlDoc *doc;
+    XmlNode_Ptr node;
 
-          if (tried_to_do_this_already)
-       return;
-          tried_to_do_this_already = true;
+    if (tried_to_do_this_already)
+       return;
+    tried_to_do_this_already = true;
 
-          if (access (OLD_SUBSCRIPTION_FILE, R_OK) != 0) {
+    if (access (OLD_SUBSCRIPTION_FILE, R_OK) != 0) {
              WAR << "Can't find rcd 1.x subscription file '"
                  << OLD_SUBSCRIPTION_FILE << "'" << endl;
-       return;
-          }
+       return;
+    }
 
-          doc = xmlParseFile (OLD_SUBSCRIPTION_FILE);
-          if (doc == NULL) {
+    doc = xmlParseFile (OLD_SUBSCRIPTION_FILE);
+    if (doc == NULL) {
              ERR << "Can't parse rcd 1.x subscription file '"
                  << OLD_SUBSCRIPTION_FILE << "'" << endl;
-       return;
-          }
+       return;
+    }
 
-          node = new XmlNode (xmlDocGetRootElement (doc));
+    node = new XmlNode (xmlDocGetRootElement (doc));
 
-          if (!node->equals("subscriptions")) {
+    if (!node->equals("subscriptions")) {
              ERR << "rcd 1.x subscription file '"
                  << OLD_SUBSCRIPTION_FILE << "' is malformed" << endl;
-       return;
-          }
+       return;
+    }
 
-          MIL << "Importing rcd 1.x subscriptions." << endl;
+    MIL << "Importing rcd 1.x subscriptions." << endl;
 
-          node = node->children();
+    node = node->children();
 
-          while (node != NULL) {
+    while (node != NULL) {
 
-       if (node->equals ("channel")) {
-           const char *id_str;
+       if (node->equals ("channel")) {
+           string id_str;
 
-           id_str = node->getProp ("channel_id");
-           if (id_str && *id_str) {
+           id_str = node->getProp ("channel_id");
+           if (!id_str.empty()) {
 
-               Subscription *sub = new Subscription (id_str);
-               sub->_old = true;
+               Subscription *sub = new Subscription (id_str);
+               sub->_old = true;
 
-               subscriptions.push_back (sub);
-           }
-       }
+               subscriptions.push_back (sub);
+           }
+       }
 
-       node = node->next();
-          }
+       node = node->next();
+    }
 
-          /* If we've imported old subscriptions, we need to write them
-             out immediately into the new subscriptions file. */
+    /* If we've imported old subscriptions, we need to write them
+       out immediately into the new subscriptions file. */
 
-          subscriptions_changed = true;
-          save ();
-      }
+    subscriptions_changed = true;
+    save ();
+}
 
 
-      void
-      Subscription::load (void)
-      {
-          xmlDoc *doc;
-          XmlNode_Ptr node;
+void
+Subscription::load (void)
+{
+    xmlDoc *doc;
+    XmlNode_Ptr node;
 
-          if (access (subscription_file, R_OK) != 0) {
-       load_old_subscriptions ();
-       return;
-          }
+    if (access (subscription_file.c_str(), R_OK) != 0) {
+       load_old_subscriptions ();
+       return;
+    }
 
-          doc = xmlParseFile (subscription_file);
-          if (doc == NULL) {
+    doc = xmlParseFile (subscription_file.c_str());
+    if (doc == NULL) {
              ERR << "Can't parse subscription file '"
                  << subscription_file << "'" << endl;
-       return;
-          }
+       return;
+    }
 
-          node = new XmlNode (xmlDocGetRootElement (doc));
+    node = new XmlNode (xmlDocGetRootElement (doc));
 
-          if (! node->equals ("subscriptions")) {
+    if (! node->equals ("subscriptions")) {
              ERR << "Subscription file '"
                  << subscription_file << "' is malformed" << endl;
-       return;
-          }
+       return;
+    }
 
-          node = node->children();
+    node = node->children();
 
-          while (node != NULL) {
+    while (node != NULL) {
 
-       if (node->equals ("channel")) {
-           const char *id_str, *last_seen_str;
+       if (node->equals ("channel")) {
+           string id_str, last_seen_str;
 
-           id_str = node->getProp ("id");
-           last_seen_str = node->getProp ("last_seen");
+           id_str = node->getProp ("id");
+           last_seen_str = node->getProp ("last_seen");
 
-           if (id_str && *id_str) {
-               Subscription *sub = new Subscription (id_str);
+           if (!id_str.empty()) {
+               Subscription *sub = new Subscription (id_str);
 
-               if (last_seen_str)
-                   sub->_last_seen = (time_t) atol (last_seen_str);
-               else
-                   sub->_last_seen = time (NULL);
+               if (!last_seen_str.empty())
+                   sub->_last_seen = (time_t) atol (last_seen_str.c_str());
+               else
+                   sub->_last_seen = time (NULL);
 
-               sub->_old = node->getUnsignedIntValueDefault("old", 0);
+               sub->_old = node->getUnsignedIntValueDefault("old", 0);
 
-               subscriptions.push_back (sub);
-           }
+               subscriptions.push_back (sub);
+           }
 
-           free ((void *)id_str);
-           free ((void *)last_seen_str);
+       }
 
-       }
+       node = node->next();
+    }
 
-       node = node->next();
-          }
+    xmlFreeDoc (doc);
+}
 
-          xmlFreeDoc (doc);
-      }
+//---------------------------------------------------------------------------
 
-      //---------------------------------------------------------------------------
+bool
+Subscription::match (Channel_constPtr channel)
+{
+    bool match;
 
-      bool
-      Subscription::match (Channel_constPtr channel)
-      {
-          bool match;
+    /* Paranoia is the programmer's friend. */
+    if (channel == NULL) return false;
+    if (channel->id().empty()) return false;
 
-          /* Paranoia is the programmer's friend. */
-          if (channel == NULL) return false;
-          if (channel->id() == NULL) return false;
+    /* If this is an old (i.e. imported from 1.x) subscription, we
+       compare it against the channel id's tail. */
 
-          /* If this is an old (i.e. imported from 1.x) subscription, we
-             compare it against the channel id's tail. */
+    if (_old) {
+       string id = channel->legacyId ();
+       int len1, len2;
 
-          if (_old) {
-       const char *id = channel->legacyId ();
-       int len1, len2;
+       if (id.empty())
+           return false;
 
-       if (!id)
-           return false;
+       len1 = strlen (_channel_id.c_str());
+       len2 = strlen (id.c_str());
 
-       len1 = strlen (_channel_id.c_str());
-       len2 = strlen (id);
+       if (len1 > len2)
+           return false;
 
-       if (len1 > len2)
-           return false;
+       /* If the tails match, mutate the Subscription into a
+          new-style subscription for that channel. */
+       if (! strcmp (id.c_str() + (len2 - len1), _channel_id.c_str())) {
+           _channel_id = channel->id ();
+           _old = false;
+           subscriptions_changed = true;
 
-       /* If the tails match, mutate the Subscription into a
-          new-style subscription for that channel. */
-       if (! strcmp (id + (len2 - len1), _channel_id.c_str())) {
-           _channel_id = channel->id ();
-           _old = false;
-           subscriptions_changed = true;
+           return true;
+       }
 
-           return true;
-       }
+       return false;
+    }
 
-       return false;
-          }
+    match = (_channel_id == channel->id ());
 
-          match = (_channel_id == channel->id ());
+    if (match) {
+       time (&_last_seen);
+    }
 
-          if (match) {
-       time (&_last_seen);
-          }
+    return match;
+}
 
-          return match;
-      }
+//-----------------------------------------------------------------------------
 
-      //-----------------------------------------------------------------------------
+void
+Subscription::setFile (const string & path)
+{
+    subscription_file = path;
+}
 
-      void
-      Subscription::setFile (const char *path)
-      {
-          subscription_file = path;
-      }
 
+bool
+Subscription::status (Channel_constPtr channel)
+{
+    if (subscriptions.empty())
+       load ();
 
-      bool
-      Subscription::status (Channel_constPtr channel)
-      {
-          if (subscriptions.empty())
-       load ();
+    if (channel == NULL)
+       return false;
 
-          if (channel == NULL)
-       return false;
+    for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) {
+       Subscription *sub = *iter;
+       if (sub->match (channel))
+           return true;
+    }
 
-          for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) {
-       Subscription *sub = *iter;
-       if (sub->match (channel))
-           return true;
-          }
+    save ();
 
-          save ();
+    return false;
+}
 
-          return false;
-      }
 
+void
+Subscription::setStatus (Channel_constPtr channel, bool subscribe_to_channel)
+{
+    bool currently_subscribed;
 
-      void
-      Subscription::setStatus (Channel_constPtr channel, bool subscribe_to_channel)
-      {
-          bool currently_subscribed;
+    if (channel == NULL) return;
 
-          if (channel == NULL) return;
+    currently_subscribed = status (channel);
 
-          currently_subscribed = status (channel);
+    if (currently_subscribed && !subscribe_to_channel) {
 
-          if (currently_subscribed && !subscribe_to_channel) {
+       /* Unsubscribe to the channel */
+       for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) {
+           Subscription *sub = *iter;
+           if (sub->match (channel)) {
+               subscriptions.erase (iter);
+               subscriptions_changed = true;
+               break;
+           }
+       }
 
-       /* Unsubscribe to the channel */
-       for (SubscriptionList::iterator iter = subscriptions.begin(); iter != subscriptions.end(); iter++) {
-           Subscription *sub = *iter;
-           if (sub->match (channel)) {
-               subscriptions.erase (iter);
-               subscriptions_changed = true;
-               break;
-           }
-       }
+    } else if (!currently_subscribed && subscribe_to_channel) {
 
-          } else if (!currently_subscribed && subscribe_to_channel) {
+       /* Subscribe to the channel */
+       Subscription *sub;
+       sub = new Subscription (channel->id ());
+       subscriptions.push_back(sub);
+       subscriptions_changed = true;
+    }
 
-       /* Subscribe to the channel */
-       Subscription *sub;
-       sub = new Subscription (channel->id ());
-       subscriptions.push_back(sub);
-       subscriptions_changed = true;
-          }
+    save ();
+}
 
-          save ();
-      }
+//---------------------------------------------------------------------------
 
-      //---------------------------------------------------------------------------
+Subscription::Subscription(const string & id)
+{
+    _channel_id = id;
+    _last_seen  = time (NULL);
+    _old        = false;
+}
 
-      Subscription::Subscription(const char *id)
-      {
-          _channel_id = string (id);
-          _last_seen  = time (NULL);
-          _old        = false;
-      }
 
+Subscription::~Subscription()
+{
+}
 
-      Subscription::~Subscription()
-      {
-      }
-
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index cb5d823..e23b0de 100644 (file)
@@ -40,57 +40,57 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : Subscription
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : Subscription
 
 
-      class Subscription;
-      typedef std::list<Subscription *> SubscriptionList;
+class Subscription;
+typedef std::list<Subscription *> SubscriptionList;
 
-      class Subscription {
+class Subscription {
 
-        private:
+  private:
 
-          static SubscriptionList subscriptions;
-          static bool subscriptions_changed;
-          static const char *subscription_file;
+    static SubscriptionList subscriptions;
+    static bool subscriptions_changed;
+    static std::string subscription_file;
 
-          std::string _channel_id;
-          time_t _last_seen;
-          bool _old;           // subscription imported from an old-style subs file
+    std::string _channel_id;
+    time_t _last_seen;
+    bool _old;         // subscription imported from an old-style subs file
 
-          bool match (Channel_constPtr channel);
-          static void save (void);
-          static void load (void);
-          static void load_old_subscriptions (void);
+    bool match (Channel_constPtr channel);
+    static void save (void);
+    static void load (void);
+    static void load_old_subscriptions (void);
 
-        public:
+  public:
 
-          Subscription (const char *id);
-          virtual ~Subscription();
+    Subscription (const std::string & id);
+    virtual ~Subscription();
 
-          // ---------------------------------- I/O
+    // ---------------------------------- I/O
 
-          static std::string toString ( const Subscription & section);
+    static std::string toString ( const Subscription & section);
 
-          virtual std::ostream & dumpOn( std::ostream & str ) const;
+    virtual std::ostream & dumpOn( std::ostream & str ) const;
 
-          friend std::ostream& operator<<( std::ostream&, const Subscription & section);
+    friend std::ostream& operator<<( std::ostream&, const Subscription & section);
 
-          std::string asString ( void ) const;
+    std::string asString ( void ) const;
 
-          // ---------------------------------- accessors
+    // ---------------------------------- accessors
 
-          // ---------------------------------- methods
+    // ---------------------------------- methods
 
-          void  setFile (const char *file);
-          static bool status (Channel_constPtr channel);
-          static void setStatus (Channel_constPtr channel, bool channel_is_subscribed);
+    void setFile (const std::string & file);
+    static bool status (Channel_constPtr channel);
+    static void setStatus (Channel_constPtr channel, bool channel_is_subscribed);
 
-      };
+};
 
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 6b976c9..0ccee71 100644 (file)
@@ -32,141 +32,141 @@ namespace zypp
     /////////////////////////////////////////////////////////////////////
     namespace detail
     { ///////////////////////////////////////////////////////////////////
-        
-      using namespace std;
-      
-      IMPL_PTR_TYPE(UndumpWorld);
-      
-      //---------------------------------------------------------------------------
-      
-      string
-      UndumpWorld::asString ( void ) const
-      {
-          return toString (*this);
-      }
-      
-      
-      string
-      UndumpWorld::toString ( const UndumpWorld & world )
-      {
-          return "<undumpworld/>";
-      }
-      
-      
-      ostream &
-      UndumpWorld::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
-      
-      
-      ostream&
-      operator<<( ostream& os, const UndumpWorld & world)
-      {
-          return os << world.asString();
-      }
-      
-      //---------------------------------------------------------------------------
-      
-      UndumpWorld::UndumpWorld (const char *filename)
-          : StoreWorld (UNDUMP_WORLD)
-      {
-          load (filename);
-      }
-      
-      
-      UndumpWorld::~UndumpWorld()
-      {
-          fprintf (stderr, "*** deleting undump world[%p]: %s\n", this, World::toString(type()).c_str());
-      }
-      
-      //---------------------------------------------------------------------------
-      
-      
-      static bool
-      add_channel_cb (Channel_Ptr channel, bool subscribed, void *data)
-      {
-          UndumpWorld *undump = (UndumpWorld *)data;
-      
-          undump->addChannel (channel);
-      
-          if (!channel->system ()) {
-       undump->setSubscription (channel, subscribed);
-          }
-      
-          return true;
-      }
-      
-      
-      static bool
-      add_resItem_cb (ResItem_constPtr res, void *data)
-      {
-          UndumpWorld *undump = (UndumpWorld *)data;
-      
-          undump->addResItem (res);
-      
-          return true;
-      }
-      
-      
-      static bool
-      add_lock_cb (Match_constPtr lock, void *data)
-      {
-          UndumpWorld *undump = (UndumpWorld *)data;
-      
-          undump->addLock (lock);
-          
-          return true;
-      }
-      
-      
-      void
-      UndumpWorld::load (const char *filename)
-      {
-          if (filename) {
-       extract_packages_from_undump_file (filename, add_channel_cb, add_resItem_cb, add_lock_cb, (void *)this);
-          }
-      }
-      
-      
-      void
-      UndumpWorld::setSubscription (Channel_constPtr channel, bool subscribe)
-      {
-         _XXX("RC_SPEW") << "UndumpWorld::setSubscription (" << channel->asString() << " , " <<  (subscribe?"subscribe":"unsubscribe")
+  
+using namespace std;
+
+IMPL_PTR_TYPE(UndumpWorld);
+
+//---------------------------------------------------------------------------
+
+string
+UndumpWorld::asString ( void ) const
+{
+    return toString (*this);
+}
+
+
+string
+UndumpWorld::toString ( const UndumpWorld & world )
+{
+    return "<undumpworld/>";
+}
+
+
+ostream &
+UndumpWorld::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
+
+
+ostream&
+operator<<( ostream& os, const UndumpWorld & world)
+{
+    return os << world.asString();
+}
+
+//---------------------------------------------------------------------------
+
+UndumpWorld::UndumpWorld (const std::string & filename)
+    : StoreWorld (UNDUMP_WORLD)
+{
+    load (filename);
+}
+
+
+UndumpWorld::~UndumpWorld()
+{
+    fprintf (stderr, "*** deleting undump world[%p]: %s\n", this, World::toString(type()).c_str());
+}
+
+//---------------------------------------------------------------------------
+
+
+static bool
+add_channel_cb (Channel_Ptr channel, bool subscribed, void *data)
+{
+    UndumpWorld *undump = (UndumpWorld *)data;
+
+    undump->addChannel (channel);
+
+    if (!channel->system ()) {
+       undump->setSubscription (channel, subscribed);
+    }
+
+    return true;
+}
+
+
+static bool
+add_resItem_cb (ResItem_constPtr res, void *data)
+{
+    UndumpWorld *undump = (UndumpWorld *)data;
+
+    undump->addResItem (res);
+
+    return true;
+}
+
+
+static bool
+add_lock_cb (Match_constPtr lock, void *data)
+{
+    UndumpWorld *undump = (UndumpWorld *)data;
+
+    undump->addLock (lock);
+    
+    return true;
+}
+
+
+void
+UndumpWorld::load (const string & filename)
+{
+    if (!filename.empty()) {
+       extract_packages_from_undump_file (filename, add_channel_cb, add_resItem_cb, add_lock_cb, (void *)this);
+    }
+}
+
+
+void
+UndumpWorld::setSubscription (Channel_constPtr channel, bool subscribe)
+{
+    _XXX("RC_SPEW") << "UndumpWorld::setSubscription (" << channel->asString() << " , " <<  (subscribe?"subscribe":"unsubscribe")
                          << ")" << endl;
-          for (ChannelSubscriptions::iterator i = _subscriptions.begin(); i != _subscriptions.end(); i++) {
-       if (*i == channel) {
-           if (!subscribe) {
-               _subscriptions.erase (i);
-           }
-           return;
-       }
-          }
-      
-          if (subscribe) {
-       _subscriptions.push_back (channel);
-          }
-      
-          return;
-      }
-      
-      
-      bool
-      UndumpWorld::isSubscribed (Channel_constPtr channel) const
-      {
-          for (ChannelSubscriptions::const_iterator i = _subscriptions.begin(); i != _subscriptions.end(); i++) {
-       if (*i == channel) {
-           _DBG("RC_SPEW") << "UndumpWorld::isSubscribed (" << channel->asString() <<") YES" << endl;
-           return true;
-       }
-          }
-      
-          _DBG("RC_SPEW") << "UndumpWorld::isSubscribed (" << channel->asString() << ") NO" << endl;
-          return false;
-      }
-      
-      ///////////////////////////////////////////////////////////////////
+    for (ChannelSubscriptions::iterator i = _subscriptions.begin(); i != _subscriptions.end(); i++) {
+       if (*i == channel) {
+           if (!subscribe) {
+               _subscriptions.erase (i);
+           }
+           return;
+       }
+    }
+
+    if (subscribe) {
+       _subscriptions.push_back (channel);
+    }
+
+    return;
+}
+
+
+bool
+UndumpWorld::isSubscribed (Channel_constPtr channel) const
+{
+    for (ChannelSubscriptions::const_iterator i = _subscriptions.begin(); i != _subscriptions.end(); i++) {
+       if (*i == channel) {
+           _DBG("RC_SPEW") << "UndumpWorld::isSubscribed (" << channel->asString() <<") YES" << endl;
+           return true;
+       }
+    }
+
+    _DBG("RC_SPEW") << "UndumpWorld::isSubscribed (" << channel->asString() << ") NO" << endl;
+    return false;
+}
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 50ee261..827d447 100644 (file)
@@ -39,44 +39,44 @@ namespace zypp
     /////////////////////////////////////////////////////////////////////
     namespace detail
     { ///////////////////////////////////////////////////////////////////
-              
-      ///////////////////////////////////////////////////////////////////
-      //
-      //       CLASS NAME : UndumpWorld
-      
-      class UndumpWorld : public StoreWorld {
-          
-      
-        private:
-      
-          typedef std::list<Channel_constPtr> ChannelSubscriptions;
-          ChannelSubscriptions _subscriptions;
-      
-        public:
-      
-          UndumpWorld (const char *filename);
-          virtual ~UndumpWorld();
-      
-          // ---------------------------------- I/O
-      
-          static std::string toString (const UndumpWorld & section);
-      
-          virtual std::ostream & dumpOn(std::ostream & str ) const;
-      
-          friend std::ostream& operator<<(std::ostream&, const UndumpWorld & section);
-      
-          std::string asString (void ) const;
-      
-          // ---------------------------------- accessors
-      
-          // ---------------------------------- methods
-      
-          void load (const char *filename);
-          virtual bool isSubscribed (Channel_constPtr channel) const;
-          virtual void setSubscription (Channel_constPtr channel, bool is_subscribed);
-      
-      };
-      ///////////////////////////////////////////////////////////////////
+        
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : UndumpWorld
+
+class UndumpWorld : public StoreWorld {
+    
+
+  private:
+
+    typedef std::list<Channel_constPtr> ChannelSubscriptions;
+    ChannelSubscriptions _subscriptions;
+
+  public:
+
+    UndumpWorld (const std::string & filename);
+    virtual ~UndumpWorld();
+
+    // ---------------------------------- I/O
+
+    static std::string toString (const UndumpWorld & section);
+
+    virtual std::ostream & dumpOn(std::ostream & str ) const;
+
+    friend std::ostream& operator<<(std::ostream&, const UndumpWorld & section);
+
+    std::string asString (void ) const;
+
+    // ---------------------------------- accessors
+
+    // ---------------------------------- methods
+
+    void load (const std::string & filename);
+    virtual bool isSubscribed (Channel_constPtr channel) const;
+    virtual void setSubscription (Channel_constPtr channel, bool is_subscribed);
+
+};
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 4d01b62..8722011 100644 (file)
@@ -35,538 +35,538 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
-
-      IMPL_PTR_TYPE(World);
-
-      World_Ptr World::GlobalWorld = NULL;
-
-      void World::setGlobalWorld( MultiWorld_Ptr world )
-      {
-        GlobalWorld = world;
-      }
-
-      MultiWorld_Ptr World::globalWorld()
-      {
-        return dynamic_pointer_cast<MultiWorld>(GlobalWorld);
-      }
-
-      //---------------------------------------------------------------------------
-
-      string
-      World::toString (WorldType type)
-      {
-          switch (type) {
-       case PLAIN_WORLD:       return "plain";
-       case STORE_WORLD:       return "store";
-       case MULTI_WORLD:       return "multi";
-       case SERVICE_WORLD:     return "service";
-       case UNDUMP_WORLD:      return "undump";
-       case LOCALDIR_WORLD:    return "localdir";
-       case SYSTEM_WORLD:      return "system";
-       default:
-               break;
-          }
-          return "???";
-      }
-
-
-      string
-      World::asString ( void ) const
-      {
-          return toString (*this);
-      }
-
-
-      string
-      World::toString ( const World & world )
-      {
-          return "<world/>";
-      }
-
-
-      ostream &
-      World::dumpOn( ostream & str ) const
-      {
-          str << asString();
-          return str;
-      }
-
-
-      ostream&
-      operator<<( ostream& os, const World & world)
-      {
-          return os << world.asString();
-      }
-
-      //---------------------------------------------------------------------------
-
-      World::World (WorldType type)
-          : _type (type)
-      {
-      //    fprintf (stderr, "*** creating world[%p]: %s\n", this, toString(_type).c_str());
-      }
-
-
-      World::~World()
-      {
-      //    fprintf (stderr, "*** deleting world[%p]: %s\n", this, toString(_type).c_str());
-      }
-
-      //---------------------------------------------------------------------------
-      // sync/refresh functions
-
-      bool
-      World::sync (void) const
-      {
-        if (getenv("FIXME"))     fprintf (stderr, "World::sync() not implemented\n");
-        return false;
-      }
-
-      bool
-      World::syncConditional (Channel_constPtr channel) const
-      {
-        if (getenv("FIXME"))    fprintf (stderr, "World::syncConditional() not implemented\n");
-        return false;
-      }
-
-
-      Pending_Ptr
-      World::refresh (void)
-      {
-        if (getenv("FIXME"))     fprintf (stderr, "World::refresh() not implemented\n");
-        return 0;
-      }
-
-      bool
-      World::hasRefresh (void)
-      {
-        if (getenv("FIXME"))     fprintf (stderr, "World::hasRefresh() not implemented\n");
-        return false;
-      }
-
-
-      bool
-      World::isRefreshing (void)
-      {
-        if (getenv("FIXME"))     fprintf (stderr, "World::isRefreshing() not implemented\n");
-        return false;
-      }
-
-
-       /* These functions are for World-implementers only!  Don't call them! */
-      void
-      World::refreshBegin (void)
-      {
-        if (getenv("FIXME"))     fprintf (stderr, "World::refreshBegin() not implemented\n");
-        return;
-      }
-
-      void
-      World::refreshComplete (void)
-      {
-        if (getenv("FIXME"))     fprintf (stderr, "World::refreshComplete() not implemented\n");
-        return;
-      }
+using namespace std;
+
+IMPL_PTR_TYPE(World);
+
+World_Ptr World::GlobalWorld = NULL;
+
+void World::setGlobalWorld( MultiWorld_Ptr world )
+{
+  GlobalWorld = world;
+}
+
+MultiWorld_Ptr World::globalWorld()
+{
+  return dynamic_pointer_cast<MultiWorld>(GlobalWorld);
+}
+
+//---------------------------------------------------------------------------
+
+string
+World::toString (WorldType type)
+{
+    switch (type) {
+       case PLAIN_WORLD:       return "plain";
+       case STORE_WORLD:       return "store";
+       case MULTI_WORLD:       return "multi";
+       case SERVICE_WORLD:     return "service";
+       case UNDUMP_WORLD:      return "undump";
+       case LOCALDIR_WORLD:    return "localdir";
+       case SYSTEM_WORLD:      return "system";
+       default:
+               break;
+    }
+    return "???";
+}
+
+
+string
+World::asString ( void ) const
+{
+    return toString (*this);
+}
+
+
+string
+World::toString ( const World & world )
+{
+    return "<world/>";
+}
+
+
+ostream &
+World::dumpOn( ostream & str ) const
+{
+    str << asString();
+    return str;
+}
+
+
+ostream&
+operator<<( ostream& os, const World & world)
+{
+    return os << world.asString();
+}
+
+//---------------------------------------------------------------------------
+
+World::World (WorldType type)
+    : _type (type)
+{
+//    fprintf (stderr, "*** creating world[%p]: %s\n", this, toString(_type).c_str());
+}
+
+
+World::~World()
+{
+//    fprintf (stderr, "*** deleting world[%p]: %s\n", this, toString(_type).c_str());
+}
+
+//---------------------------------------------------------------------------
+// sync/refresh functions
+
+bool
+World::sync (void) const
+{
+  if (getenv("FIXME"))     fprintf (stderr, "World::sync() not implemented\n");
+  return false;
+}
+
+bool
+World::syncConditional (Channel_constPtr channel) const
+{
+  if (getenv("FIXME"))    fprintf (stderr, "World::syncConditional() not implemented\n");
+  return false;
+}
+
+
+Pending_Ptr
+World::refresh (void)
+{
+  if (getenv("FIXME"))     fprintf (stderr, "World::refresh() not implemented\n");
+  return 0;
+}
+
+bool
+World::hasRefresh (void)
+{
+  if (getenv("FIXME"))     fprintf (stderr, "World::hasRefresh() not implemented\n");
+  return false;
+}
+
+
+bool
+World::isRefreshing (void)
+{
+  if (getenv("FIXME"))     fprintf (stderr, "World::isRefreshing() not implemented\n");
+  return false;
+}
+
+
+       /* These functions are for World-implementers only!  Don't call them! */
+void
+World::refreshBegin (void)
+{
+  if (getenv("FIXME"))     fprintf (stderr, "World::refreshBegin() not implemented\n");
+  return;
+}
+
+void
+World::refreshComplete (void)
+{
+  if (getenv("FIXME"))     fprintf (stderr, "World::refreshComplete() not implemented\n");
+  return;
+}
 
-      //---------------------------------------------------------------------------
-      // channels, subscriptions
-
-      void
-      World::setSubscription (Channel_Ptr channel, bool is_subscribed)
-      {
-          bool curr_subs_status;
+//---------------------------------------------------------------------------
+// channels, subscriptions
+
+void
+World::setSubscription (Channel_Ptr channel, bool is_subscribed)
+{
+    bool curr_subs_status;
 
-          if (channel == NULL) return;
+    if (channel == NULL) return;
 
          _XXX("RC_SPEW") << "World::setSubscription (" << channel->asString() << ", " <<
              (is_subscribed?"subscribe":"unsubscribe") << ")" << endl;
 
-          if (channel->system ()) {
-       fprintf (stderr, "Can't subscribe to system channel '%s'\n",  channel->name ());
-       return;
-          }
+    if (channel->system ()) {
+       fprintf (stderr, "Can't subscribe to system channel '%s'\n",  channel->name ().c_str());
+       return;
+    }
 
-          curr_subs_status = isSubscribed (channel);
+    curr_subs_status = isSubscribed (channel);
 
-          Subscription::setStatus (channel, is_subscribed);
+    Subscription::setStatus (channel, is_subscribed);
 
-          if (curr_subs_status != isSubscribed (channel))
-       touchSubscriptionSequenceNumber ();
+    if (curr_subs_status != isSubscribed (channel))
+       touchSubscriptionSequenceNumber ();
 
-          return;
-      }
+    return;
+}
 
 
-      bool
-      World::isSubscribed (Channel_constPtr channel) const
-      {
-          if (channel == NULL) return false;
+bool
+World::isSubscribed (Channel_constPtr channel) const
+{
+    if (channel == NULL) return false;
          _XXX("RC_SPEW") <<  "World::isSubscribed (" << channel->asString() << ")" << endl;
 
-          if (channel->system ())
-       return false;
+    if (channel->system ())
+       return false;
 
-          return Subscription::status (channel) ? true : false;
-      }
+    return Subscription::status (channel) ? true : false;
+}
 
 
 
-      //---------------------------------------------------------------------------
-      // ResItem Locks
+//---------------------------------------------------------------------------
+// ResItem Locks
 
-      typedef struct {
-          ResItem_constPtr resItem;
-          World_Ptr world;
-          bool is_locked;
-      } IsLockedInfo;
+typedef struct {
+    ResItem_constPtr resItem;
+    World_Ptr world;
+    bool is_locked;
+} IsLockedInfo;
 
 
-      static bool
-      is_locked_cb (Match_constPtr match, void *data)
-      {
-          IsLockedInfo *info = (IsLockedInfo *)data;
+static bool
+is_locked_cb (Match_constPtr match, void *data)
+{
+    IsLockedInfo *info = (IsLockedInfo *)data;
 
-          if (match->test (info->resItem, info->world)) {
-       info->is_locked = true;
-       return false;
-          }
+    if (match->test (info->resItem, info->world)) {
+       info->is_locked = true;
+       return false;
+    }
 
-          return true;
-      }
+    return true;
+}
 
 
-      bool
-      World::resItemIsLocked (ResItem_constPtr resItem)
-      {
-          IsLockedInfo info;
+bool
+World::resItemIsLocked (ResItem_constPtr resItem)
+{
+    IsLockedInfo info;
 
-          info.resItem = resItem;
-          info.world = this;
-          info.is_locked = false;
+    info.resItem = resItem;
+    info.world = this;
+    info.is_locked = false;
 
-          foreachLock (is_locked_cb, &info);
+    foreachLock (is_locked_cb, &info);
 
-          return info.is_locked;
-      }
+    return info.is_locked;
+}
 
 
-      //---------------------------------------------------------------------------
-      // Transacting
+//---------------------------------------------------------------------------
+// Transacting
 
-      bool
-      World::canTransactResItem (ResItem_constPtr resItem)
-      {
-        if (getenv("FIXME"))      fprintf (stderr, "World::canTransactResItem() not implemented\n");
-        return false;
-      }
+bool
+World::canTransactResItem (ResItem_constPtr resItem)
+{
+  if (getenv("FIXME"))      fprintf (stderr, "World::canTransactResItem() not implemented\n");
+  return false;
+}
 
-      bool
-      World::transact (const ResItemList & installResItems, const ResItemList & remove_resItems, int flags)
-      {
-        if (getenv("FIXME"))      fprintf (stderr, "World::transact() not implemented\n");
-        return false;
-      }
+bool
+World::transact (const ResItemList & installResItems, const ResItemList & remove_resItems, int flags)
+{
+  if (getenv("FIXME"))      fprintf (stderr, "World::transact() not implemented\n");
+  return false;
+}
 
 
-      //---------------------------------------------------------------------------
-      // XML serialization
+//---------------------------------------------------------------------------
+// XML serialization
 
-      void
-      World::serialize (XmlNode_Ptr parent)
-      {
-        if (getenv("FIXME"))      fprintf (stderr, "World::serialize() not implemented\n");
-        return;
-      }
+void
+World::serialize (XmlNode_Ptr parent)
+{
+  if (getenv("FIXME"))      fprintf (stderr, "World::serialize() not implemented\n");
+  return;
+}
 
-      void
-      World::toFile (const char *filename)
-      {
-        if (getenv("FIXME"))      fprintf (stderr, "World::toFile() not implemented\n");
-        return;
-      }
+void
+World::toFile (const std::string & filename)
+{
+  if (getenv("FIXME"))      fprintf (stderr, "World::toFile() not implemented\n");
+  return;
+}
 
 
-      //---------------------------------------------------------------------------
-      // Duplicating (primarily for atomic refreshes)
+//---------------------------------------------------------------------------
+// Duplicating (primarily for atomic refreshes)
 
-      World_Ptr
-      World::dup (void)
-      {
-        if (getenv("FIXME"))      fprintf (stderr, "World::dup() not implemented\n");
-        return 0;
-      }
+World_Ptr
+World::dup (void)
+{
+  if (getenv("FIXME"))      fprintf (stderr, "World::dup() not implemented\n");
+  return 0;
+}
 
 
-      //---------------------------------------------------------------------------
-      // only used for bindings
+//---------------------------------------------------------------------------
+// only used for bindings
 
-      void
-      World::setRefreshFunction (WorldRefreshFn refresh_fn)
-      {
-        if (getenv("FIXME"))      fprintf (stderr, "World::setRefreshFunction() not implemented\n");
-        return;
-      }
+void
+World::setRefreshFunction (WorldRefreshFn refresh_fn)
+{
+  if (getenv("FIXME"))      fprintf (stderr, "World::setRefreshFunction() not implemented\n");
+  return;
+}
 
 
 
-      //-----------------------------------------------------------------------------
-      // Upgrades
+//-----------------------------------------------------------------------------
+// Upgrades
 
-      typedef struct  {
-          ResItem_constPtr original_resItem;
-          CResItemFn fn;
-          void *data;
-          int count;
-          World_Ptr world;
-      } ForeachUpgradeInfo;
+typedef struct  {
+    ResItem_constPtr original_resItem;
+    CResItemFn fn;
+    void *data;
+    int count;
+    World_Ptr world;
+} ForeachUpgradeInfo;
 
-      static bool
-      foreach_upgrade_cb (ResItem_constPtr resItem, void *data)
-      {
-          ForeachUpgradeInfo *info = (ForeachUpgradeInfo *)data;
-          int cmp;
+static bool
+foreach_upgrade_cb (ResItem_constPtr resItem, void *data)
+{
+    ForeachUpgradeInfo *info = (ForeachUpgradeInfo *)data;
+    int cmp;
 
-          cmp = ResItem::compare (info->original_resItem, resItem);
+    cmp = ResItem::compare (info->original_resItem, resItem);
 
-          if (cmp >= 0)                                // original is already better
-       return true;
+    if (cmp >= 0)                              // original is already better
+       return true;
 
-          if (info->world->resItemIsLocked (resItem))
-       return true;
+    if (info->world->resItemIsLocked (resItem))
+       return true;
 
-          if (info->fn)
-       info->fn (resItem, info->data);
-          ++info->count;
+    if (info->fn)
+       info->fn (resItem, info->data);
+    ++info->count;
 
-          return true;
-      }
+    return true;
+}
 
 
-      // rc_world_foreach_upgrade:
-      // @world: An #RCWorld.
-      // @resItem: An #RCResItem.
-      // @channel: An #RCChannel or channel wildcard.
-      // @fn: A callback function.
-      // @user_data: Pointer passed to the callback function.
-      //
-      // Searchs @world for all resItems whose channel matches
-      // @channel and that are an upgrade for @resItem.
-      // (To be precise, an upgrade is a resItem with the same
-      // name as @resItem but with a greater version number.)
-      //
-      // Return value: The number of matching resItems
-      // that the callback functions was invoked on, or
-      // -1 in the case of an error.
+// rc_world_foreach_upgrade:
+// @world: An #RCWorld.
+// @resItem: An #RCResItem.
+// @channel: An #RCChannel or channel wildcard.
+// @fn: A callback function.
+// @user_data: Pointer passed to the callback function.
+//
+// Searchs @world for all resItems whose channel matches
+// @channel and that are an upgrade for @resItem.
+// (To be precise, an upgrade is a resItem with the same
+// name as @resItem but with a greater version number.)
+//
+// Return value: The number of matching resItems
+// that the callback functions was invoked on, or
+// -1 in the case of an error.
 
-      int
-      World::foreachUpgrade (ResItem_constPtr resItem, Channel_Ptr channel, CResItemFn fn, void *data)
-      {
-          ForeachUpgradeInfo info;
+int
+World::foreachUpgrade (ResItem_constPtr resItem, Channel_Ptr channel, CResItemFn fn, void *data)
+{
+    ForeachUpgradeInfo info;
 
-          syncConditional (channel);
+    syncConditional (channel);
 
-          info.original_resItem = resItem;
-          info.fn = fn;
-          info.data = data;
-          info.count = 0;
-          info.world = this;
+    info.original_resItem = resItem;
+    info.fn = fn;
+    info.data = data;
+    info.count = 0;
+    info.world = this;
 
-          foreachResItemByName (resItem->name(), channel, foreach_upgrade_cb, (void *)&info);
+    foreachResItemByName (resItem->name(), channel, foreach_upgrade_cb, (void *)&info);
 
-          return info.count;
-      }
+    return info.count;
+}
 
 
 
-      typedef struct {
-          World_Ptr world;
-          ResItem_constPtr system_resItem;
-          CResItemList best_upgrades;
-          bool subscribed_only;
-          ResItemPairFn fn;
-          void *data;
-          int count;
-      } SystemUpgradeInfo;
-
+typedef struct {
+    World_Ptr world;
+    ResItem_constPtr system_resItem;
+    CResItemList best_upgrades;
+    bool subscribed_only;
+    ResItemPairFn fn;
+    void *data;
+    int count;
+} SystemUpgradeInfo;
 
-      static bool
-      foreach_system_upgrade_cb (ResItem_constPtr upgrade, void *data)
-      {
-          SystemUpgradeInfo *info = (SystemUpgradeInfo *)data;
-          Channel_constPtr channel = upgrade->channel();
-          int cmp;
 
-          if (info->subscribed_only) {
-       if (!(channel && channel->isSubscribed ()))
-           return true;
-          }
-
-          if (info->world->resItemIsLocked (upgrade))
-       return true;
+static bool
+foreach_system_upgrade_cb (ResItem_constPtr upgrade, void *data)
+{
+    SystemUpgradeInfo *info = (SystemUpgradeInfo *)data;
+    Channel_constPtr channel = upgrade->channel();
+    int cmp;
 
-          if (info->best_upgrades.empty()) {
-       info->best_upgrades.push_back (upgrade);
-          }
-          else {
-       /* All the versions are equal, so picking the first is fine */
-       ResItem_constPtr best_up = info->best_upgrades.front();
-
-       cmp = ResItem::compare (best_up, upgrade);
-
-       if (cmp <= 0) {
-           /* We have a new best resItem... */
-           info->best_upgrades.pop_front();
-           info->best_upgrades.push_back (upgrade);
-       }
-          }
-
-          return true;
-      }
+    if (info->subscribed_only) {
+       if (!(channel && channel->isSubscribed ()))
+           return true;
+    }
 
+    if (info->world->resItemIsLocked (upgrade))
+       return true;
 
-      static void
-      foreach_system_resItem_cb (const string & name, ResItem_constPtr resItem, SystemUpgradeInfo *info)
-      {
-          info->system_resItem = resItem;
-          info->best_upgrades.clear();
+    if (info->best_upgrades.empty()) {
+       info->best_upgrades.push_back (upgrade);
+    }
+    else {
+       /* All the versions are equal, so picking the first is fine */
+       ResItem_constPtr best_up = info->best_upgrades.front();
 
-          /* If the resItem is excluded, skip it. */
-          if (info->world->resItemIsLocked (info->system_resItem))
-       return;
-
-          info->world->foreachUpgrade (info->system_resItem, new Channel (CHANNEL_TYPE_NONSYSTEM), foreach_system_upgrade_cb, info);
-
-          for (CResItemList::const_iterator iter = info->best_upgrades.begin(); iter != info->best_upgrades.end(); iter++) {
-       ResItem_constPtr upgrade = *iter;
-
-       if (info->fn)
-           info->fn (info->system_resItem, upgrade, info->data);
-
-       ++info->count;
-          }
-
-          info->best_upgrades.clear();
-      }
+       cmp = ResItem::compare (best_up, upgrade);
 
-      typedef map<const string,ResItem_constPtr> UniqueTable;
+       if (cmp <= 0) {
+           /* We have a new best resItem... */
+           info->best_upgrades.pop_front();
+           info->best_upgrades.push_back (upgrade);
+       }
+    }
 
-      static bool
-      build_unique_table_cb (ResItem_constPtr resItem, void *data)
-      {
-          UniqueTable *unique_table = (UniqueTable *)data;
+    return true;
+}
 
-          UniqueTable::const_iterator pos = unique_table->find (resItem->name());
 
-          if (pos != unique_table->end()) {
-       if (ResItem::compare (resItem, pos->second) <= 0)
-           return true;
-          }
+static void
+foreach_system_resItem_cb (const string & name, ResItem_constPtr resItem, SystemUpgradeInfo *info)
+{
+    info->system_resItem = resItem;
+    info->best_upgrades.clear();
 
-          (*unique_table)[resItem->name()] = resItem;
+    /* If the resItem is excluded, skip it. */
+    if (info->world->resItemIsLocked (info->system_resItem))
+       return;
 
-          return true;
-      }
+    info->world->foreachUpgrade (info->system_resItem, new Channel (CHANNEL_TYPE_NONSYSTEM), foreach_system_upgrade_cb, info);
 
+    for (CResItemList::const_iterator iter = info->best_upgrades.begin(); iter != info->best_upgrades.end(); iter++) {
+       ResItem_constPtr upgrade = *iter;
 
-      /**
-       * foreachSystemUpgrade:
-       * @world: An #RCWorld.
-       * @subscribed_only: if TRUE, only subscribed channels are used.
-       * @fn: A callback function.
-       * @user_data: Pointer to be passed to the callback function.
-       *
-       * Iterates across all system resItems in @world for which there
-       * exists an upgrade, and passes both the original resItem and
-       * the upgrade resItem to the callback function.
-       *
-       * Return value: The number of matching resItems that the callback
-       * function was invoked on, or -1 in case of an error.
-       **/
-
-      int
-      World::foreachSystemUpgrade (bool subscribed_only, ResItemPairFn fn, void *data)
-      {
-          SystemUpgradeInfo info;
-          UniqueTable unique_table;
+       if (info->fn)
+           info->fn (info->system_resItem, upgrade, info->data);
 
-          /* rc_world_foreach_resItem calls rc_world_sync */
-
-          foreachResItem (new Channel (CHANNEL_TYPE_SYSTEM), build_unique_table_cb, &unique_table);
+       ++info->count;
+    }
 
-          info.world = this;
-          info.subscribed_only = subscribed_only;
-          info.fn = fn;
-          info.data = data;
-          info.count = 0;
+    info->best_upgrades.clear();
+}
 
-          for (UniqueTable::const_iterator iter = unique_table.begin(); iter != unique_table.end(); iter++) {
-       foreach_system_resItem_cb (iter->first, iter->second, &info);
-          }
+typedef map<const string,ResItem_constPtr> UniqueTable;
 
-          return info.count;
-      }
+static bool
+build_unique_table_cb (ResItem_constPtr resItem, void *data)
+{
+    UniqueTable *unique_table = (UniqueTable *)data;
 
+    UniqueTable::const_iterator pos = unique_table->find (resItem->name());
 
-      PackageUpdateList
-      World::getUpgrades (ResItem_constPtr resItem, Channel_constPtr channel)
-      {
-          fprintf (stderr, "World::getUpgrades not implemented\n");
-        return PackageUpdateList();
-      }
+    if (pos != unique_table->end()) {
+       if (ResItem::compare (resItem, pos->second) <= 0)
+           return true;
+    }
 
-      ResItem_constPtr
-      World::getBestUpgrade (ResItem_constPtr resItem, bool subscribed_only)
-      {
-          fprintf (stderr, "World::getBestUpgrade not implemented\n");
-        return 0;
-      }
+    (*unique_table)[resItem->name()] = resItem;
 
+    return true;
+}
 
-      //-----------------------------------------------------------------------------
-      // Locks
 
-      int
-      World::foreachLock (MatchFn fn, void *data) const
-      {
-          int count = 0;
+/**
+ * foreachSystemUpgrade:
+ * @world: An #RCWorld.
+ * @subscribed_only: if TRUE, only subscribed channels are used.
+ * @fn: A callback function.
+ * @user_data: Pointer to be passed to the callback function.
+ *
+ * Iterates across all system resItems in @world for which there
+ * exists an upgrade, and passes both the original resItem and
+ * the upgrade resItem to the callback function.
+ *
+ * Return value: The number of matching resItems that the callback
+ * function was invoked on, or -1 in case of an error.
+ **/
+
+int
+World::foreachSystemUpgrade (bool subscribed_only, ResItemPairFn fn, void *data)
+{
+    SystemUpgradeInfo info;
+    UniqueTable unique_table;
+
+    /* rc_world_foreach_resItem calls rc_world_sync */
+
+    foreachResItem (new Channel (CHANNEL_TYPE_SYSTEM), build_unique_table_cb, &unique_table);
+
+    info.world = this;
+    info.subscribed_only = subscribed_only;
+    info.fn = fn;
+    info.data = data;
+    info.count = 0;
+
+    for (UniqueTable::const_iterator iter = unique_table.begin(); iter != unique_table.end(); iter++) {
+       foreach_system_resItem_cb (iter->first, iter->second, &info);
+    }
+
+    return info.count;
+}
+
+
+PackageUpdateList
+World::getUpgrades (ResItem_constPtr resItem, Channel_constPtr channel)
+{
+    fprintf (stderr, "World::getUpgrades not implemented\n");
+  return PackageUpdateList();
+}
+
+ResItem_constPtr
+World::getBestUpgrade (ResItem_constPtr resItem, bool subscribed_only)
+{
+    fprintf (stderr, "World::getBestUpgrade not implemented\n");
+  return 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// Locks
+
+int
+World::foreachLock (MatchFn fn, void *data) const
+{
+    int count = 0;
+
+    for (MatchList::const_iterator iter = _locks.begin(); iter != _locks.end(); iter++) {
+        if (! fn (*iter, data))
+            return -1;
+        ++count;
+    }
+
+    return count;
+}
+
+
+void
+World::addLock (Match_constPtr lock)
+{
+    _locks.push_back (lock);
+}
+
 
-          for (MatchList::const_iterator iter = _locks.begin(); iter != _locks.end(); iter++) {
-              if (! fn (*iter, data))
-                  return -1;
-              ++count;
-          }
+void
+World::removeLock (Match_constPtr lock)
+{
+    for (MatchList::iterator iter = _locks.begin(); iter != _locks.end(); iter++) {
+       if (*iter == lock) {
+           _locks.erase (iter);
+           break;
+       }
+    }
+}
 
-          return count;
-      }
 
+void
+World::clearLocks (void)
+{
+    _locks.clear();
+}
 
-      void
-      World::addLock (Match_constPtr lock)
-      {
-          _locks.push_back (lock);
-      }
-
-
-      void
-      World::removeLock (Match_constPtr lock)
-      {
-          for (MatchList::iterator iter = _locks.begin(); iter != _locks.end(); iter++) {
-       if (*iter == lock) {
-           _locks.erase (iter);
-           break;
-       }
-          }
-      }
-
-
-      void
-      World::clearLocks (void)
-      {
-          _locks.clear();
-      }
-
-      ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 2dc444b..0aafbc9 100644 (file)
@@ -194,9 +194,9 @@ namespace zypp
           virtual ChannelList channels () const = 0;
           virtual bool containsChannel (Channel_constPtr channel) const = 0;
 
-          virtual Channel_Ptr getChannelByName (const char *channel_name) const = 0;
-          virtual Channel_Ptr getChannelByAlias (const char *alias) const = 0;
-          virtual Channel_Ptr getChannelById (const char *channel_id) const = 0;
+          virtual Channel_Ptr getChannelByName (const std::string & channel_name) const = 0;
+          virtual Channel_Ptr getChannelByAlias (const std::string & alias) const = 0;
+          virtual Channel_Ptr getChannelById (const std::string & channel_id) const = 0;
 
           // ResItem Locks
 
@@ -211,8 +211,8 @@ namespace zypp
           // Single resItem queries
 
           virtual ResItem_constPtr findInstalledResItem (ResItem_constPtr resItem) = 0;
-          virtual ResItem_constPtr findResItem (Channel_constPtr channel, const char *name) const = 0;
-          virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const char *name, const Capability &  constraint, bool is_and) const = 0;
+          virtual ResItem_constPtr findResItem (Channel_constPtr channel, const std::string & name) const = 0;
+          virtual ResItem_constPtr findResItemWithConstraint (Channel_constPtr channel, const std::string & name, const Capability &  constraint, bool is_and) const = 0;
           virtual Channel_Ptr guessResItemChannel (ResItem_constPtr resItem) const = 0;
 
           // Iterate across resItems
@@ -246,7 +246,7 @@ namespace zypp
           // XML serialization
 
           void serialize (XmlNode_Ptr parent);
-          void toFile (const char *filename);
+          void toFile (const std::string & filename);
 
           // Duplicating (primarily for atomic refreshes)
           World_Ptr dup (void);
index 9a7134a..bb9ce0a 100644 (file)
@@ -47,8 +47,8 @@ XmlNode::XmlNode (const xmlNodePtr node)
 {
 }
 
-XmlNode::XmlNode (const char *name)
-    : _node(xmlNewNode (NULL, (const xmlChar *)name))
+XmlNode::XmlNode (const string & name)
+    : _node(xmlNewNode (NULL, (const xmlChar *)name.c_str()))
 {
 }
 
@@ -88,18 +88,18 @@ operator<<( ostream& os, const XmlNode& node)
 
 //---------------------------------------------------------------------------
 
-const char *
-XmlNode::getValue (const char *name, const char *deflt) const
+string 
+XmlNode::getValue (const string & name, const string & deflt) const
 {
-    char *ret;
+    string ret;
     xmlChar *xml_s;
     xmlNode *child;
 
-    xml_s = xmlGetProp(_node, (const xmlChar *)name);
+    xml_s = xmlGetProp(_node, (const xmlChar *)name.c_str());
          _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") xmlGetProp '" << (char *)xml_s << "'" << endl;
 
     if (xml_s) {
-       ret = strdup ((const char *)xml_s);
+       ret = string ((const char *)xml_s);
        xmlFree (xml_s);
        return ret;
     }
@@ -107,14 +107,12 @@ XmlNode::getValue (const char *name, const char *deflt) const
     child = _node->xmlChildrenNode;
 
     while (child) {
-             _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") child '" << (const char *)(child->name) << "'" 
-                                 << endl;
-       if (strcasecmp((const char *)(child->name), name) == 0) {
+             _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") child '" << (child->name) << "'" << endl;
+       if (strcasecmp((const char *)(child->name), name.c_str()) == 0) {
            xml_s = xmlNodeGetContent(child);
-           _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") xmlNodeGetContent '" << (char *)xml_s << "'"
-                               << endl;
+           _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") xmlNodeGetContent '" << (char *)xml_s << "'" << endl;
            if (xml_s) {
-               ret = strdup ((const char *)xml_s);
+               ret = string ((const char *)xml_s);
                xmlFree (xml_s);
                return ret;
            }
@@ -122,22 +120,34 @@ XmlNode::getValue (const char *name, const char *deflt) const
        child = child->next;
     }
 
-         _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") NULL" << endl;
+    _XXX("RC_SPEW_XML") << "XmlNode::getValue(" << name << ") deflt" << endl;
     return deflt;
 }
 
 
-const char *
-XmlNode::getProp (const char *name, const char *deflt) const
+bool
+XmlNode::hasProp (const std::string & name) const
+{
+    xmlChar *ret;
+
+    ret = xmlGetProp (_node, (const xmlChar *)name.c_str());
+    if (ret) {
+       return true;
+    }
+    return false;
+}
+
+
+string
+XmlNode::getProp (const std::string & name, const std::string & deflt) const
 {
     xmlChar *ret;
-    char *gs;
+    string gs;
 
-    ret = xmlGetProp (_node, (const xmlChar *)name);
-         _XXX("RC_SPEW_XML") << "XmlNode::getProp(" << name << ") xmlGetProp '" << (char *)ret << "'"
-                             << endl;
+    ret = xmlGetProp (_node, (const xmlChar *)name.c_str());
+         _XXX("RC_SPEW_XML") << "XmlNode::getProp(" << name << ") xmlGetProp '" << (char *)ret << "'" << endl;
     if (ret) {
-       gs = strdup ((const char *)ret);
+       gs = string ((const char  *)ret);
        xmlFree (ret);
        return gs;
     }
@@ -146,31 +156,29 @@ XmlNode::getProp (const char *name, const char *deflt) const
 
 
 bool
-XmlNode::getIntValue (const char *name, int *value) const
+XmlNode::getIntValue (const std::string & name, int *value) const
 {
-    const char *strval;
+    string strval;
     char *ret;
-    int z;
+    long z;
 
     strval = this->getValue (name, NULL);
-    if (!strval) {
+    if (strval.empty()) {
        return false;
     }
 
-    z = strtol (strval, &ret, 10);
+    z = strtol (strval.c_str(), &ret, 10);
     if (*ret != '\0') {
-       free ((void *)strval);
        return false;
     }
 
-    free ((void *)strval);
     *value = z;
     return true;
 }
 
 
 int
-XmlNode::getIntValueDefault (const char *name, int def) const
+XmlNode::getIntValueDefault (const std::string & name, int def) const
 {
     int z;
     if (this->getIntValue (name, &z))
@@ -181,7 +189,7 @@ XmlNode::getIntValueDefault (const char *name, int def) const
 
               
 unsigned int
-XmlNode::getUnsignedIntValueDefault (const char *name, unsigned int def) const
+XmlNode::getUnsignedIntValueDefault (const std::string & name, unsigned int def) const
 {
     unsigned int z;
     if (this->getUnsignedIntValue (name, &z))
@@ -192,56 +200,53 @@ XmlNode::getUnsignedIntValueDefault (const char *name, unsigned int def) const
 
 
 bool
-XmlNode::getUnsignedIntValue (const char *name, unsigned int *value) const
+XmlNode::getUnsignedIntValue (const std::string & name, unsigned int *value) const
 {
-    const char *strval;
+    string strval;
     char *ret;
     int z;
 
     strval = this->getValue (name, NULL);
-    if (!strval) {
+    if (strval.empty()) {
        return false;
     }
 
-    z = strtoul (strval, &ret, 10);
+    z = strtoul (strval.c_str(), &ret, 10);
     if (*ret != '\0') {
-       free ((void *)strval);
        return false;
     }
 
-    free ((void *)strval);
     *value = z;
     return true;
 }
 
 
 unsigned int
-XmlNode::getUnsignedIntPropDefault (const char *name, unsigned int def) const
+XmlNode::getUnsignedIntPropDefault (const std::string & name, unsigned int def) const
 {
     xmlChar *buf;
     unsigned int ret;
 
-    buf = xmlGetProp (_node, (const xmlChar *)name);
+    buf = xmlGetProp (_node, (const xmlChar *)name.c_str());
 
     if (buf) {
        ret = strtol ((const char *)buf, NULL, 10);
        xmlFree (buf);
        return (ret);
-    } else {
-       return (def);
     }
+    return (def);
 }
 
 
-const char *
+string
 XmlNode::getContent (void) const
 {
     xmlChar *buf;
-    char *ret;
+    string ret;
 
     buf = xmlNodeGetContent (_node);
 
-    ret = strdup ((const char *)buf);
+    ret = string ((const char *)buf);
 
     xmlFree (buf);
 
@@ -261,19 +266,18 @@ XmlNode::getUnsignedIntContentDefault (unsigned int def) const
        ret = strtol ((const char *)buf, NULL, 10);
        xmlFree (buf);
        return (ret);
-    } else {
-       return (def);
     }
+    return (def);
 }
 
 
 const XmlNode_Ptr
-XmlNode::getNode (const char *name) const
+XmlNode::getNode (const std::string & name) const
 {
     xmlNodePtr iter;
 
     for (iter = _node->xmlChildrenNode; iter; iter = iter->next) {
-       if (strcasecmp ((const char *)(iter->name), name) == 0) {
+       if (strcasecmp ((const char *)(iter->name), name.c_str()) == 0) {
            return new XmlNode (iter);
        }
     }
@@ -286,9 +290,9 @@ XmlNode::getNode (const char *name) const
 
 
 void
-XmlNode::addTextChild (const char *name, const char *content)
+XmlNode::addTextChild (const std::string & name, const std::string & content)
 {
-    xmlNewTextChild (_node, NULL, (const xmlChar *)name, (const xmlChar *)content);
+    xmlNewTextChild (_node, NULL, (const xmlChar *)name.c_str(), (const xmlChar *)content.c_str());
 }
 
 ///////////////////////////////////////////////////////////////////
index 3681b83..baa912b 100644 (file)
@@ -51,14 +51,13 @@ namespace zypp
 
 class XmlNode : public base::ReferenceCounted, private base::NonCopyable
 {
-    
 
   private:
     const xmlNodePtr _node;
 
   public:
     XmlNode (const xmlNodePtr node);
-    XmlNode (const char *name);
+    XmlNode (const std::string & name);
     virtual ~XmlNode ();
 
     // ---------------------------------- I/O
@@ -73,7 +72,7 @@ class XmlNode : public base::ReferenceCounted, private base::NonCopyable
 
     // ---------------------------------- accessors
 
-    const char *name() const { return ((const char *)(_node->name)); }
+    const std::string name() const { return (std::string((const char *)_node->name)); }
     xmlNodePtr node() const { return (_node); }
     XmlNode_Ptr next() const { return (_node->next == NULL ? NULL : new XmlNode (_node->next)); }
     XmlNode_Ptr children() const { return (_node->xmlChildrenNode == NULL ? NULL : new XmlNode (_node->xmlChildrenNode)); }
@@ -81,31 +80,30 @@ class XmlNode : public base::ReferenceCounted, private base::NonCopyable
 
     // ---------------------------------- methods
 
-    const char *getProp (const char *name, const char *deflt = "") const;
-    const char *getValue (const char *name, const char *deflt = "") const;
-    const char *getContent (void) const;
+    bool hasProp (const std::string & name) const;
+    std::string getProp (const std::string & name, const std::string & deflt = "") const;
+    std::string getValue (const std::string & name, const std::string & deflt = "") const;
+    std::string getContent (void) const;
 
-    bool equals (const char *n) const { return (strcasecmp (name(), n) == 0); }
+    bool equals (const std::string & n) const { return (strcasecmp (name().c_str(), n.c_str()) == 0); }
     bool isElement (void) const { return (type() == XML_ELEMENT_NODE); }
 
-    bool match (const char *str) const { return (! strcasecmp ((const char *)(_node->name), str)); }
-
-    const XmlNode_Ptr getNode (const char *name) const;
+    const XmlNode_Ptr getNode (const std::string & name) const;
 
     // The former will get either a property or a tag, whereas the latter will
     //   get only a property
 
-    bool getIntValue (const char *name, int *value) const;
-    int getIntValueDefault (const char *name, int def) const;
+    bool getIntValue (const std::string & name, int *value) const;
+    int getIntValueDefault (const std::string & name, int def) const;
 
-    bool getUnsignedIntValue (const char *name, unsigned int *value) const;
-    unsigned int getUnsignedIntValueDefault (const char *name, unsigned int def) const;
+    bool getUnsignedIntValue (const std::string & name, unsigned int *value) const;
+    unsigned int getUnsignedIntValueDefault (const std::string & name, unsigned int def) const;
 
-    unsigned int getUnsignedIntPropDefault (const char *name, unsigned int def) const;
+    unsigned int getUnsignedIntPropDefault (const std::string & name, unsigned int def) const;
 
     unsigned int getUnsignedIntContentDefault (unsigned int def) const;
 
-    void addTextChild (const char *name, const char *content);
+    void addTextChild (const std::string & name, const std::string & content);
 };
 
       ///////////////////////////////////////////////////////////////////
index 9262c00..d2fa154 100644 (file)
@@ -681,7 +681,7 @@ XmlParser::updateEnd(const char *name)
     _XXX("RC_SPEW_XML") << "XmlParser::updateEnd(" << name << ")" << endl;
 
     Channel_constPtr channel;
-    const char *url_prefix = NULL;
+    string url_prefix;
 
     assert(_current_update != NULL);
 
@@ -701,7 +701,7 @@ XmlParser::updateEnd(const char *name)
     } else if (!strcmp(name, "arch")) {                        _current_update->setArch (strstrip (_text_buffer));
     } else if (!strcmp(name, "filename")) {
         strstrip (_text_buffer);
-        if (url_prefix) {
+        if (!url_prefix.empty()) {
             _current_update->setPackageUrl (maybe_merge_paths(url_prefix, _text_buffer));
         }
         else {
@@ -711,7 +711,7 @@ XmlParser::updateEnd(const char *name)
     } else if (!strcmp(name, "installedsize")) {       _current_update->setInstalledSize (atoi (_text_buffer));
     } else if (!strcmp(name, "signaturename")) {
         strstrip (_text_buffer);
-        if (url_prefix) {
+        if (!url_prefix.empty()) {
             _current_update->setSignatureUrl (maybe_merge_paths(url_prefix, _text_buffer));
         }
         else {
@@ -719,7 +719,7 @@ XmlParser::updateEnd(const char *name)
         }
     } else if (!strcmp(name, "signaturesize")) {       _current_update->setSignatureSize (atoi (_text_buffer));
     } else if (!strcmp(name, "md5sum")) {              _current_update->setMd5sum (strstrip (_text_buffer));
-    } else if (!strcmp(name, "importance")) {          _current_update->setImportance (new Importance (strstrip (_text_buffer)));
+    } else if (!strcmp(name, "importance")) {          _current_update->setImportance (Importance::parse (strstrip (_text_buffer)));
     } else if (!strcmp(name, "description")) {         _current_update->setDescription (strstrip (_text_buffer));
     } else if (!strcmp(name, "hid")) {                 _current_update->setHid (atoi(_text_buffer));
     } else if (!strcmp (name, "license")) {            _current_update->setLicense (strstrip (_text_buffer));
index c1af5e8..a5f271e 100644 (file)
@@ -52,640 +52,639 @@ namespace zypp
     namespace detail
     { ///////////////////////////////////////////////////////////////////
 
-      using namespace std;
-      
-      //---------------------------------------------------------------------------
-      // string stuff
-      
-      /* Like g_strstrip(), only returns NULL on an empty string */
-      char *
-      strstrip (const char *str)
-      {
-          const char *start;
-          const char *end;
-      
-          if (str == NULL)
-       return "";
-      
-          start = str;
-          while (isblank (*start)) {
-       start++;
-          }
-      
-          end = start + strlen (start) - 1;
-          while (end > start
-          && isblank (*end)) {
-       end--;
-          }
-      
-          if (start > end) {                   // empty string
-       return NULL;
-          }
-      
-          if (start > str
-       || *(end+1) != 0) {             // we stripped at least one blank somewhere
-       return strndup (start, end - start + 1);
-          }
-          return strdup (str);         // no blanks stripped
-      }
-      
-      
-      //---------------------------------------------------------------------------
-      // url and path stuff
-      
-      char *
-      maybe_merge_paths(const char *parent_path, const char *child_path)
-      {
-          /* Child path is NULL, so we return a dup of the parent path.
-             Ex: maybe_merge_paths("/foo", NULL) => "/foo" */
-          if (!child_path)
-       return strdup(parent_path);
-      
-          /* Child path is a fully qualified URL, so we return a dup of it.
-             Ex: maybe_merge_paths("/foo", "http://www.ximian.com") =>
-             "http://www.ximian.com"
-      
-             OR
-      
-             Child path is an absolute path, so we just return a dup of it.
-             Ex: maybe_merge_paths("/foo", "/bar/baz") => "/bar/baz" */
-      
-          if (url_is_absolute(child_path) || child_path[0] == '/')
-       return strdup(child_path);
-      
-          /* Child path is a relative path, so we tack child path onto the end of
-             parent path.
-             Ex: maybe_merge_paths("/foo", "bar/baz") => "/foo/bar/baz" */
-      
-          char *s = (char *)malloc (strlen (parent_path) + strlen (child_path) + 1 + 1);       // +1 for /, +1 for \0
-          strcpy (s, parent_path);
-      
-          if (parent_path[strlen(parent_path) - 1] != '/')
-       strcat (s, "/");
-          
-          strcat (s, child_path);
-      
-          return s;
-      }
-      
-      
-      bool
-      url_is_absolute (const char *url)
-      {
-          if (strncasecmp (url, "http:", 5) == 0 ||
-       strncasecmp (url, "https:", 6) == 0 ||
-       strncasecmp (url, "ftp:", 4) == 0 ||
-       strncasecmp (url, "cd:", 3) == 0 ||
-       strncasecmp (url, "dvd:", 4) == 0 ||
-       strncasecmp (url, "dir:", 4) == 0 ||
-       strncasecmp (url, "file:", 5) == 0)
-          {
-       return true;
-          }
-      
-          return false;
-      }
-      
-      
-      //---------------------------------------------------------------------------
-      // compress/uncompress stuff
-      
-      /*
-       * Magic gunzipping goodness
-       */
-      
-      /*
-       * Count number of bytes to skip at start of buf
-       */
-      static int gz_magic[2] = {0x1f, 0x8b};
-      /* gzip flag byte */
-      #define GZ_ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
-      #define GZ_HEAD_CRC     0x02 /* bit 1 set: header CRC present */
-      #define GZ_EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
-      #define GZ_ORIG_NAME    0x08 /* bit 3 set: original file name present */
-      #define GZ_COMMENT      0x10 /* bit 4 set: file comment present */
-      #define GZ_RESERVED     0xE0 /* bits 5..7: reserved */
-      
-      static int
-      count_gzip_header (const unsigned char *buf, unsigned int input_length)
-      {
-          int method, flags;
-          const unsigned char *s = buf;
-          unsigned int left_len = input_length;
-      
-          if (left_len < 4) return -1;
-          if (*s++ != gz_magic[0] || *s++ != gz_magic[1]) {
-       return -2;
-          }
-      
-          method = *s++;
-          flags = *s++;
-          left_len -= 4;
-      
-          if (method != Z_DEFLATED || (flags & GZ_RESERVED) != 0) {
-       /* If it's not deflated, or the reserved isn't 0 */
-       return -3;
-          }
-      
-          /* Skip time, xflags, OS code */
-          if (left_len < 6) return -4;
-          s += 6;
-          left_len -= 6;
-      
-          if (flags & GZ_EXTRA_FIELD) {
-       unsigned int len;
-       if (left_len < 2) return -5;
-       len = (unsigned int)(*s++);
-       len += ((unsigned int)(*s++)) << 8;
-       if (left_len < len) return -6;
-       s += len;
-       left_len -= len;
-          }
-      
-          /* Skip filename */
-          if (flags & GZ_ORIG_NAME) {
-       while (--left_len != 0 && *s++ != '\0') ;
-       if (left_len == 0) return -7;
-          }
-          /* Skip comment */
-          if (flags & GZ_COMMENT) {
-       while (--left_len != 0 && *s++ != '\0') ;
-       if (left_len == 0) return -7;
-          }
-          /* Skip CRC */
-          if (flags & GZ_HEAD_CRC) {
-       if (left_len < 2) return -7;
-       s += 2;
-       left_len -= 2;
-          }
-      
-          return input_length - left_len;
-      }
-      
-      
-      int
-      gunzip_memory (const unsigned char *input_buffer, unsigned int input_length, ByteArray **out_ba)
-      {
-          z_stream zs;
-          char *outbuf = NULL;
-          ByteArray *ba = NULL;
-          int zret;
-      
-          int gzip_hdr;
-      
-          if (input_buffer == NULL) return -1;
-          if (input_length == 0) return -2;
-          if (out_ba == NULL) return -3;
-      
-          ba = (ByteArray *)malloc (sizeof (ByteArray));
-          ba->data = NULL;
-          ba->len = 0;
-      
-          gzip_hdr = count_gzip_header (input_buffer, input_length);
-          if (gzip_hdr < 0)
-       return -1;
-      
-          zs.next_in = (unsigned char *) input_buffer + gzip_hdr;
-          zs.avail_in = input_length - gzip_hdr;
-          zs.zalloc = NULL;
-          zs.zfree = NULL;
-          zs.opaque = NULL;
-      
-      #define OUTBUFSIZE 10000
-          outbuf = (char *)malloc (OUTBUFSIZE);
-          zs.next_out = (Bytef *)outbuf;
-          zs.avail_out = OUTBUFSIZE;
-      
-          /* Negative inflateinit is magic to tell zlib that there is no
-           * zlib header */
-          inflateInit2 (&zs, -MAX_WBITS);
-      
-          while (1) {
-       zret = inflate (&zs, Z_SYNC_FLUSH);
-       if (zret != Z_OK && zret != Z_STREAM_END)
-           break;
-      
-       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
-       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
-       ba->len += (OUTBUFSIZE - zs.avail_out);
-      
-       zs.next_out = (Bytef *)outbuf;
-       zs.avail_out = OUTBUFSIZE;
-      
-       if (zret == Z_STREAM_END)
-           break;
-          }
-      
-          inflateEnd (&zs);
-          free ((void *)outbuf);
-      
-          if (zret != Z_STREAM_END) {
-       fprintf (stderr, "libz inflate failed! (%d)", zret);
-       free (ba->data);
-       free (ba);
-       ba = NULL;
-          } else {
-       zret = 0;
-          }
-      
-          *out_ba = ba;
-          return zret;
-      }
-      
-      
-      int
-      gzip_memory (const char *input_buffer, unsigned int input_length, ByteArray **out_ba)
-      {
-          z_stream zs;
-          char *outbuf = NULL;
-          ByteArray *ba = NULL;
-          int zret;
-      
-          if (input_buffer == NULL) return -1;
-          if (input_length == 0) return -2;
-          if (out_ba == NULL) return -3;
-      
-          ba = (ByteArray *)malloc (sizeof (ByteArray));
-          ba->data = NULL;
-          ba->len = 0;
-      
-          zs.next_in = (unsigned char *) input_buffer;
-          zs.avail_in = input_length;
-          zs.zalloc = NULL;
-          zs.zfree = NULL;
-          zs.opaque = NULL;
-      
-          outbuf = (char *)malloc (OUTBUFSIZE);
-          zs.next_out = (Bytef *)outbuf;
-          zs.avail_out = OUTBUFSIZE;
-      
-          deflateInit (&zs, Z_DEFAULT_COMPRESSION);
-      
-          while (1) {
-       if (zs.avail_in)
-           zret = deflate (&zs, Z_SYNC_FLUSH);
-       else
-           zret = deflate (&zs, Z_FINISH);
-           
-       if (zret != Z_OK && zret != Z_STREAM_END)
-           break;
-      
-       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
-       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
-       ba->len += (OUTBUFSIZE - zs.avail_out);
-      
-       zs.next_out = (Bytef *)outbuf;
-       zs.avail_out = OUTBUFSIZE;
-      
-       if (zret == Z_STREAM_END)
-           break;
-          }
-      
-          deflateEnd (&zs);
-          free ((void *)outbuf);
-      
-          if (zret != Z_STREAM_END) {
-       fprintf (stderr, "libz deflate failed! (%d)", zret);
-       free (ba->data);
-       free (ba);
-       ba = NULL;
-          } else {
-       zret = 0;
-          }
-      
-          *out_ba = ba;
-          return zret;
-      } /* gzip_memory */
-      
-      
-      bool
-      memory_looks_gzipped (const unsigned char *buffer)
-      {
-          if (buffer == NULL)
-       return false;
-      
-          /* This is from RFC 1952 */
-      
-          return buffer[0] == gz_magic[0]  /* ID1 */
-       && buffer[1] == gz_magic[1]; /* ID2 */
-      }
-      
-      /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
-      
-      static char bz2_magic[3] = { 'B', 'Z', 'h' };
-      
-      int
-      bunzip2_memory (const unsigned char *input_buffer, unsigned int input_length, ByteArray **out_ba)
-      {
-      #ifndef HAVE_BZ2
-      
-          fprintf (stderr, "bz2 support not compiled in");
-          *out_ba = NULL;
-      
-          return -1;
-      
-      #else
-      
-          bz_stream bzs;
-          ByteArray *ba;
-          char *outbuf;
-          int bzret;
-      
-          if (input_buffer == NULL) return -1;
-          if (input_length == 0) return -2;
-          if (out_ba == NULL) return -3;
-      
-          ba = (ByteArray *)malloc (sizeof (ByteArray));
-          ba->data = NULL;
-          ba->len = 0;
-      
-          bzs.next_in = (unsigned char *) input_buffer;
-          bzs.avail_in = input_length;
-          bzs.bzalloc = NULL;
-          bzs.bzfree = NULL;
-          bzs.opaque = NULL;
-      
-          outbuf = (char *)malloc (OUTBUFSIZE);
-          bzs.next_out = (Bytef *)outbuf;
-          bzs.avail_out = OUTBUFSIZE;
-      
-          BZ2_bzDecompressInit (&bzs, 1, 0);
-      
-          while (1) {
-       bzret = BZ2_bzDecompress (&bzs);
-       if (bzret != BZ_OK && bzret != BZ_STREAM_END)
-           break;
-      
-       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
-       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
-       ba->len += (OUTBUFSIZE - zs.avail_out);
-      
-       bzs.next_out = (Bytef *)outbuf;
-       bzs.avail_out = OUTBUFSIZE;
-      
-       if (bzret == BZ_STREAM_END)
-           break;
-      
-       if (bzs.avail_in == 0) {
-           /* The data is incomplete */
-           bzret = -1;
-           break;
-       }
-          }
-      
-          BZ2_bzDecompressEnd (&bzs);
-          free ((void *)outbuf);
-      
-          if (bzret != BZ_STREAM_END) {
-       fprintf (stderr, "libbzip2 decompress failed (%d)", bzret);
-       free (ba->data);
-       free (ba);
-       ba = NULL;
-          } else {
-       bzret = 0;
-          }
-      
-          *out_ba = ba;
-          return bzret;
-      #endif
-      }
-      
-      
-      int
-      bzip2_memory (const char *input_buffer, unsigned int input_length, ByteArray **out_ba)
-      {
-      #ifndef HAVE_BZ2
-      
-          fprintf (stderr, "bz2 support not compiled in");
-          *out_ba = NULL;
-      
-          return -1;
-      
-      #else
-      
-          bz_stream bzs;
-          ByteArray *ba;
-          char *outbuf;
-          int bzret;
-      
-          if (input_buffer == NULL) return -1;
-          if (input_length == 0) return -2;
-          if (out_ba == NULL) return -3;
-      
-          ba = (ByteArray *)malloc (sizeof (ByteArray));
-          ba->data = NULL;
-          ba->len = 0;
-      
-          bzs.next_in = (unsigned char *) input_buffer;
-          bzs.avail_in = input_length;
-          bzs.bzalloc = NULL;
-          bzs.bzfree = NULL;
-          bzs.opaque = NULL;
-      
-          outbuf = (char *)malloc (OUTBUFSIZE);
-          bzs.next_out = (Bytef *)outbuf;
-          bzs.avail_out = OUTBUFSIZE;
-      
-          BZ2_bzCompressInit (&bzs, 5, 1, 0);
-      
-          while (1) {
-       if (bzs.avail_in)
-           bzret = BZ2_bzCompress (&bzs, BZ_RUN);
-       else
-           bzret = BZ2_bzCompress (&bzs, BZ_FINISH);
-           
-       if (bzret != BZ_OK && bzret != BZ_STREAM_END)
-           break;
-      
-       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
-       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
-       ba->len += (OUTBUFSIZE - zs.avail_out);
-      
-       bzs.next_out = (Bytef *)outbuf;
-       bzs.avail_out = OUTBUFSIZE;
-      
-       if (bzret == BZ_STREAM_END)
-           break;
-          }
-      
-          BZ2_bzCompressEnd (&bzs);
-          free ((void *)outbuf);
-      
-          if (bzret != BZ_STREAM_END) {
-       fprintf (stderr, "bz2 compress failed! (%d)", bzret);
-       free (ba->data);
-       free (ba);
-       ba = NULL;
-          } else {
-       bzret = 0;
-          }
-      
-          *out_ba = ba;
-          return bzret;
-      #endif
-      }
-      
-      
-      bool
-      memory_looks_bzip2ed (const unsigned char *buffer)
-      {
-          if (buffer == NULL)
-       return false;
-      
-          return buffer[0] == bz2_magic[0]
-       && buffer[1] == bz2_magic[1]
-       && buffer[2] == bz2_magic[2];
-      }
-      
-      /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
-      
-      int
-      uncompress_memory (const unsigned char *input_buffer, unsigned int input_length, ByteArray **out_ba)
-      {
-          if (input_length > 2 && memory_looks_bzip2ed (input_buffer))
-       return bunzip2_memory (input_buffer, input_length, out_ba);
-          else if (input_length > 3 && memory_looks_gzipped (input_buffer))
-       return gunzip_memory (input_buffer, input_length, out_ba);
-          else
-       return -1;
-      }
-      
-      bool
-      memory_looks_compressed (const unsigned char *buffer, size_t size)
-      {
-      #ifdef HAVE_BZ2
-          if (size > 2 && memory_looks_bzip2ed (buffer))
-       return true;
-      #endif
-      
-          if (size > 4 && memory_looks_gzipped (buffer))
-       return true;
-      
-          return false;
-      }
-      
-      //---------------------------------------------------------------------------
-      // I/O stuff
-      
-      /* 
-       * This just allows reading from the buffer for now.  It could be extended to
-       * do writing if necessary.
-       */
-      
-      Buffer *
-      buffer_map_file (const string & filename)
-      {
-          struct stat s;
-          int fd;
-          unsigned char *data;
-          Buffer *buf = NULL;
-      
-          if (filename.empty())
-       return NULL;
-      
-          if (stat(filename.c_str(), &s) < 0)
-       return NULL;
-      
-          fd = open(filename.c_str(), O_RDONLY);
-      
-          if (fd < 0)
-       return NULL;
-      
-          data = (unsigned char *)mmap(NULL, s.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
-      
-          close (fd);
-      
-          if (data == MAP_FAILED)
-       return NULL;
-      
-          /* Transparently uncompress */
-          if (memory_looks_compressed (data, s.st_size)) {
-       ByteArray *byte_array = NULL;
-      
-       if (uncompress_memory (data, s.st_size, &byte_array)) {
-           WAR << "Uncompression of '" << filename
+using namespace std;
+
+//---------------------------------------------------------------------------
+// string stuff
+
+/* Like g_strstrip(), only returns NULL on an empty string */
+char *
+strstrip (const char *str)
+{
+    const char *start;
+    const char *end;
+
+    if (str == NULL)
+       return "";
+
+    start = str;
+    while (isblank (*start)) {
+       start++;
+    }
+
+    end = start + strlen (start) - 1;
+    while (end > start
+          && isblank (*end)) {
+       end--;
+    }
+
+    if (start > end) {                 // empty string
+       return NULL;
+    }
+
+    if (start > str
+       || *(end+1) != 0) {             // we stripped at least one blank somewhere
+       return strndup (start, end - start + 1);
+    }
+    return strdup (str);               // no blanks stripped
+}
+
+
+//---------------------------------------------------------------------------
+// url and path stuff
+
+string
+maybe_merge_paths(const std::string & parent_path, const std::string & child_path)
+{
+    /* Child path is "", so we return a dup of the parent path.
+       Ex: maybe_merge_paths("/foo", "") => "/foo" */
+    if (child_path.empty())
+       return parent_path;
+
+    /* Child path is a fully qualified URL, so we return a dup of it.
+       Ex: maybe_merge_paths("/foo", "http://www.ximian.com") =>
+       "http://www.ximian.com"
+
+       OR
+
+       Child path is an absolute path, so we just return a dup of it.
+       Ex: maybe_merge_paths("/foo", "/bar/baz") => "/bar/baz" */
+
+    if (url_is_absolute(child_path) || child_path[0] == '/')
+       return child_path;
+
+    /* Child path is a relative path, so we tack child path onto the end of
+       parent path.
+       Ex: maybe_merge_paths("/foo", "bar/baz") => "/foo/bar/baz" */
+
+    string s = parent_path;
+
+    if (parent_path[parent_path.length() - 1] != '/')
+       s += "/";
+    
+    s += child_path;
+
+    return s;
+}
+
+
+bool
+url_is_absolute (const std::string & url)
+{
+    if (strncasecmp (url.c_str(), "http:", 5) == 0 ||
+       strncasecmp (url.c_str(), "https:", 6) == 0 ||
+       strncasecmp (url.c_str(), "ftp:", 4) == 0 ||
+       strncasecmp (url.c_str(), "cd:", 3) == 0 ||
+       strncasecmp (url.c_str(), "dvd:", 4) == 0 ||
+       strncasecmp (url.c_str(), "dir:", 4) == 0 ||
+       strncasecmp (url.c_str(), "file:", 5) == 0)
+    {
+       return true;
+    }
+
+    return false;
+}
+
+
+//---------------------------------------------------------------------------
+// compress/uncompress stuff
+
+/*
+ * Magic gunzipping goodness
+ */
+
+/*
+ * Count number of bytes to skip at start of buf
+ */
+static int gz_magic[2] = {0x1f, 0x8b};
+/* gzip flag byte */
+#define GZ_ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
+#define GZ_HEAD_CRC     0x02 /* bit 1 set: header CRC present */
+#define GZ_EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
+#define GZ_ORIG_NAME    0x08 /* bit 3 set: original file name present */
+#define GZ_COMMENT      0x10 /* bit 4 set: file comment present */
+#define GZ_RESERVED     0xE0 /* bits 5..7: reserved */
+
+static int
+count_gzip_header (const unsigned char *buf, unsigned int input_length)
+{
+    int method, flags;
+    const unsigned char *s = buf;
+    unsigned int left_len = input_length;
+
+    if (left_len < 4) return -1;
+    if (*s++ != gz_magic[0] || *s++ != gz_magic[1]) {
+       return -2;
+    }
+
+    method = *s++;
+    flags = *s++;
+    left_len -= 4;
+
+    if (method != Z_DEFLATED || (flags & GZ_RESERVED) != 0) {
+       /* If it's not deflated, or the reserved isn't 0 */
+       return -3;
+    }
+
+    /* Skip time, xflags, OS code */
+    if (left_len < 6) return -4;
+    s += 6;
+    left_len -= 6;
+
+    if (flags & GZ_EXTRA_FIELD) {
+       unsigned int len;
+       if (left_len < 2) return -5;
+       len = (unsigned int)(*s++);
+       len += ((unsigned int)(*s++)) << 8;
+       if (left_len < len) return -6;
+       s += len;
+       left_len -= len;
+    }
+
+    /* Skip filename */
+    if (flags & GZ_ORIG_NAME) {
+       while (--left_len != 0 && *s++ != '\0') ;
+       if (left_len == 0) return -7;
+    }
+    /* Skip comment */
+    if (flags & GZ_COMMENT) {
+       while (--left_len != 0 && *s++ != '\0') ;
+       if (left_len == 0) return -7;
+    }
+    /* Skip CRC */
+    if (flags & GZ_HEAD_CRC) {
+       if (left_len < 2) return -7;
+       s += 2;
+       left_len -= 2;
+    }
+
+    return input_length - left_len;
+}
+
+
+int
+gunzip_memory (const unsigned char *input_buffer, unsigned int input_length, ByteArray **out_ba)
+{
+    z_stream zs;
+    char *outbuf = NULL;
+    ByteArray *ba = NULL;
+    int zret;
+
+    int gzip_hdr;
+
+    if (input_buffer == NULL) return -1;
+    if (input_length == 0) return -2;
+    if (out_ba == NULL) return -3;
+
+    ba = (ByteArray *)malloc (sizeof (ByteArray));
+    ba->data = NULL;
+    ba->len = 0;
+
+    gzip_hdr = count_gzip_header (input_buffer, input_length);
+    if (gzip_hdr < 0)
+       return -1;
+
+    zs.next_in = (unsigned char *) input_buffer + gzip_hdr;
+    zs.avail_in = input_length - gzip_hdr;
+    zs.zalloc = NULL;
+    zs.zfree = NULL;
+    zs.opaque = NULL;
+
+#define OUTBUFSIZE 10000
+    outbuf = (char *)malloc (OUTBUFSIZE);
+    zs.next_out = (Bytef *)outbuf;
+    zs.avail_out = OUTBUFSIZE;
+
+    /* Negative inflateinit is magic to tell zlib that there is no
+     * zlib header */
+    inflateInit2 (&zs, -MAX_WBITS);
+
+    while (1) {
+       zret = inflate (&zs, Z_SYNC_FLUSH);
+       if (zret != Z_OK && zret != Z_STREAM_END)
+           break;
+
+       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
+       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
+       ba->len += (OUTBUFSIZE - zs.avail_out);
+
+       zs.next_out = (Bytef *)outbuf;
+       zs.avail_out = OUTBUFSIZE;
+
+       if (zret == Z_STREAM_END)
+           break;
+    }
+
+    inflateEnd (&zs);
+    free ((void *)outbuf);
+
+    if (zret != Z_STREAM_END) {
+       fprintf (stderr, "libz inflate failed! (%d)", zret);
+       free (ba->data);
+       free (ba);
+       ba = NULL;
+    } else {
+       zret = 0;
+    }
+
+    *out_ba = ba;
+    return zret;
+}
+
+
+int
+gzip_memory (const char *input_buffer, unsigned int input_length, ByteArray **out_ba)
+{
+    z_stream zs;
+    char *outbuf = NULL;
+    ByteArray *ba = NULL;
+    int zret;
+
+    if (input_buffer == NULL) return -1;
+    if (input_length == 0) return -2;
+    if (out_ba == NULL) return -3;
+
+    ba = (ByteArray *)malloc (sizeof (ByteArray));
+    ba->data = NULL;
+    ba->len = 0;
+
+    zs.next_in = (unsigned char *) input_buffer;
+    zs.avail_in = input_length;
+    zs.zalloc = NULL;
+    zs.zfree = NULL;
+    zs.opaque = NULL;
+
+    outbuf = (char *)malloc (OUTBUFSIZE);
+    zs.next_out = (Bytef *)outbuf;
+    zs.avail_out = OUTBUFSIZE;
+
+    deflateInit (&zs, Z_DEFAULT_COMPRESSION);
+
+    while (1) {
+       if (zs.avail_in)
+           zret = deflate (&zs, Z_SYNC_FLUSH);
+       else
+           zret = deflate (&zs, Z_FINISH);
+           
+       if (zret != Z_OK && zret != Z_STREAM_END)
+           break;
+
+       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
+       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
+       ba->len += (OUTBUFSIZE - zs.avail_out);
+
+       zs.next_out = (Bytef *)outbuf;
+       zs.avail_out = OUTBUFSIZE;
+
+       if (zret == Z_STREAM_END)
+           break;
+    }
+
+    deflateEnd (&zs);
+    free ((void *)outbuf);
+
+    if (zret != Z_STREAM_END) {
+       fprintf (stderr, "libz deflate failed! (%d)", zret);
+       free (ba->data);
+       free (ba);
+       ba = NULL;
+    } else {
+       zret = 0;
+    }
+
+    *out_ba = ba;
+    return zret;
+} /* gzip_memory */
+
+
+bool
+memory_looks_gzipped (const unsigned char *buffer)
+{
+    if (buffer == NULL)
+       return false;
+
+    /* This is from RFC 1952 */
+
+    return buffer[0] == gz_magic[0]  /* ID1 */
+       && buffer[1] == gz_magic[1]; /* ID2 */
+}
+
+/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
+
+static char bz2_magic[3] = { 'B', 'Z', 'h' };
+
+int
+bunzip2_memory (const unsigned char *input_buffer, unsigned int input_length, ByteArray **out_ba)
+{
+#ifndef HAVE_BZ2
+
+    fprintf (stderr, "bz2 support not compiled in");
+    *out_ba = NULL;
+
+    return -1;
+
+#else
+
+    bz_stream bzs;
+    ByteArray *ba;
+    char *outbuf;
+    int bzret;
+
+    if (input_buffer == NULL) return -1;
+    if (input_length == 0) return -2;
+    if (out_ba == NULL) return -3;
+
+    ba = (ByteArray *)malloc (sizeof (ByteArray));
+    ba->data = NULL;
+    ba->len = 0;
+
+    bzs.next_in = (unsigned char *) input_buffer;
+    bzs.avail_in = input_length;
+    bzs.bzalloc = NULL;
+    bzs.bzfree = NULL;
+    bzs.opaque = NULL;
+
+    outbuf = (char *)malloc (OUTBUFSIZE);
+    bzs.next_out = (Bytef *)outbuf;
+    bzs.avail_out = OUTBUFSIZE;
+
+    BZ2_bzDecompressInit (&bzs, 1, 0);
+
+    while (1) {
+       bzret = BZ2_bzDecompress (&bzs);
+       if (bzret != BZ_OK && bzret != BZ_STREAM_END)
+           break;
+
+       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
+       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
+       ba->len += (OUTBUFSIZE - zs.avail_out);
+
+       bzs.next_out = (Bytef *)outbuf;
+       bzs.avail_out = OUTBUFSIZE;
+
+       if (bzret == BZ_STREAM_END)
+           break;
+
+       if (bzs.avail_in == 0) {
+           /* The data is incomplete */
+           bzret = -1;
+           break;
+       }
+    }
+
+    BZ2_bzDecompressEnd (&bzs);
+    free ((void *)outbuf);
+
+    if (bzret != BZ_STREAM_END) {
+       fprintf (stderr, "libbzip2 decompress failed (%d)", bzret);
+       free (ba->data);
+       free (ba);
+       ba = NULL;
+    } else {
+       bzret = 0;
+    }
+
+    *out_ba = ba;
+    return bzret;
+#endif
+}
+
+
+int
+bzip2_memory (const char *input_buffer, unsigned int input_length, ByteArray **out_ba)
+{
+#ifndef HAVE_BZ2
+
+    fprintf (stderr, "bz2 support not compiled in");
+    *out_ba = NULL;
+
+    return -1;
+
+#else
+
+    bz_stream bzs;
+    ByteArray *ba;
+    char *outbuf;
+    int bzret;
+
+    if (input_buffer == NULL) return -1;
+    if (input_length == 0) return -2;
+    if (out_ba == NULL) return -3;
+
+    ba = (ByteArray *)malloc (sizeof (ByteArray));
+    ba->data = NULL;
+    ba->len = 0;
+
+    bzs.next_in = (unsigned char *) input_buffer;
+    bzs.avail_in = input_length;
+    bzs.bzalloc = NULL;
+    bzs.bzfree = NULL;
+    bzs.opaque = NULL;
+
+    outbuf = (char *)malloc (OUTBUFSIZE);
+    bzs.next_out = (Bytef *)outbuf;
+    bzs.avail_out = OUTBUFSIZE;
+
+    BZ2_bzCompressInit (&bzs, 5, 1, 0);
+
+    while (1) {
+       if (bzs.avail_in)
+           bzret = BZ2_bzCompress (&bzs, BZ_RUN);
+       else
+           bzret = BZ2_bzCompress (&bzs, BZ_FINISH);
+           
+       if (bzret != BZ_OK && bzret != BZ_STREAM_END)
+           break;
+
+       ba->data = (byte *)realloc (ba->data, ba->len + (OUTBUFSIZE - zs.avail_out));
+       memcpy (ba->data + ba->len, outbuf, OUTBUFSIZE - zs.avail_out);
+       ba->len += (OUTBUFSIZE - zs.avail_out);
+
+       bzs.next_out = (Bytef *)outbuf;
+       bzs.avail_out = OUTBUFSIZE;
+
+       if (bzret == BZ_STREAM_END)
+           break;
+    }
+
+    BZ2_bzCompressEnd (&bzs);
+    free ((void *)outbuf);
+
+    if (bzret != BZ_STREAM_END) {
+       fprintf (stderr, "bz2 compress failed! (%d)", bzret);
+       free (ba->data);
+       free (ba);
+       ba = NULL;
+    } else {
+       bzret = 0;
+    }
+
+    *out_ba = ba;
+    return bzret;
+#endif
+}
+
+
+bool
+memory_looks_bzip2ed (const unsigned char *buffer)
+{
+    if (buffer == NULL)
+       return false;
+
+    return buffer[0] == bz2_magic[0]
+       && buffer[1] == bz2_magic[1]
+       && buffer[2] == bz2_magic[2];
+}
+
+/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */
+
+int
+uncompress_memory (const unsigned char *input_buffer, unsigned int input_length, ByteArray **out_ba)
+{
+    if (input_length > 2 && memory_looks_bzip2ed (input_buffer))
+       return bunzip2_memory (input_buffer, input_length, out_ba);
+    else if (input_length > 3 && memory_looks_gzipped (input_buffer))
+       return gunzip_memory (input_buffer, input_length, out_ba);
+    else
+       return -1;
+}
+
+bool
+memory_looks_compressed (const unsigned char *buffer, size_t size)
+{
+#ifdef HAVE_BZ2
+    if (size > 2 && memory_looks_bzip2ed (buffer))
+       return true;
+#endif
+
+    if (size > 4 && memory_looks_gzipped (buffer))
+       return true;
+
+    return false;
+}
+
+//---------------------------------------------------------------------------
+// I/O stuff
+
+/* 
+ * This just allows reading from the buffer for now.  It could be extended to
+ * do writing if necessary.
+ */
+
+Buffer *
+buffer_map_file (const string & filename)
+{
+    struct stat s;
+    int fd;
+    unsigned char *data;
+    Buffer *buf = NULL;
+
+    if (filename.empty())
+       return NULL;
+
+    if (stat(filename.c_str(), &s) < 0)
+       return NULL;
+
+    fd = open(filename.c_str(), O_RDONLY);
+
+    if (fd < 0)
+       return NULL;
+
+    data = (unsigned char *)mmap(NULL, s.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+
+    close (fd);
+
+    if (data == MAP_FAILED)
+       return NULL;
+
+    /* Transparently uncompress */
+    if (memory_looks_compressed (data, s.st_size)) {
+       ByteArray *byte_array = NULL;
+
+       if (uncompress_memory (data, s.st_size, &byte_array)) {
+           WAR << "Uncompression of '" << filename
                << "' failed" << endl;
-       } else {
-           buf = (Buffer *)malloc(sizeof (Buffer));
-           buf->data       = byte_array->data;
-           buf->size       = byte_array->len;
-           buf->is_mmapped = false;
-       }
-      
-       munmap (data, s.st_size);
-      
-       if (byte_array) {
-           free (byte_array);
-       }
-      
-          } else {
-       buf = (Buffer *)malloc(sizeof (Buffer));
-       buf->data       = (byte *)data;
-       buf->size       = s.st_size;
-       buf->is_mmapped = true;
-          }
-      
-          return buf;
-      } /* buffer_map_file */
-      
-      void
-      buffer_unmap_file (Buffer *buf)
-      {
-          if (buf == NULL) return;
-      
-          if (buf->is_mmapped)
-       munmap (buf->data, buf->size);
-          else
-       free (buf->data);
-      
-          free (buf);
-      }
-      
-      //---------------------------------------------------------------------------
-      // XML stuff
-      
-      xmlDoc *
-      parse_xml_from_buffer (const char *input_buffer, size_t input_length)
-      {
-          xmlDoc *doc = NULL;
-      
-          if (input_buffer == NULL) return NULL;
-      
-          if (input_length > 3 && memory_looks_gzipped ((const unsigned char *)input_buffer)) { 
-              ByteArray *buf;
-      
-              if (uncompress_memory ((const unsigned char *)input_buffer, input_length, &buf)) {
-                  return NULL;
-              }
-              doc = xmlParseMemory ((const char *)(buf->data), buf->len);
-       free (buf->data);
-              free (buf);
-          } else {
-              doc = xmlParseMemory (input_buffer, input_length);
-          }
-      
-          return doc;
-      }
-      
-      
-      xmlDoc *
-      parse_xml_from_file (const string & filename)
-      {
-          Buffer *buf;
-          xmlDoc *doc = NULL;
-      
-          if (filename.empty()) return NULL;
-      
-          buf = buffer_map_file (filename);
-          if (buf) {
-              doc = xmlParseMemory ((const char *)(buf->data), buf->size);
-              buffer_unmap_file (buf);
-          }
-      
-          return doc;
-      }
-      
-      ///////////////////////////////////////////////////////////////////
+       } else {
+           buf = (Buffer *)malloc(sizeof (Buffer));
+           buf->data       = byte_array->data;
+           buf->size       = byte_array->len;
+           buf->is_mmapped = false;
+       }
+
+       munmap (data, s.st_size);
+
+       if (byte_array) {
+           free (byte_array);
+       }
+
+    } else {
+       buf = (Buffer *)malloc(sizeof (Buffer));
+       buf->data       = (byte *)data;
+       buf->size       = s.st_size;
+       buf->is_mmapped = true;
+    }
+
+    return buf;
+} /* buffer_map_file */
+
+void
+buffer_unmap_file (Buffer *buf)
+{
+    if (buf == NULL) return;
+
+    if (buf->is_mmapped)
+       munmap (buf->data, buf->size);
+    else
+       free (buf->data);
+
+    free (buf);
+}
+
+//---------------------------------------------------------------------------
+// XML stuff
+
+xmlDoc *
+parse_xml_from_buffer (const char *input_buffer, size_t input_length)
+{
+    xmlDoc *doc = NULL;
+
+    if (input_buffer == NULL) return NULL;
+
+    if (input_length > 3 && memory_looks_gzipped ((const unsigned char *)input_buffer)) { 
+        ByteArray *buf;
+
+        if (uncompress_memory ((const unsigned char *)input_buffer, input_length, &buf)) {
+            return NULL;
+        }
+        doc = xmlParseMemory ((const char *)(buf->data), buf->len);
+       free (buf->data);
+        free (buf);
+    } else {
+        doc = xmlParseMemory (input_buffer, input_length);
+    }
+
+    return doc;
+}
+
+
+xmlDoc *
+parse_xml_from_file (const string & filename)
+{
+    Buffer *buf;
+    xmlDoc *doc = NULL;
+
+    if (filename.empty()) return NULL;
+
+    buf = buffer_map_file (filename);
+    if (buf) {
+        doc = xmlParseMemory ((const char *)(buf->data), buf->size);
+        buffer_unmap_file (buf);
+    }
+
+    return doc;
+}
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index 278f568..dca3719 100644 (file)
@@ -40,36 +40,35 @@ namespace zypp
     /////////////////////////////////////////////////////////////////////
     namespace detail
     { ///////////////////////////////////////////////////////////////////
-      
-      typedef unsigned char byte;
-      
-      char *strstrip (const char *str);
-      char *maybe_merge_paths(const char *parent_path, const char *child_path);
-      bool url_is_absolute (const char *url);
-      
-      
-      typedef struct {
-          byte *data;
-          size_t len;
-      } ByteArray;
-      
-      // An easy way to map files.  If we map a compressed file,
-      //   it will be magically uncompressed for us.
-      
-      typedef struct {
-          byte *data;
-          size_t size;
-          bool is_mmapped;
-      } Buffer;
-      
-      Buffer *buffer_map_file (const std::string & filename);
-      void buffer_unmap_file (Buffer *buffer);
-      
-      
-      xmlDoc *parse_xml_from_buffer (const char *input_buffer, size_t input_length);
-      xmlDoc *parse_xml_from_file (const std::string & filename);
-      
-      ///////////////////////////////////////////////////////////////////
+
+typedef unsigned char byte;
+
+char *strstrip (const char *str);
+std::string maybe_merge_paths(const std::string & parent_path, const std::string & child_path);
+bool url_is_absolute (const std::string & url);
+
+typedef struct {
+    byte *data;
+    size_t len;
+} ByteArray;
+
+// An easy way to map files.  If we map a compressed file,
+//   it will be magically uncompressed for us.
+
+typedef struct {
+    byte *data;
+    size_t size;
+    bool is_mmapped;
+} Buffer;
+
+Buffer *buffer_map_file (const std::string & filename);
+void buffer_unmap_file (Buffer *buffer);
+
+
+xmlDoc *parse_xml_from_buffer (const char *input_buffer, size_t input_length);
+xmlDoc *parse_xml_from_file (const std::string & filename);
+
+///////////////////////////////////////////////////////////////////
     };// namespace detail
     /////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////
index e01611a..6a61f27 100644 (file)
@@ -235,13 +235,13 @@ print_solution (ResolverContext_Ptr context, int *count, ChecksumList & checksum
 
 //---------------------------------------------------------------------------------------------------------------------
 static void
-undump (const char *filename)
+undump (const std::string & filename)
 {
     UndumpWorld_Ptr undump_world;
 
     undump_world = new UndumpWorld (filename);
     if (undump_world == NULL) {
-       fprintf (stderr, "Couldn't undump from file '%s'", filename);
+       fprintf (stderr, "Couldn't undump from file '%s'", filename.c_str());
        return;
     }
 
@@ -250,7 +250,7 @@ undump (const char *filename)
 
 
 static Channel_Ptr
-get_channel (const char *channel_name)
+get_channel (const string & channel_name)
 {
     Channel_Ptr channel;
 
@@ -267,7 +267,7 @@ get_channel (const char *channel_name)
 
 
 static ResItem_constPtr
-get_resItem (const char *channel_name, const char *package_name)
+get_resItem (const string & channel_name, const string & package_name)
 {
     Channel_constPtr channel;
     ResItem_constPtr resItem;
@@ -275,14 +275,14 @@ get_resItem (const char *channel_name, const char *package_name)
     channel = get_channel (channel_name);
 
     if (channel == NULL) {
-       fprintf (stderr, "Can't find package '%s': channel '%s' not defined\n", package_name, channel_name);
+       fprintf (stderr, "Can't find package '%s': channel '%s' not defined\n", package_name.c_str(), channel_name.c_str());
        return NULL;
     }
 
     resItem = world->findResItem (channel, package_name);
 
     if (resItem == NULL) {
-       fprintf (stderr, "Can't find package '%s' in channel '%s': no such package\n", package_name, channel_name);
+       fprintf (stderr, "Can't find package '%s' in channel '%s': no such package\n", package_name.c_str(), channel_name.c_str());
        return NULL;
     }
 
@@ -305,8 +305,9 @@ add_to_world_cb (ResItem_constPtr resItem, void *data)
 static void
 load_channel (const string & name, const string & filename, const string & type, bool system_packages)
 {
-    string pathname = "deptestomatic/" + filename;
-    
+//    string pathname = "deptestomatic/" + filename;
+    string pathname = filename;
+
     if (getenv ("RC_SPEW")) fprintf (stderr, "load_channel(%s,%s,%s,%s)\n", name.c_str(), pathname.c_str(), type.c_str(), system_packages?"system":"non-system");
 
     ChannelType chan_type = system_packages ? CHANNEL_TYPE_SYSTEM : CHANNEL_TYPE_UNKNOWN;
@@ -373,10 +374,9 @@ parse_xml_setup (XmlNode_Ptr node)
        }
 
        if (node->equals ("system")) {
-           const char *file = node->getProp ("file");
-           assertExit (file);
+           string file = node->getProp ("file");
+           assertExit (!file.empty());
            load_channel ("@system", file, "helix", true);
-           free ((void *)file);
        } else if (node->equals ("channel")) {
            string name = node->getProp ("name");
            string file = node->getProp ("file");
@@ -385,22 +385,21 @@ parse_xml_setup (XmlNode_Ptr node)
            assertExit (!file.empty());
            load_channel (name, file, type, false);
        } else if (node->equals ("undump")) {
-           const char *file = node->getProp ("file");
-           assertExit (file);
+           string file = node->getProp ("file");
+           assertExit (!file.empty());
            undump (file);
-           free((void *)file);
        } else if (node->equals ("force-install")) {
-           const char *channel_name = node->getProp ("channel");
-           const char *package_name = node->getProp ("package");
+           string channel_name = node->getProp ("channel");
+           string package_name = node->getProp ("package");
            ResItem_constPtr resItem;
            Channel_constPtr system_channel;
 
-           assertExit (channel_name);
-           assertExit (package_name);
+           assertExit (!channel_name.empty());
+           assertExit (!package_name.empty());
 
            resItem = get_resItem (channel_name, package_name);
            if (resItem) {
-               printf (">!> Force-installing %s from channel %s\n", package_name, channel_name);
+               printf (">!> Force-installing %s from channel %s\n", package_name.c_str(), channel_name.c_str());
 
                system_channel = world->getChannelById ("@system");
 
@@ -411,48 +410,42 @@ parse_xml_setup (XmlNode_Ptr node)
 //             r->setChannel (system_channel);
 //             r->setInstalled (true);
            } else {
-               fprintf (stderr, "Unknown package %s::%s\n", channel_name, package_name);
+               fprintf (stderr, "Unknown package %s::%s\n", channel_name.c_str(), package_name.c_str());
            }
 
-           free ((void *)channel_name);
-           free ((void *)package_name);
        } else if (node->equals ("force-uninstall")) {
-           const char *package_name = node->getProp ("package");
+           string package_name = node->getProp ("package");
            ResItem_constPtr resItem;
 
-           assertExit (package_name);
+           assertExit (!package_name.empty());
            resItem = get_resItem ("@system", package_name);
            
            if (! resItem) {
-               fprintf (stderr, "Can't force-uninstall installed package '%s'\n", package_name);
+               fprintf (stderr, "Can't force-uninstall installed package '%s'\n", package_name.c_str());
            } else {
-               printf (">!> Force-uninstalling '%s'\n", package_name);
+               printf (">!> Force-uninstalling '%s'\n", package_name.c_str());
            }
 
-           free ((void *)package_name);
        } else if (node->equals ("lock")) {
-           const char *channel_name = node->getProp ("channel");
-           const char *package_name = node->getProp ("package");
+           string channel_name = node->getProp ("channel");
+           string package_name = node->getProp ("package");
            ResItem_constPtr resItem;
 
-           assertExit (channel_name);
-           assertExit (package_name);
+           assertExit (!channel_name.c_str());
+           assertExit (!package_name.c_str());
 
            resItem = get_resItem (channel_name, package_name);
            if (resItem) {
-               printf (">!> Locking %s from channel %s\n", package_name, channel_name);
+               printf (">!> Locking %s from channel %s\n", package_name.c_str(), channel_name.c_str());
 #warning lock disabled
 //             ResItem_Ptr r = ResItem_Ptr::cast_away_const(resItem);
 //             r->setLocked (true);
            } else {
-               fprintf (stderr, "Unknown package %s::%s\n", channel_name, package_name);
+               fprintf (stderr, "Unknown package %s::%s\n", channel_name.c_str(), package_name.c_str());
            }
 
-           free ((void *)channel_name);
-           free ((void *)package_name);
-
        } else {
-           fprintf (stderr, "Unrecognized tag '%s' in setup\n", node->name());
+           fprintf (stderr, "Unrecognized tag '%s' in setup\n", node->name().c_str());
        }
 
        node = node->next();
@@ -562,9 +555,8 @@ parse_xml_trial (XmlNode_Ptr node)
 
        if (node->equals("note")) {
 
-           const char *note = node->getContent ();
-           printf ("NOTE: %s\n", note);
-           free ((void *)note);
+           string note = node->getContent ();
+           printf ("NOTE: %s\n", note.c_str());
 
        } else if (node->equals ("verify")) {
 
@@ -572,67 +564,58 @@ parse_xml_trial (XmlNode_Ptr node)
 
        } else if (node->equals ("current")) {
 
-           const char *channel_name = node->getProp ("channel");
+           string channel_name = node->getProp ("channel");
            Channel_constPtr channel = get_channel (channel_name);
 
            if (channel != NULL) {
                resolver.setCurrentChannel (channel);
            } else {
-               fprintf (stderr, "Unknown channel '%s' (current)\n", channel_name);
+               fprintf (stderr, "Unknown channel '%s' (current)\n", channel_name.c_str());
            }
 
-           free ((void *)channel_name);
-
        } else if (node->equals ("subscribe")) {
 
-           const char *channel_name = node->getProp ("channel");
+           string channel_name = node->getProp ("channel");
            Channel_Ptr channel = get_channel (channel_name);
 
            if (channel != NULL) {
                channel->setSubscription (true);
            } else {
-               fprintf (stderr, "Unknown channel '%s' (subscribe)\n", channel_name);
+               fprintf (stderr, "Unknown channel '%s' (subscribe)\n", channel_name.c_str());
            }
 
-           free ((void *)channel_name);
-       
        } else if (node->equals ("install")) {
 
-           const char *channel_name = node->getProp ("channel");
-           const char *package_name = node->getProp ("package");
+           string channel_name = node->getProp ("channel");
+           string package_name = node->getProp ("package");
            ResItem_constPtr resItem;
 
-           assertExit (channel_name);
-           assertExit (package_name);
+           assertExit (!channel_name.empty());
+           assertExit (!package_name.empty());
 
            resItem = get_resItem (channel_name, package_name);
            if (resItem) {
-               printf (">!> Installing %s from channel %s\n", package_name, channel_name);
+               printf (">!> Installing %s from channel %s\n", package_name.c_str(), channel_name.c_str());
                resolver.addResItemToInstall (resItem);
            } else {
-               fprintf (stderr, "Unknown package %s::%s\n", channel_name, package_name);
+               fprintf (stderr, "Unknown package %s::%s\n", channel_name.c_str(), package_name.c_str());
            }
 
-           free ((void *)channel_name);
-           free ((void *)package_name);
-
        } else if (node->equals ("uninstall")) {
 
-           const char *package_name = node->getProp ("package");
+           string package_name = node->getProp ("package");
            ResItem_constPtr resItem;
 
-           assertExit (package_name);
+           assertExit (!package_name.empty());
 
            resItem = get_resItem ("@system", package_name);
            if (resItem) {
-               printf (">!> Uninstalling %s\n", package_name);
+               printf (">!> Uninstalling %s\n", package_name.c_str());
                resolver.addResItemToRemove (resItem);
            } else {
-               fprintf (stderr, "Unknown system package %s\n", package_name);
+               fprintf (stderr, "Unknown system package %s\n", package_name.c_str());
            }
 
-           free ((void *)package_name);
-
        } else if (node->equals ("upgrade")) {
            int count;
 
@@ -655,13 +638,12 @@ parse_xml_trial (XmlNode_Ptr node)
                /* We just skip over anything that doesn't look like a dependency. */
 
                if (dep) {
-                   const char *conflict_str = iter->getProp ("conflict");
+                   string conflict_str = iter->getProp ("conflict");
 
-                   printf (">!> Solvedeps %s%s\n", conflict_str ? "conflict " : "",  dep->asString().c_str());
+                   printf (">!> Solvedeps %s%s\n", conflict_str.empty() ? "" : "conflict ",  dep->asString().c_str());
 
                    resolver.addExtraDependency (dep);
 
-                   free ((void *)conflict_str);
                }
                iter = iter->next();
            }
@@ -669,7 +651,7 @@ parse_xml_trial (XmlNode_Ptr node)
 #warning solvedeps disabled
 #endif
        } else {
-           fprintf (stderr, "Unknown tag '%s' in trial\n", node->name());
+           fprintf (stderr, "Unknown tag '%s' in trial\n", node->name().c_str());
        }
 
        node = node->next();
@@ -705,7 +687,7 @@ parse_xml_test (XmlNode_Ptr node)
            } else if (node->equals ("trial")) {
                parse_xml_trial (node);
            } else {
-               fprintf (stderr, "Unknown tag '%s' in test\n", node->name());
+               fprintf (stderr, "Unknown tag '%s' in test\n", node->name().c_str());
            }
        }