Chapter 4. Frame Type 0

Table of Contents

1. Method Response
2. Hello
3. Authorization
3.1. authorize
3.2. authorize2
4. Connection State
5. Objects
6. Documents
6.1. Structure Document
6.2. Push Document
6.3. Get Document
6.4. Save Document
6.5. Remove Document
7. Files
7.1. Request File
7.2. Failed File Request
7.3. Configuration Request
7.4. Configuration Request 2 (update configuration)
7.5. Failed Config Request
8. Tasks
8.1. List of Tasks
8.2. Task Request
9. Folders
9.1. Open Folder
9.2. Close Folder
9.3. Notifications
9.4. Rename Folder
9.5. Add Document to Folder
9.6. Move Item
9.7. Remove Folder
10. Disconnect

Frame type 0 is used for generic remote procedure call - RPC. This method call is based on XML-RPC (s. http://www.xmlrpc.com/spec ). There is one xml file inside such frame which contains serialized procedure call.

This section contains description of various method which should be implemented. Most of them can be implemented by server and client, some of them only by one side. Method specification is written in pseudo "C" notation.

Every method call contains at least one parameter "ticker" - string. This parameter contains unique method call identification. Such identification can be used to pair together request and response. Every response have to also contain "ticker". Protocol is asynchronous and it is possible to send several independent requests at once.

Example 4.1. Example of method call in XMLRPC

<?xml version="1.0"?>
 <methodCall>
  <methodName>authorize</methodName>
 <params>
  <param>
   <value><string>ticker</string></value>
  </param>
  <param>
   <value><string>user</string></value>
  </param>
  <param>
   <value><string>password</string></value>
   </param>
 </params>
</methodCall>

1. Method Response

Method response is standard response as defined in XML-RPC. Each response has to contain as first parameter "ticker" which has to have same value as "ticker" send by caller. Example of metho response:

<?xml version="1.0"?>
<methodResponse>
 <params>
  <param>
   <value><string>ticker</string></value>
  </param>
  <param>
   <value><i4>130</i4></value>
  </param>
 </params> 
</methodResponse>

2. Hello

First step is to introduce client to the server. There is method called hello.

Struct HelloData {
  // Application name
  string systemName;
  // Application version
  string systemVersion,
  // Array of supported options
  array options {
    struct Option {
      // Name of option
      string name;
      // Value of option
      string value;
    };
  };
};

HelloData hello(string ticker, HelloData data);

Table 4.1. hello, parameters

ParameterDescription

data

structure describing client


Returns informations about server and its protocol implementation.

Note

For compatibility with older clients server should be able to communicate without hello call. Older client will start communication with method authorize.

List of options:

REQUEST_TASKLIST

This is server extension. Server should send it to the client if supports method requestTaskList. Value have to be 1. If server does not support this extension option is not sent or value is set to 0.

FOLDERS

This extension requires support on server and client. Both sides have to be notified about folder support. If side does not support this extension option is not sent or value is set to 0.

AUTHORIZE2

This is protocol extension. Server should send it to the client if supports method authorize2. Value has to be 1. If server does not support this extension option is not sent or value is set to 0. Client can use method authorize2 only when it is supported by server.

STOREDOCUMENT

Store document extension requires support on server and client. Both sides has to be notified about STOREDOCUMENT support. Default value is 0. Value has to be set to 1 when server or client want to use errorStoreDocument notification or send extended error messages in SaveDocument structure.

3. Authorization

Next step to establish a connection is to authorized client. This can be done by calling method authorize or authorize2.

3.1. authorize

Simple authorization by username and plaintext password.

int authorize(string ticker, string user, string password);

Table 4.2. authorize, parameters

ParameterDescription

user

user name

password

password


Return value is number. List of error codes is in the following table

Table 4.3. authorize, List of Error Codes

Error CodeDescription

0

authorized

1

wrong name or password

2

other error in login

3

rejected by server (user with same user and password is already connected from another computer)


3.2. authorize2

Extended authorization. Authorize user by username and password encrypted by selected method. (Compatibility notice AUTHORIZE2)

AuthorizeResponse authorize2(string ticker, string method, string user, string password);

Table 4.4. authorize parameters

ParameterDescription

method

authentication method (method of password encryption)

user

user name

password

password


Table 4.5. authentication methods

MethodDescription
plainplain text password
external-tokenexternal token ( send token provided by external application as password )

Return value is structure containing error code and error description. Set errorCode to 0 when authorization process was successfull.

/* AuthorizeResponse description */
struct AuthorizeResponse {
    /* error code 0-OK, >0 - fail*/ 
    int errorCode;
    /* string containing error description message */
    string errorDescription;
}

4. Connection State

Method setState allows to change connection state. Directly after authorization only one way communication is allowed (client to server). Server can send message to the client only when connection is in state '1' (default state after connection is '0').

void setState(string ticker, int iNewState);

Table 4.6. Set State, possible values

ValueDescription

0

default state, method like pushObject and pushDocument are not allowed

1

allow to receive objects, documents, ...


5. Objects

Protocol has API for object transfer. Objects are quite generic mechanism. It is possible to use them for Client to Server and also for Server to Client communication. Each object has a type and set of attributes.

/* Object description /
Struct Object {
 /* Object type */
 string type;
 /* Array of object attributes */
 array attributes { 
  /* One attribute */
  struct Attribute {
   /* Attribute name */
   string name;
   /* Attribute value */
   string value;
  };
 };
}; 

