Files
@ 46cc37619d68
Branch filter:
Location: libtransport.git/docs/guide/developer_lowlevel.textile
46cc37619d68
10.8 KiB
text/plain
Update skype.cpp
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | This page is useful only if you want to write backend in a language for which there's no NetworkPlugin class ready or if you just want to know what protocol Spectrum 2 uses to communicate with backends.
h2. Packets
Spectrum 2 main instance and its backends communicate using TCP socket. Packets sent over this socket are serialized using Google Protobuf library. This library has bindings (unofficial) for many programming languages.
Packets look like this:
|_. Byte|_. Description|
|0-4| Length of payload sent in this packet in network byte order as generated by uint32_t htonl(uint32_t hostlong); method.|
|4-x| WrapperMessage payload serialized using Google Protobuf.|
h3. WrapperMessage payload
This Protobuf object is used to contain payloads of different types. Every payload type has its own type and Protobuf object representing it. All payloads are explained later in this document.
All objects which can be used as payload in WrapperMessage object are declared in "include/transport/protocol.proto":https://github.com/hanzz/libtransport/blob/master/include/transport/protocol.proto.
h2. Spawning the backend
1. Spectrum 2 main instance spawns the backend when it's needed. Backend is executed with following arguments: @"--host localhost --port 32453"@.
2. Backend has to initalize itself and connect the Spectrum 2 main instance using @host@ and @port@.
3. Spectrum 2 main instance sends packet with payload of TYPE_PING (stored in WrapperMessage object).
4. Backend answers the TYPE_PING payload with TYPE_PONG payload and since the requests are forwarded to it.
h2. User wants to login the legacy network
1. @Type: TYPE_LOGIN, Payload: Login@ packet is sent to backend, backend starts connecting the user to legacy network.
2. When the user is connected, it populates his roster using @Type: TYPE_BUDDY_CHANGED, Payload: Buddy@ packets.
3. It sends @Type: TYPE_CONNECTED, Payload: Connected@ packet to Spectrum 2 main instance to inform it that user is connected to legacy network.
If something goes bad during the login process or later, backend sends @Type: TYPE_DISCONNECTED, Payload: Disconnected@ packet at any time.
h2. User wants to join the room
1. @Type: TYPE_JOIN_ROOM, Payload: Room@ packet is sent to backend, backend starts joining the user to the room.
2. Backend populates room's participant list using @Type: TYPE_PARTICIPANT_CHANGED, Payload: Participant@ packets. As last Participant it has to send the user itself.
3. Backend can change room subject using @Type: TYPE_ROOM_SUBJECT_CHANGED, Payload: ConversationMessage@.
h2. WrapperMessage payloads sent by Spectrum 2 main instance
This chapter describes all possible payloads which can be sent by Spectrum 2 main instance to backend and therefore received by backend. It also describes what should backend do when it receives payload of that type and what should sends back to Spectrum 2 main instance.
h3. Type: TYPE_PING, Payload: Nothing
Backend has to responds with @Type: TYPE_PONG, Payload: Nothing@ payload. If it does not responds in 20 seconds, it's terminated.
h3. Type: TYPE_LOGIN, Payload: Login
Backend has to login this user to legacy network. When it logins the user, it has to send @Type: TYPE_CONNECTED, Payload: Connected@ back to transport. If the backend is not able to login the user, it has to send @Type: TYPE_DISCONNECTED, Payload: Disconnected@
|_. Variable|_. Description|
|user| JID of XMPP user who wants to login|
|legacyName| Legacy network user name (for example ICQ number) of the user|
|password|Legacy network password|
h3. Type: TYPE_LOGOUT, Payload: Logout
Backend has to logout user from legacy network.
|_. Variable|_. Description|
|user| JID of XMPP user|
|legacyName| Legacy network user name (for example ICQ number) of the user|
h3. Type: TYPE_STATUS_CHANGED, Payload: Status
Backend has to change the legacy network status of this user.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|status| Status as defined by StatusType enum in protocol.proto|
|statusMessage|Status message|
h3. Type: TYPE_JOIN_ROOM, Payload: Room
Backend has to join this user to the room. Backend has to send list of participants back to Spectrum 2 using @Type: TYPE_PARTICIPANT_CHANGED, Payload: Participant@. As a last participant, the user who wanted to join the room has to be sent.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|nickname| Nickname used to join the room|
|room|Name of the room|
|password|password|
h3. Type: TYPE_LEAVE_ROOM, Payload: Room
Backend has to disconnect this user from the room.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|nickname| Nickname used to join the room|
|room|Name of the room|
h3. Type: TYPE_BUDDY_TYPING, Payload: Buddy
Backend should forward to buddy represented by buddyName information that XMPP user is typing now.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_TYPED, Payload: Buddy
Backend should forward to buddy represented by buddyName information that XMPP user paused typing now.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_STOPPED_TYPED, Payload: Buddy
Backend should forward to buddy represented by buddyName information that XMPP user stopped tying and is not typing for some time.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_REMOVED, Payload: Buddy
Backend should remove buddy from the legacy network contact list.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_CHANGED, Payload: Buddy
Backend should change the buddy alias or group according to Buddy payload. If the buddy is not stored in legacy network contact list yet, it should add it there. Backend has to send @Type: TYPE_BUDDY_CHANGED, Payload: Buddy@ back.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|alias|Alias|
|group|Group|
|blocked| True if this buddy should be blocked|
h3. Type: TYPE_ATTENTION, Payload: ConversationMessage
Backend should forward to buddy represented by buddyName information that XMPP user wants his attention.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|message| Message|
h3. Type: TYPE_CONV_MESSAGE, Payload: ConversationMessage
Backend should forward to buddy represented by buddyName message received from user.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|message|Plain text message|
|xhtml|Message formatted using XHTML-IM XEP if available|
h3. Type: TYPE_VCARD, Payload: VCard
If buddyName is empty, backend should update XMPP user's VCard according to VCard payload. If buddyName is not empty, backend has to fetch VCard of buddyName buddy including photo send it back using @Type: TYPE_VCard, Payload: Buddy@
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|id|Id used when sending the response with buddy's photo back. You have to use the same id in response as you received in request.|
|photo| Binary photo|
|nickname|Nickname|
h2. WrapperMessage payloads sent by backend
This chapter describes all possible payloads which can be sent by backend to Spectrum 2 main instance.
h3. Type: TYPE_CONV_MESSAGE, Payload: ConversationMessage
Backend sends this payload when it receives new message from legacy network which should be forwarded to XMPP user.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network who sent the message. If the conversation is room, buddyName is name of the room.|
|message|Plain text message|
|xhtml|Message formatted using XHTML-IM XEP if available|
|nickname| If the conversation is room, this is the nickname of user who sent the original message|
h3. Type: TYPE_ATTENTION, Payload: ConversationMessage
Backend sends this payload when it receives attention request from legacy network which should be forwarded to XMPP user.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|message| Message|
h3. Type: TYPE_VCARD, Payload: VCard
Backend sends this payload as a response to @Type: TYPE_VCARD, Payload: VCard@ received from main Spectrum 2 instance.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|id|You have to use the same id in response as you received in request.|
|photo| Binary photo|
|nickname|Nickname|
h3. Type: TYPE_ROOM_SUBJECT_CHANGED, Payload: ConversationMessage
Backend sends this payload when it receives room subject from legacy network which should be forwarded to XMPP user.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the room.|
|message|Plain text subject.|
|nickname| Nickname of user who set the subject.|
h3. Type: TYPE_BUDDY_TYPING, Payload: Buddy
Backend sends this payload when buddy starts typing.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_TYPED, Payload: Buddy
Backend sends this payload when buddy paused typing.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_STOPPED_TYPED, Payload: Buddy
Backend sends this payload when buddy is not typing anymore.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_BUDDY_CHANGED, Payload: Buddy
Backend sends this payload when some information about Buddy changed.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
|alias|Alias|
|group|Group|
|blocked| True if this buddy should be blocked|
h3. Type: TYPE_BUDDY_REMOVED, Payload: Buddy
Backend sends this payload when it removes buddy from legacy network contact list or the buddy gets removed from the contact lists somehow.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_AUTH_REQUEST, Payload: Buddy
Backend sends this payload when it receives authorization request from legacy network. If XMPP user accepts the authorization request, Spectrum 2 main instances sends @Type: TYPE_BUDDY_CHANGED, Payload: Buddy@ to backend, otherwise it will send @Type: TYPE_BUDDY_REMOVED, Payload: Buddy@.
|_. Variable|_. Description|
|userName| JID of XMPP user|
|buddyName| Name of the buddy in legacy network|
h3. Type: TYPE_CONNECTED, Payload: Connected
Backend sends this payload when it connects the user to legacy network.
h3. Type: TYPE_DISCONNECTED, Payload: Disconnected
Backend sends this payload when it disconnects the user from legacy network.
|