aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/oscar/bos.h
blob: e7c2cbcd8e65b3db237c9e57244832b45ffa6b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef __OSCAR_BOS_H__
#define __OSCAR_BOS_H__

#define AIM_CB_FAM_BOS 0x0009

/*
 * SNAC Family: Misc BOS Services.
 */ 
#define AIM_CB_BOS_ERROR 0x0001
#define AIM_CB_BOS_RIGHTSQUERY 0x0002
#define AIM_CB_BOS_RIGHTS 0x0003
#define AIM_CB_BOS_DEFAULT 0xffff

#endif /* __OSCAR_BOS_H__ */
{ color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/***************************************************************************\
*                                                                           *
*  BitlBee - An IRC to IM gateway                                           *
*  Jabber module - HipChat specific functions                               *
*                                                                           *
*  Copyright 2015 Xamarin Inc                                               *
*                                                                           *
*  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 "jabber.h"

xt_status hipchat_handle_success(struct im_connection *ic, struct xt_node *node)
{
	struct jabber_data *jd = ic->proto_data;
	char *sep, *jid;

	jid = xt_find_attr(node, "jid");

	sep = strchr(jid, '/');
	if (sep) {
		*sep = '\0';
	}

	jabber_set_me(ic, jid);
	imcb_log(ic, "Setting Hipchat JID to %s", jid);

	if (sep) {
		*sep = '/';
	}

	jd->muc_host = g_strdup(xt_find_attr(node, "muc_host"));

	/* Hipchat's auth doesn't expect a restart here */
	jd->flags &= ~JFLAG_STREAM_RESTART;

	if (!jabber_get_roster(ic) ||
	    !jabber_iq_disco_server(ic) ||
	    !jabber_get_hipchat_profile(ic)) {
		return XT_ABORT;
	}

	return XT_HANDLED;
}

int jabber_get_hipchat_profile(struct im_connection *ic)
{
	struct jabber_data *jd = ic->proto_data;
	struct xt_node *node;
	int st;

	imcb_log(ic, "Fetching hipchat profile for %s", jd->me);

	node = xt_new_node("query", NULL, NULL);
	xt_add_attr(node, "xmlns", XMLNS_HIPCHAT_PROFILE);
	node = jabber_make_packet("iq", "get", jd->me, node);

	jabber_cache_add(ic, node, jabber_parse_hipchat_profile);
	st = jabber_write_packet(ic, node);

	return st;
}

xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
{
	struct xt_node *query, *name_node;

	if (!(query = xt_find_node(node->children, "query"))) {
		imcb_log(ic, "Warning: Received NULL profile packet");
		return XT_ABORT;
	}

	name_node = xt_find_node(query->children, "name");
	if (!name_node) {
		imcb_log(ic, "Warning: Can't find real name in profile. Joining groupchats will not be possible.");
		return XT_ABORT;
	}

	set_setstr(&ic->acc->set, "display_name", name_node->text);
	return XT_HANDLED;

}

/* Returns a newly allocated string that tries to match the "slug" part of the JID using an
 * approximation of the method used by the server. This might fail in some rare conditions
 * (old JIDs generated a different way, locale settings unicode, etc) */
char *hipchat_make_channel_slug(const char *name)
{
	char *lower;
	char *new = g_malloc(strlen(name) + 1);
	int i = 0;

	do {
		if (*name == ' ') {
			new[i++] = '_';
		} else if (*name && !strchr("\"&'/:<>@", *name)) {
			new[i++] = *name;
		}
	} while (*(name++));

	new[i] = '\0';

	lower = g_utf8_strdown(new, -1);
	g_free(new);

	return lower;
}

char *hipchat_guess_channel_name(struct im_connection *ic, const char *name)
{
	struct jabber_data *jd = ic->proto_data;
	char *slug, *retval, *underscore;
	
	if (!(underscore = strchr(jd->username, '_')) || !jd->muc_host) {
		return NULL;
	}

	slug = hipchat_make_channel_slug(name);

	/* Get the organization ID from the username, before the underscore */
	*underscore = '\0';

	retval = g_strdup_printf("%s_%s@%s", jd->username, slug, jd->muc_host);

	*underscore = '_';

	g_free(slug);

	return retval;
}