Object is send using method pushObject.

void pushObject(ticker, Object);

Method will send object. There is no return value for this method. Value can be returned by another object send in oposite direction.

6. Documents

Document is collection of pages and attributes. Protocol allows to transfer such documents.

6.1. Structure Document

Structure Document is usually used to send/receive document.

/* Document description */
Struct Document {
 /* Unique document identifacator */
 string documentId;

 /* Document version. Every document
  * can have more versions. */
 string version;

 /* Document version. This is identification
  * of subversion on server side. Client can
  * safely ignore this value and have to just
  * send it back to server. */
 string serverVersion;

 /* Document type. Document type define which
  * attributes are valid for document, how-to
  * display document and organize in logical
  * structure. Every document have to have
  * valid type. */
 string type;

 /* Document modification.
  * 0 – document is not modified
  * 1 – document attributes are modified */ 
 int modified;

 /* Document attributes. Array of document
  * attributes. Used attributes depens on document type */
 array attributes {
  /* Structure describes one attribute */
  struct Attribute {
   /* Attribute name */
   string name;
   /* Attribute value */
   string value; 
  }; 
 };

 /* Array of files, pages. */ 
 array files {
  /* Structure describing one file, page */
  struct File {
   /* Unique file (page) identifacator */
   string ident;
   /* File mime-type. */
   string mimeType;
   /* Page importance.
    * 0 – page is not important
    * 1 – page is important */
   int important;
   /* Page modification.
    * 0 – page is not modified
    * 1 – page attributes are modified
    * 2 – page data modified
    * 3 – page attributes and data modified */
   int modified;
   /* Page number */
   int pageNumber;
   /* Page notes or comments. */
   string note;
   /* Original filename. */
   string origName;
   /* Keys for page decryption/encryption. */
   string keys;
   /* Page signature. */
   string signature; 
  };
 };
};

6.2. Push Document

Document can be send from server to client using method pushDocument.

void pushDocument(string ticker, Document document, int state);

Client receiving this method call should display received document. Document can be in read-only or with full access rights.

Table 4.7. pushDocument, parameters

ParameterDescription

document

Document

state

Document state:

  • 0 - document is read-only, no changes can be send back to the server

  • 1 - document can be modified - read/write access


Note

Pushed document can have pre-set attribute modified and client should properly interpret this attribute.

Note

It is possible to send page without defined mime-type. It is useful when mime-type definition is obtain from the document store together with binary data. Such mime-type is send together with data - look in section Chapter 5, Frame Type 1. Instead of real type mime-type Tahiti/Attrs+Bin have to be set.

6.3. Get Document

Client can request document using method getDocument.

GetDocumentResponse getDocument(string ticker, string docId, string version, int state);

Table 4.8. getDocument, parameters

ParameterDescription

docId

document identifier

version

requested version, empty string means last version is requested

state

request mode (0 - read-only, 1 - read/write)


Method will return structure GetDocumentResponse. Requested document will be send using method pushDocument (Section 6.2, “Push Document”).

struct GetDocumentResponse { 
 string ticker;
 int retCode;
 string version;
} 

Item retCode is 0 if success. If method failed item retCode will be greater then 0.

Item version contains returned version ( can be used to pair pushDocument with this request ).

6.4. Save Document

Changed or new document is saved using method saveDocument. Save operation is done in three steps:

  1. Send new/changed document to the server. Server have to allocate new identifiers and send them to the client.

  2. Send binary data files

  3. Server have to send confirmation to the client about succesfull save opertaion.

Example 4.2. SaveDocument structure definition

/* Structure with newly allocated
 * Identifiers, new version
 */
