Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
commands.hpp
1 //////////////////////////////
2 //
3 // File: lxs/network/commands.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Feb 15 2013
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_COMMANDS_H__
15 #define __LXS_COMMANDS_H__
16 #include <sys/socket.h>
17 
18 namespace LxS
19 {
20  namespace Network
21  {
22  //! command is really an LxS name for message sent by either server or client
23  class Command
24  {
25  int command_id;
26  int command_size; // if there is "file" associated with command,
27  // it is passed here; otherwise it is zero
28  void * data;
29  bool data_allocated;
30  void AllocateData();
31  public:
32  //! predefined list of messages
33  enum IDs
34  {
35  //! inquiry (size=0); sent by client;
36  //! list (newline separated); sent by server
38  //! followed by character data; sent by client
40  //! followed by character name; sent by client
42  //! followed by character data; sent by server
44  //! only client message, where response is not expected;
45  Bye=5,
46  //! sent by server, s answer to "ExportCharacter",
47  OK=6,
48  //! sent by server if server refused to fulfill calll.
49  //! textual message may be added in data field
51  //! not recognized by side
53  //! Access "file" for r/w (sent by client)
54  //! Read entire blob (command sent by client)
55  //! (parameter is path)
57  //! Response for FileRead command (from Server)
58  //! or followup of Writefile command (from client)
59  Blob=11,
60  //! Command sent from server - to write file (parameter is path)
62  //! sent by client or server
63  Helo=13,
64  //! login name
65  Login=14,
66  //! user password
68  //! start FS transaction (write op sequence)
70  //! end FS transaction - commit all
72  //! server side error
73  Error=18,
74  //! get timeout (in seconds)
76  //! get timeout (in seconds)
78  //! timeout value (4 bytes)
79  Timeout=21,
80  //! set password; allowed only if no user exists or
81  //! user already correctly logged in
83  };
84  Command();
85  //! get data buffer
86  void * GetData() {return data;}
87  //! set data buffer
88  void SetData(const void * d);
89  //! get command id
90  int GetCommandID() {return command_id;}
91  //! get command size (of data)
92  int GetCommandSize() {return command_size;}
93  //! set id (use enum IDs or associated)
94  void SetCommandID(int id) {command_id=id;}
95  //! set command size (of data)
96  void SetCommandSize(int siz) {command_size=siz;}
97  //! read from fd
98  int Read(int fd);
99  //! write to fd
100  int Write(int fd);
101  //! read from fd using recv routine
102  int Recv(int fd);
103  //! send to fd using send routine
104  int Send(int fd);
105  };
106  }
107 }
108 
109 
110 #endif