aboutsummaryrefslogtreecommitdiff
path: root/weechat/net.h
blob: 6348a89719fb8fff9d4015ffa0e118e5e61f1089 (plain)
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
#pragma once

#include <stdbool.h>
#include "global.h"


enum net_response_type{
	NET_OK,
	NET_NUMBER,
	NET_ERROR,
	NET_NAME,
	NET_LIST,
	NET_PONG,
	NET_MESSAGE,
	NET_HISTORY,
	NET_JOIN,
	NET_INVITE,
	NET_ONLINE,
};

struct net_response{
	enum net_response_type type;
	union {
		i64 number;
		char *error;
		char *name;
		struct {
			int nitems;
			char **items;
		};
		struct {
			char *room;
			char *username;
			i64 timestamp;
			char *message;
		};
		struct {
			char *username;
			i64 num;
		} online;
	};
};

typedef void net_callback_t(int fd,struct net_response res,void *payload);


void net_set_push_callback(net_callback_t *callback);
void net_set_history_callback(net_callback_t *callback);

bool net_sendf(int fd,net_callback_t *callback,void *payload,const char *format,...)
	__attribute__((format (printf, 4, 5)));

void net_handle_recv(int fd,const char *msg);