Struct SaveDocument {
 /* Document state:
  * 0 – ok, 
  * 1 – lock, 
  * 2 – document not up2date, 
  * 3 – error 
  * 4 - error with detail, error details are stored in version and serverVersion fields */ 
 int state;
 /* Document identifier. This is unique
  * document identifier. If new document
  * is saved server has to generate this 
  * identifier. When error is returned this field is empty string*/
 string documentId;
 /* Identifier of new document version.
  * Each document version has unique combination of
  * docId and version. 
  * 
  * Error message is stored here when state is 4. This message will be shown in UI to user.
  */
 string version;
 /* Identifier of new server version.
  * Server version is used by optimistic 
  * server locks. 
  *
  * Detailed error message is stored here when state is 4. This message will be logged on client side and/or shown as detail or error.
  */
 string serverVersion;
 /* List of new Identifiers for files. */
 array<string> NewFileIdents;
};      

Function for saving new document or new version:

SaveDocument saveDocument(string ticker, Document document);

Structure Document is parameter of the funcion. All requested items have to be correctly filled in the structure. Document identifier is empty string if document is saved for first time (new document). Server will return new document identifier.

Page identifiers are set only for existing unmodified pages. If page is modified or new identifier is empty string.

Function will return list of new file identifiers and identifier of new document. Server behavioure:

  1. If document is requested from the server when newer version is saved last saved version will be returned.

  2. If client is trying to save new version of the document in parallel with other client lock error have to be returned. Document is unlock on succesfull save operation, on error or on time-out.

Compatibility notice: error state 4 is valid only when STOREDOCUMENT is set to 1.

Notification about succefull save operation:

void receivedDocument(string ticker, string documentId, string documentVersion);

Function has no return value and is used only for client notification.

6.4.1. Error notification

When error occur in the save operation client is notified with method errorReceivedDocument or errorStoreDocument

6.4.1.1. errorReceivedDocument

void errorReceivedDocument(string ticker, string documentId, string documentVersion, int reason);

Function has no return value and is used only for client notification. Parametr reason is used to signal error code:

Table 4.9. errorReceivedDocument parameters

ParametersDescription

documentId

id of document

documentVersion

version of document

reason

reason of fail, error code


Table 4.10. reason, list of error codes

Error CodeDescription

1

lock

2

document not up2date

3

error


6.4.1.2. errorStoreDocument

void errorStoreDocument(string ticker, string documentId, string version, int reason, string errorMessage, string errorDetail);

Function has no return value and is used only for client notification. Compatibility notice STOREDOCUMENT

Table 4.11. errorReceivedDocument parameters

ParametersDescription

documentId

id of document

documentVersion

version of document

reason

reason of fail, error code

errorMessage

error message to be presented in UI. Valid only when reason is 4.

errorDetail

detailed error message. Valid only when reason is 4.


Table 4.12. reason, list of error codes

Error CodeDescription

1

lock

2

document not up2date

3

error

4

error with description, parameters errorMessage and errorDetails are used.


6.5. Remove Document

Existing document can be deleted using method deleteDocument. Function has parameter document id as parameter.

int deleteDocument(string ticker, string documentId);

Function return 0 if success, 1 - document is locked, 2 - no permissions, 3 - other error

7. Files

Methods for file transfer.

7.1. Request File

File from server can be requested using method requestFile. When server receive such request it has to send page to the client. File is send in frame type 1 (Chapter 5, Frame Type 1).

void requestFile(string ticker, string fileId);

Table 4.13. pushDocument, parameters

ParameterDescription

fileId

File ID (Identifier). This ID have to be unique.


If file is not available server can send notification requestFileFailed (Section 7.2, “Failed File Request”).

7.2. Failed File Request

If file request (Section 7.1, “Request File”) failed other side should send response requestFileFailed. It is up to the caller to correctly display this error to the user.

void requestFileFailed(string ticker, string fileId, int errorCode, string description);

Parameter fileId is unique file identifier.

Parameter errorCode is error code.

Parameter description is error description.

7.3. Configuration Request

Configuration file can be requested using method requestConfig. Method will send configuration file to the client. File is send as frame, type 2.

void requestConfig(string ticker, string fileId);

Table 4.14. requestConfig, parameters

ParameterDescription

fileId

configuration identifier


If file is not available server can send notification requestFileFailed (Section 7.5, “Failed Config Request”).

7.4. Configuration Request 2 (update configuration)

Configuration file can be updated/requested using method requestConfig2.

void requestConfig2(string ticker, string fileId, string hashType, string fileHash)

Method will send configuration file if hash of the configuration file on the server is different from the hash of the current configuration file on the client. File is send as frame type 2. Server have to send new configuration file or respond errorRequestConfig. Method errorRequestConfig is used to signal that current configuration is up-to-date (errorCode is set to 0) or to signal wrong request (errorCode greater then 0 ).

Table 4.15. requestConfig2, parameters

ParameterDescription

fileId

configuration identifier

hashType

Type of function used to compute hash of configuration file. The only posible value is md5 for now.

fileHashHash of configuration file stored on client.

