summaryrefslogtreecommitdiff
path: root/include/m_protomod.h
blob: 5ba369f8d51245792f533e9d49fb5bef6c3d880c (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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2008 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
//this module was created in v0.1.1.0

//this header file is for the use of protocol modules only. Other users should
//use the functions exposed in m_protocols.h and m_protosvc.h

#ifndef M_PROTOMOD_H__
#define M_PROTOMOD_H__ 1

#include <stdio.h>

#include <m_protocols.h>
#include <m_protosvc.h>

//notify the protocol manager that you're around
//wParam = 0
//lParam = (PROTOCOLDESCRIPTOR*)&descriptor
//returns 0 on success, nonzero on failure
//This service must be called in your module's Load(void) routine.
//descriptor.type can be a value other than the PROTOTYPE_ constants specified
//above to provide more precise positioning information for the contact
//protocol lists. It is strongly recommended that you give values relative to
//the constants, however, by adding or subtracting small integers ( <= 100).
//PROTOTYPE_PROTOCOL modules must not do this. The value must be exact.
//See MS_PROTO_ENUMPROTOCOLS for more notes.
#define MS_PROTO_REGISTERMODULE    "Proto/RegisterModule"

//adds the specified protocol module to the chain for a contact
//wParam = (WPARAM)(HANDLE)hContact
//lParam = (LPARAM)(const char*)szName
//returns 0 on success, nonzero on failure
//The module is added in the correct position according to the type given when
//it was registered.
#define MS_PROTO_ADDTOCONTACT      "Proto/AddToContact"

//removes the specified protocol module from the chain for a contact
//wParam = (WPARAM)(HANDLE)hContact
//lParam = (LPARAM)(const char*)szName
//returns 0 on success, nonzero on failure
#define MS_PROTO_REMOVEFROMCONTACT      "Proto/RemoveFromContact"

//Create a protocol service
//Protocol services are called with wParam and lParam as standard if they are
//to be called with CallProtoServiceInt(NULL,) (as PS_ services are)
//If they are called with CallContactService() (PSS_ and PSR_ services) then
//they are called with lParam = (CCSDATA*)&ccs and wParam an opaque internal
//reference that should be passed unchanged to MS_PROTO_CHAIN*.
__forceinline HANDLE CreateProtoServiceFunction(const char *szModule, const char *szService, MIRANDASERVICE serviceProc)
{
	char str[MAXMODULELABELLENGTH];
	_snprintf(str, sizeof(str), "%s%s", szModule, szService);
	str[MAXMODULELABELLENGTH-1] = 0;
	return CreateServiceFunction(str, serviceProc);
}

//Call the next service in the chain for this send operation
//wParam = wParam
//lParam = lParam
//The return value should be returned immediately
//wParam and lParam should be passed as the parameters that your service was
//called with. wParam must remain untouched but lParam is a CCSDATA structure
//that can be copied and modified if needed.
//Typically, the last line of any chaining protocol function is
//return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
#define MS_PROTO_CHAINSEND       "Proto/ChainSend"

//Call the next service in the chain for this receive operation
//wParam = wParam
//lParam = lParam
//The return value should be returned immediately
//wParam and lParam should be passed as the parameters that your service was
//called with. wParam must remain untouched but lParam is a CCSDATA structure
//that can be copied and modified if needed.
//When being initiated by the network-access protocol module, wParam should be
//zero.
//Thread safety: ms_proto_chainrecv is completely thread safe since 0.1.2.0
//Calls to it are translated to the main thread and passed on from there. The
//function will not return until all callees have returned, irrepective of
//differences between threads the functions are in.
#define MS_PROTO_CHAINRECV       "Proto/ChainRecv"

__forceinline INT_PTR ProtoChainRecv(HANDLE hContact, char *szService, WPARAM wParam, LPARAM lParam)
{	CCSDATA ccs = { hContact, szService, wParam, lParam };
	return CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
}

__forceinline INT_PTR ProtoChainRecvMsg(HANDLE hContact, PROTORECVEVENT *pre)
{	CCSDATA ccs = { hContact, PSR_MESSAGE, 0, (LPARAM)pre };
	return CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
}

__forceinline INT_PTR ProtoChainRecvFile(HANDLE hContact, PROTORECVFILET *pre)
{	CCSDATA ccs = { hContact, PSR_FILE, 0, (LPARAM)pre };
	return CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs);
}

//Broadcast a ME_PROTO_ACK event
//wParam = 0
//lParam = (LPARAM)(ACKDATA*)&ack
//returns the return value of the notifyeventhooks() call
//Thread safety: me_proto_ack is completely thread safe since 0.1.2.0
//See the notes in core/modules.h under NotifyEventHooks()
#define MS_PROTO_BROADCASTACK    "Proto/BroadcastAck"

__forceinline INT_PTR ProtoBroadcastAck(const char *szModule, HANDLE hContact, int type, int result, HANDLE hProcess, LPARAM lParam)
{
	ACKDATA ack = { sizeof(ACKDATA), szModule, hContact, type, result, hProcess, lParam };
	return CallService(MS_PROTO_BROADCASTACK, 0, (LPARAM)&ack);
}

/* -- Added during 0.3.4 (2004/09/27) development! -----
*/

/*
	wParam: (HANDLE)hContact
	lParam: 0
	Affect: Given a hContact, return the protocol that is registered for it, or NULL if no such protocol exists,
			the returned string does not have to be freed and is valid even for multiple threads.
	Note:	Prior to 2004/09/28 this service WAS NOT THREAD SAFE and was slower
	Note:	Prior to 2004/09/28 this service would return NULL for a hContact if the protocol module
			associated with the hContact was not currently loaded, no such check is performed now.
	Version: 0.3.4 (2004/09/28)
*/
#define MS_PROTODIR_PROTOFROMCONTACT MS_PROTO_GETCONTACTBASEPROTO

#endif // M_PROTOMOD_H__