~aleteoryx/sexchat

ref: 7bcf0afcdb0263caa2fc6588284bb8dbfb198373 sexchat/src/common/batch.c -rw-r--r-- 2.7 KiB
7bcf0afcAleteoryx basic batch support 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* sexchat
 * Copyright (C) 2025 Aleteoryx.
 *
 * 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 St, Fifth Floor, Boston, MA 02110-1301, USA
 */

/* IRCv3 batch CAP */

#include <string.h>

#include "hexchat.h"
#include "batch.h"
#include "proto-irc.h"

void
batch_new (ircconn *serv, char *reftag, char *type, char **args)
{
	struct batch *bat;

	if (batch_lookup (serv, reftag))
		return;
	
	if (strcmp (type, "soju.im/bouncer-networks") == 0)
	{
		bat = (struct batch *)g_new0 (struct batch_sojuim_bouncer_networks, 1);
		bat->type = BATCH_SOJUIM_BOUNCER_NETWORKS;
	} else
	{
		bat = (struct batch *)g_new0 (struct batch_replay, 1);
		bat->type = BATCH_REPLAY;
	}
	
	bat->reftag = g_strdup (reftag);
	
	serv->batches = g_slist_prepend (serv->batches, bat);
}

void
batch_finalize (ircconn *serv, char *reftag)
{
	struct batch *bat;
	
	bat = batch_lookup (serv, reftag);
	if (bat == NULL)
		return;
	
	serv->batches = g_slist_remove (serv->batches, bat);
	
	switch (bat->type)
	{
	case BATCH_SOJUIM_BOUNCER_NETWORKS:
		break;

	case BATCH_REPLAY:
		{
			struct batch_replay *bat2 = (struct batch_replay *)bat;
			GSList *el;
			char *line;
			
			bat2->messages = g_slist_reverse (bat2->messages);
			for (el = bat2->messages; el; el = el->next)
			{
				line = (char *)el->data;
				irc_inline (serv, line, strlen (line));
				g_free (line);
			}
			
			g_slist_free (bat2->messages);
		}
	}
	
	g_free (bat);
}

gboolean
batch_event (ircconn *serv, char *reftag, char *raw, char **word, char **word_eol)
{
	struct batch *bat;

	bat = batch_lookup (serv, reftag);
	if (bat == NULL)
		return FALSE;

	switch (bat->type)
	{
	case BATCH_SOJUIM_BOUNCER_NETWORKS:
		break;
	case BATCH_REPLAY:
		{
			struct batch_replay *bat2 = (struct batch_replay *)bat;
			bat2->messages = g_slist_prepend (bat2->messages, g_strdup (raw));
		}
	}

	return TRUE;
}


struct batch *
batch_lookup (ircconn *serv, char *reftag)
{
	GSList *el;
	struct batch *bat;
	
	for (el = serv->batches; el; el = el->next)
	{
		bat = (struct batch *)el->data;
		if (strcmp (bat->reftag, reftag) == 0)
			return bat;
	}

	return NULL;
}