libpurple/protocols/demo/purpledemoprotocolim.c

Fri, 10 Mar 2023 01:16:40 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Fri, 10 Mar 2023 01:16:40 -0600
changeset 42135
1a89a067a0d5
parent 42025
f37c11d0200a
child 42305
a3895b6d3621
permissions
-rw-r--r--

Add a PurpleRequestFieldString subclass

This also does an `hg cp`, though with all the renaming of the parameter names, maybe that wasn't as useful for tracking the diff.

Note, I didn't bother re-indenting some of the blocks, because they'll all eventually be moved when everything is subclassed.

Testing Done:
Compiled and opened Request Fields from the Demo protocol.

Reviewed at https://reviews.imfreedom.org/r/2324/

/*
 * Purple - Internet Messaging Library
 * Copyright (C) Pidgin Developers <devel@pidgin.im>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include <glib/gi18n-lib.h>

#include "purpledemoprotocol.h"
#include "purpledemoprotocolim.h"

/******************************************************************************
 * PurpleProtocolIM Implementation
 *****************************************************************************/
typedef struct {
	PurpleConnection *connection;
	PurpleMessage *message;
} PurpleDemoProtocolIMInfo;

static void
purple_demo_protocol_im_info_free(PurpleDemoProtocolIMInfo *info) {
	g_object_unref(info->message);
	g_free(info);
}

static gboolean
purple_demo_protocol_echo_im_cb(gpointer data)
{
	PurpleDemoProtocolIMInfo *info = data;
	const char *who = NULL;
	PurpleMessageFlags flags;
	GDateTime *timestamp = NULL;

	/* Turn outgoing message back incoming. */
	who = purple_message_get_recipient(info->message);
	flags = purple_message_get_flags(info->message);
	flags &= ~PURPLE_MESSAGE_SEND;
	flags |= PURPLE_MESSAGE_RECV;
	timestamp = purple_message_get_timestamp(info->message);

	purple_serv_got_im(info->connection, who,
	                   purple_message_get_contents(info->message), flags,
	                   g_date_time_to_unix(timestamp));

	return FALSE;
}

static gint
purple_demo_protocol_send_im(G_GNUC_UNUSED PurpleProtocolIM *im,
                             PurpleConnection *conn, PurpleMessage *msg)
{
	const gchar *who = purple_message_get_recipient(msg);

	if(purple_strequal(who, "Echo")) {
		PurpleDemoProtocolIMInfo *info = g_new(PurpleDemoProtocolIMInfo, 1);

		info->connection = conn;
		info->message = g_object_ref(msg);

		g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
		                purple_demo_protocol_echo_im_cb, info,
		                (GDestroyNotify)purple_demo_protocol_im_info_free);
	}

	return 1;
}

void
purple_demo_protocol_im_init(PurpleProtocolIMInterface *iface) {
	iface->send = purple_demo_protocol_send_im;
}

mercurial