Project

General

Profile

JSON » History » Version 5

Nevcairiel, 03/25/2010 09:52 AM

1 1 Nevcairiel
h1. JSON
2 1 Nevcairiel
3 5 Nevcairiel
NOTE:
4 5 Nevcairiel
This is not in the main quassel distribution, and it will probably be a long time until it gets there (if ever).
5 5 Nevcairiel
This article is here for discussion purposes only.
6 5 Nevcairiel
7 5 Nevcairiel
h3. Abstract
8 5 Nevcairiel
9 4 Nevcairiel
This Article introduces a new communication protocol being developed for the core based on JSON.
10 1 Nevcairiel
JSON is a lightweight data format that is text-based and human readable to represent simple data structures.
11 1 Nevcairiel
12 1 Nevcairiel
A JSON library exists for most programming languages, so its really easy to use from any platform, which was the main motivation behind this project - enabling developers to write a Quassel Client without the lockin to Qt based systems.
13 5 Nevcairiel
14 1 Nevcairiel
15 1 Nevcairiel
h2. General Message Syntax
16 1 Nevcairiel
17 1 Nevcairiel
Every message follows this general syntax, and just adds new fields depending on the type.
18 1 Nevcairiel
19 1 Nevcairiel
<pre>
20 1 Nevcairiel
{
21 1 Nevcairiel
  "MsgType": "..."
22 1 Nevcairiel
}
23 1 Nevcairiel
</pre>
24 1 Nevcairiel
25 1 Nevcairiel
This is Version 1 of the JSON Protocol and might as well be extended if the need arises.
26 1 Nevcairiel
27 1 Nevcairiel
h2. Client Message Types
28 1 Nevcairiel
29 1 Nevcairiel
This is a list of message types the client should send, and the core will understand:
30 1 Nevcairiel
31 1 Nevcairiel
h3. Init
32 2 Nevcairiel
33 1 Nevcairiel
<pre>
34 1 Nevcairiel
{
35 1 Nevcairiel
  "MsgType": "ClientInit",
36 1 Nevcairiel
  "ProtocolVersion": 1
37 1 Nevcairiel
}
38 1 Nevcairiel
</pre>
39 1 Nevcairiel
40 1 Nevcairiel
h3. Login
41 2 Nevcairiel
42 1 Nevcairiel
<pre>
43 1 Nevcairiel
{
44 1 Nevcairiel
  "MsgType": "ClientLogin",
45 1 Nevcairiel
  "User": "UserName",
46 1 Nevcairiel
  "Password": "Password",
47 1 Nevcairiel
}
48 1 Nevcairiel
</pre>
49 1 Nevcairiel
50 1 Nevcairiel
h2. Server Message Types
51 1 Nevcairiel
52 1 Nevcairiel
These are the messages the server sends to the client.
53 1 Nevcairiel
54 1 Nevcairiel
h3. Responses to Init
55 1 Nevcairiel
56 1 Nevcairiel
"ClientTooOld" indicates that the client is using a protocol version that is too old for this core. The ProtocolVersion argument is the current version of the core.
57 1 Nevcairiel
<pre>
58 1 Nevcairiel
{
59 1 Nevcairiel
  "MsgType": "ClientTooOld",
60 1 Nevcairiel
  "ProtocolVersion": 1
61 1 Nevcairiel
}
62 1 Nevcairiel
</pre>
63 1 Nevcairiel
64 1 Nevcairiel
This message indicates that the core is not yet configured. Configuring is currently not possible with the JSON protocol, but might be changed.
65 1 Nevcairiel
66 1 Nevcairiel
<pre>
67 1 Nevcairiel
{
68 1 Nevcairiel
  "MsgType": "CoreNotConfigured",
69 1 Nevcairiel
}
70 3 Nevcairiel
</pre>
71 1 Nevcairiel
72 1 Nevcairiel
This messages indicates a successfull connection init. The Client should send login information now.
73 1 Nevcairiel
<pre>
74 1 Nevcairiel
{
75 1 Nevcairiel
  "MsgType": "ClientInitAck",
76 1 Nevcairiel
  "ProtocolVersion": 1,
77 1 Nevcairiel
}
78 1 Nevcairiel
</pre>
79 1 Nevcairiel
80 1 Nevcairiel
h3. Responses to Login
81 1 Nevcairiel
82 1 Nevcairiel
General purpose error if a client trys to login (or send anything besides ClientInit) without initializing before.
83 1 Nevcairiel
<pre>
84 1 Nevcairiel
{
85 1 Nevcairiel
  "MsgType": "ClientNotInitialized",
86 1 Nevcairiel
}
87 3 Nevcairiel
</pre>
88 1 Nevcairiel
89 1 Nevcairiel
The user details have not been accepted by the core.
90 1 Nevcairiel
<pre>
91 1 Nevcairiel
{
92 1 Nevcairiel
  "MsgType": "ClientLoginReject",
93 1 Nevcairiel
}
94 1 Nevcairiel
</pre>
95 1 Nevcairiel
96 1 Nevcairiel
The login was successfull and the session was established.
97 1 Nevcairiel
<pre>
98 1 Nevcairiel
{
99 1 Nevcairiel
  "MsgType": "ClientLoginAck",
100 1 Nevcairiel
}
101 1 Nevcairiel
</pre>
102 1 Nevcairiel
103 1 Nevcairiel
h3. Session
104 1 Nevcairiel
105 1 Nevcairiel
The Core will send the following message after login when the session is initialized.
106 1 Nevcairiel
107 1 Nevcairiel
<pre>
108 1 Nevcairiel
{
109 1 Nevcairiel
  "MsgType": "SessionInit",
110 1 Nevcairiel
  "SessionState": {
111 1 Nevcairiel
    "Networks": {
112 1 Nevcairiel
      "<networkname>": {
113 1 Nevcairiel
        "Id": <netid>, 
114 1 Nevcairiel
        "StatusBuffer": <bufferid>, 
115 1 Nevcairiel
        "Buffers": {
116 1 Nevcairiel
          "<buffername>": { "Id": <bufferid>, "Type": "Channel|Query|Group|Status|Invalid" },
117 1 Nevcairiel
          "<buffername>": { ... }
118 1 Nevcairiel
        }
119 1 Nevcairiel
      },
120 1 Nevcairiel
      "<networkname>": { ... },   
121 1 Nevcairiel
    ]
122 1 Nevcairiel
  }
123 1 Nevcairiel
}
124 1 Nevcairiel
</pre>
125 1 Nevcairiel
126 1 Nevcairiel
In protocol version 1, different chatview configurations are not yet supported, every network and every buffer known to this core account will be shown. This is planned to be changed in the future.
127 1 Nevcairiel
128 1 Nevcairiel
h3. Messages
129 1 Nevcairiel
130 1 Nevcairiel
NOTE: This message type is a temporary message for testing the message sending capabilities, and will change. But for discussions of the protocol, its added here as well.
131 1 Nevcairiel
132 1 Nevcairiel
This message will be send for a chat event while the client is connected:
133 1 Nevcairiel
134 1 Nevcairiel
<pre>
135 1 Nevcairiel
{
136 1 Nevcairiel
  "MsgType": "Message",
137 1 Nevcairiel
  "Data": {
138 1 Nevcairiel
    "MsgId": <id>,
139 1 Nevcairiel
    "BufId": <bufferid>,
140 1 Nevcairiel
    "Type": <msgtype>,
141 1 Nevcairiel
    "Time": <unix timestamp>,
142 1 Nevcairiel
    "Sender": "<sender>",
143 1 Nevcairiel
    "Contents": "<message>",
144 1 Nevcairiel
  }
145 1 Nevcairiel
}
146 1 Nevcairiel
</pre>
147 1 Nevcairiel
148 1 Nevcairiel
As a next step we'll need to define messages to request backlog and actually send commands to the core.