Example 4.3. requestConfig2 example

requestConfig2("ticker", "config.zip", "md5", 
               "fcd66e666a77a18ca8d08c24f40bc439");

Example requests file config.zip.


7.5. Failed Config Request

If configuration file does not exists or some other error occur server should send followinf notification about error.

void errorRequestConfig(string ticker, string fileId, int errorCode);

Table 4.16. errorRequestConfig, parameters

ParameterDescription

fileId

file identifier

errorCode

error code

  • 0 - no error, used in requestConfig2 to signal - configuration is up-to-date.

  • >0 - server specific error


8. Tasks

Methods for task management.

8.1. List of Tasks

Method requestTaskList can be used to request list of tasks.

void requestTaskList(string ticker, array<string> tasks);

Parameter tasks is list of currently available taks on the client.

Server can send list of tasks to the client using method pushTaskList.

void pushTaskList(string ticker, array<string> tasks, int flag);

Parametr tasks is list of tasks. Flag values are in the following table:

Table 4.17. flag, List of tasks

FlagDescription

1

Full List - this is full list of all tasks. Client should drop old list and use this one. This is also response on requestTaskList

2

Additional List - tasks in the list should be added to the existing list


Total number of displayed tasks on the client can be limitied in the server configuration. Tasks which client sent to the server in the requestTaskList and are not part of the response are not valid anymore and client have to delete them from UI.

8.2. Task Request

Specific task can be requested using method requestTask.

void requestTask(string ticker, string taskId);

Method request task from the server. Way of sending task to the client is up to server implementation, common way is to use method pushDocument. Server can notify about error in task request using method errorRequestTask.

void errorRequestTask(string ticker, string taskId);

9. Folders

Documents can be organized in the tree structure. There is API to manipulate with this tree ( create, change, remove folders, add items ,.. ).

Folders are quite similiar to folders on file system. Each folder has name (only root folder is empty string) and contains items. Item is document or another folder.

9.1. Open Folder

Methods allows to open folder. Client will receive for opened folder notifications about changes. Notifications are send until the folder is closed (Section 9.2, “Close Folder”).

Folder openFolder(string ticker, string folderId);

struct Folder { 
 // Status of folder 
 // -3 - no permission to open
 // -2 - folder is locked 
 // -1 - folder not exists 
 // 0 - ok
 int status;
 // Items in the folder 
 array items { 
  struct FolderItem { 
   // Type
   // 0 - folder, 1 - document
   int type;
   // Item id
   // id of folder or id of document
   string itemId;
   // Item name
   string name;
  };
 };
};

9.2. Close Folder

Close folder. Closing folder will also stop sending notifications about folder changes.

void closeFolder(string ticker, string folderId);

9.3. Notifications

Client (subscriber) will receive notification about folder changes. Following notifications are available:

  • new item in the folder

  • item was removed from the folder (or item was moved to another folder)

  • item was renamed

void updateItem(string ticker, string folderId, int oper, FolderItem item);

Function has three parameters: path, type of change, item with new data.

Possible types:

0

New item

1

Item was removed ( is no longer in the folder )

2

Item was renamed (docId is same with the original)

9.4. Rename Folder

Folder or item can be renamed using method renameItem.

int renameItem(string ticker, string parentFolderId, string itemId, string name);

parentFolderId is id of the folder.

Return values: 0 - ok, 1 - wrong id, 2 - no permissions, 3 - other error

9.5. Add Document to Folder

New document is added to the tree calling bindDocument. Document have to be saved before it can be add to the tree.

int bindDocument(string ticker, string parentFolderId, string name, string docId);

Return values: 0 - ok, 1 - wrong id, 2 - no permissions, 3 - other error

9.6. Move Item

It is possible to move any tree item to another folder. Method also allows to remove item from the tree.

int moveItem(string ticker, string parentFolderId, string itemId, string newFolderId);

parentFolderId is id of the original folder

newFolderId is id of new folder. If this parameter is empty string item will be removed from the tree.

Return values: 0 - ok, 1 - wrong id, 2 - no permissions, 3 - other error

9.7. Remove Folder

It is possible to delete folder using method removeFolder.

int removeFolder(string ticker, string folderId);

Only empty folder can be removed.

Possible return values:

  • 0 - OK

  • 1 - wrong folder ID

  • 2 - no permission

  • 3 - other error.

10. Disconnect

Before disconnect it is possible to notify other side about this event calling method disconnect.

void disconnect(int iReason, string description);

Reason of disconnect is in parameter iReason. List of possible reasons is in the table bellow.

Table 4.18. disconnect, parameters

ConstantDescription

0

timeout

1

ukonceni aplikace

2

jiný důvod, popis je uveden v proměnné description