/* xmpp-capability.c - XMPP Entity Capability * Capability hash / Disco Features pair * * Copyright 2008 OpenMoko, Inc. * Authored by Daniel Willmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include G_DEFINE_TYPE(XmppCapability, xmpp_capability, G_TYPE_OBJECT); #define XMPP_CAPABILITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), XMPP_TYPE_CAPABILITY, XmppCapabilityPrivate)) typedef struct _XmppCapabilityPrivate XmppCapabilityPrivate; struct _XmppCapabilityPrivate { gchar *hash; gchar *hash_func; XmppDiscoinfo *discoinfo; }; static void xmpp_capability_finalize(GObject *obj) { GError *error = NULL; XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(obj); g_free(priv->hash); g_free(priv->hash_func); if (priv->discoinfo) { g_object_unref(priv->discoinfo); } ((GObjectClass *) xmpp_capability_parent_class)->finalize(obj); } static void xmpp_capability_class_init(XmppCapabilityClass *klass) { GObjectClass *o_class = (GObjectClass *) klass; //o_class->dispose = xmpp_capability_dispose; o_class->finalize = xmpp_capability_finalize; g_type_class_add_private(klass, sizeof(XmppCapabilityPrivate)); } static void xmpp_capability_init(XmppCapability *capability) { XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(capability); priv->hash = NULL; priv->hash_func = NULL; } XmppCapability *xmpp_capability_new(XmppDiscoinfo *discoinfo, const gchar *hash_func, const gchar *hash, GError **error) { XmppCapability * capability; XmppCapabilityPrivate *priv; capability = g_object_new(XMPP_TYPE_CAPABILITY, NULL); priv = XMPP_CAPABILITY_GET_PRIVATE(capability); if (discoinfo) { priv->discoinfo = discoinfo; g_object_ref(priv->discoinfo); } if (hash_func) priv->hash_func = strdup(hash_func); if (hash) priv->hash = strdup(hash); return capability; } gchar *xmpp_capability_get_hash_func(XmppCapability *capability) { XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(capability); return priv->hash_func; } gchar *xmpp_capability_get_hash(XmppCapability *capability) { XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(capability); return priv->hash; } XmppDiscoinfo *xmpp_capability_get_discoinfo(XmppCapability *capability) { XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(capability); return priv->discoinfo; } void xmpp_capability_set_discoinfo(XmppCapability *capability, XmppDiscoinfo *discoinfo) { XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(capability); if (priv->discoinfo) { g_object_unref(priv->discoinfo); } priv->discoinfo = discoinfo; if (priv->discoinfo) { g_object_ref(priv->discoinfo); } } void xmpp_capability_set_hash(XmppCapability *capability, const char* hash_func, const char* hash) { XmppCapabilityPrivate *priv = XMPP_CAPABILITY_GET_PRIVATE(capability); g_free(priv->hash_func); g_free(priv->hash); priv->hash_func = strdup(hash_func); priv->hash = strdup(hash); }