[Nym3-commit] r17 - trunk
nym3-devel@lists.noreply.org
nym3-devel@lists.noreply.org
Thu, 13 May 2004 14:47:00 +0200
Author: jr
Date: 2004-05-13 14:47:00 +0200 (Thu, 13 May 2004)
New Revision: 17
Added:
trunk/message.ml
Log:
Beginning of the parser
types describing the commands passed between client and server, and some functions to begin to parse
Added: trunk/message.ml
===================================================================
--- trunk/message.ml 2004-05-02 21:54:59 UTC (rev 16)
+++ trunk/message.ml 2004-05-13 12:47:00 UTC (rev 17)
@@ -0,0 +1,68 @@
+(*let sign_message m () =
+ ();;*)
+
+let sig_length = 256;;
+
+
+type header = { sign : string; nl : int; nym : string; seqno : string };;
+
+let read_header buffer start len=
+ let sign = String.sub buffer start sig_length in
+ let nl = Char.code buffer.[start+sig_length] in
+ let nym = String.sub buffer (start + sig_length + 1) nl in
+ let seqno = String.sub buffer (start + sig_length + 1 + nl) 20 in
+ { sign = sign; nl = nl; nym = nym; seqno = seqno };;
+
+let make_header nym seq_no =
+ let nl = String.length nym in
+ assert( nl < 256 && String.length seq_no = 20);
+ let length = sig_length + 1 + nl + 20 in
+ let s = String.make length '\000' in
+ s.[sig_length] <- Char.chr nl;
+ String.blit nym 0 s (sig_length+1) nl;
+ String.blit seq_no 0 s (sig_length + 1 + nl) 20;
+ s;;
+
+type surb;;
+type config_option;;
+
+(*TODO describe explicitely which data corresponds to what (int * int * string) maybe isn't explicit enough *)
+(* is it necessary to separate them *)
+type command2client =
+ Create of string list (*add the proof of work too *)
+ | Create2 of string
+ | Surb of surb list
+ | Newpk of string * string
+ | Relay of int * string * string (* routing type * routing info * email body *)
+ | Get of string list
+ | Summarize of int * string
+ | Delete of string list
+ | Policy of config_option
+
+type command2server =
+ Created of string * string
+ | Status of int * int * int * int * string list (* do we use native int for 4 bytes length? *)
+ | Summary of int * string
+ | Msg of string * string
+ | Dropped of string list
+ | Error of string * string
+
+(* maybe it is too vicious to replace 2serv by C (from the client) *)
+type command =
+ CommandC of command2serv
+ | CommandS of command2client
+
+type message = header * (command list)
+
+let read_command buffer start =
+ 0,[];;
+
+let read_command_list s start =
+ let aux buffer start accu =
+ if start > (string_length buffer) then
+ accu
+ else
+ let n,e = read_command buffer start in
+ aux buffer (start + n) (e::accu)
+ in
+ aux s start [];;