+/*
+ * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include <string.h>
+#include <stdlib.h>
+#include "xmpp_internal.h"
+#include "sasl.h"
+
+void
+hc_xmpp_sasl_authenticate (hc_xmpp_t *xmpp)
+{
+ const char *mech = "PLAIN";
+ char *p = "";
+ iks *auth;
+ gsasl_client_start (xmpp->sasl_ctx, mech, &xmpp->sasl_session);
+ gsasl_property_set (xmpp->sasl_session, GSASL_AUTHID, xmpp->user);
+ gsasl_property_set (xmpp->sasl_session, GSASL_PASSWORD, xmpp->password);
+ gsasl_step64 (xmpp->sasl_session, p, &p);
+ auth = iks_new ("auth");
+ iks_insert_attrib (auth, "xmlns", HC_XMPP_NS_SASL);
+ iks_insert_attrib (auth, "mechanism", mech);
+ iks_insert_cdata (auth, p, 0);
+ hc_xmpp_send_iks (xmpp, auth);
+ free (p);
+}
+
+void
+hc_xmpp_sasl_iterate (hc_xmpp_t *xmpp, iks *stanza)
+{
+ if (!iks_strcmp (iks_name (stanza), "success"))
+ {
+ xmpp->status = HC_XMPP_AUTHENTICATED;
+ }
+}