Project

General

Profile

JSON » History » Version 3

« Previous - Version 3/9 (diff) - Next » - Current version
Nevcairiel, 03/25/2010 09:47 AM


JSON

This Article introduces a new communication protocol for the core based on JSON.
JSON is a lightweight data format that is text-based and human readable to represent simple data structures.

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.

General Message Syntax

Every message follows this general syntax, and just adds new fields depending on the type.

{
  "MsgType": "..." 
}

This is Version 1 of the JSON Protocol and might as well be extended if the need arises.

Client Message Types

This is a list of message types the client should send, and the core will understand:

Init

{
  "MsgType": "ClientInit",
  "ProtocolVersion": 1
}

Login

{
  "MsgType": "ClientLogin",
  "User": "UserName",
  "Password": "Password",
}

Server Message Types

These are the messages the server sends to the client.

Responses to Init

"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.

{
  "MsgType": "ClientTooOld",
  "ProtocolVersion": 1
}

This message indicates that the core is not yet configured. Configuring is currently not possible with the JSON protocol, but might be changed.

{
  "MsgType": "CoreNotConfigured",
}

This messages indicates a successfull connection init. The Client should send login information now.

{
  "MsgType": "ClientInitAck",
  "ProtocolVersion": 1,
}

Responses to Login

General purpose error if a client trys to login (or send anything besides ClientInit) without initializing before.

{
  "MsgType": "ClientNotInitialized",
}

The user details have not been accepted by the core.

{
  "MsgType": "ClientLoginReject",
}

The login was successfull and the session was established.

{
  "MsgType": "ClientLoginAck",
}

Session

The Core will send the following message after login when the session is initialized.

{
  "MsgType": "SessionInit",
  "SessionState": {
    "Networks": {
      "<networkname>": {
        "Id": <netid>, 
        "StatusBuffer": <bufferid>, 
        "Buffers": {
          "<buffername>": { "Id": <bufferid>, "Type": "Channel|Query|Group|Status|Invalid" },
          "<buffername>": { ... }
        }
      },
      "<networkname>": { ... },   
    ]
  }
}

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.

Messages

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.

This message will be send for a chat event while the client is connected:

{
  "MsgType": "Message",
  "Data": {
    "MsgId": <id>,
    "BufId": <bufferid>,
    "Type": <msgtype>,
    "Time": <unix timestamp>,
    "Sender": "<sender>",
    "Contents": "<message>",
  }
}

As a next step we'll need to define messages to request backlog and actually send commands to the core.