00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _C_PROTOCOLTLV_
00021 #define _C_PROTOCOLTLV_
00022
00023 #include "Utils.hpp"
00024 #include "C_XmlData.hpp"
00025
00026 #include "iostream_t.hpp"
00027 #include "string_t.hpp"
00028 #include "map_t.hpp"
00029 #include "C_ProtocolStats.hpp"
00030
00031 #include "C_ProtocolBinaryFrame.hpp"
00032
00033 #include "C_ProtocolContext.hpp"
00034
00035
00036 class C_ProtocolTlv : public C_ProtocolBinaryFrame {
00037
00038 public:
00039
00040 typedef enum _enum_msg_id_type {
00041 E_MSG_ID_HEADER = 0,
00042 E_MSG_ID_BODY
00043 } T_MsgIdType, *T_pMsgIdType ;
00044
00045 typedef struct _cond_value {
00046 unsigned long m_mask ;
00047 int m_f_id ;
00048 } T_CondPresence, *T_pCondPresence ;
00049
00050 typedef map_t<string_t, int> T_IdMap, *T_pIdMap ;
00051 typedef map_t<unsigned long, int> T_DecodeMap, *T_pDecodeMap ;
00052
00053 typedef struct _struct_header_field {
00054 int m_id ;
00055 char *m_name ;
00056 unsigned long m_size ;
00057 T_pCondPresence m_cond_presence ;
00058 int m_type_id;
00059 int m_counter_id;
00060 } T_HeaderField, *T_pHeaderField ;
00061
00062 typedef struct _struct_header_value {
00063 int m_id ;
00064 char *m_name ;
00065 int m_nb_set ;
00066 bool *m_value_setted ;
00067 int *m_id_value_setted ;
00068 T_pValueData m_values ;
00069 } T_HeaderValue, *T_pHeaderValue ;
00070
00071 typedef struct _struct_header_body_value {
00072 int m_id ;
00073 char *m_name ;
00074 int m_type_id ;
00075 int m_nb_set ;
00076 bool *m_value_setted ;
00077 int *m_id_value_setted ;
00078 T_pValueData m_values ;
00079 unsigned long *m_size ;
00080 bool *m_present ;
00081 } T_HeaderBodyValue, *T_pHeaderBodyValue ;
00082
00083 typedef struct _struct_protocol_counter_data {
00084 int m_id ;
00085 int m_start_id ;
00086 int m_stop_id ;
00087 } T_ProtocolCounterData, *T_pProtocolCounterData ;
00088 typedef list_t<T_ProtocolCounterData> T_ProtocolCounterDataList, *T_pProtocolCounterDataList ;
00089
00090 typedef struct _struct_body_value {
00091 int m_id ;
00092 T_Value m_value ;
00093 _struct_body_value *m_sub_val ;
00094 } T_BodyValue, *T_pBodyValue ;
00095
00096
00097 typedef struct _struct_body_def {
00098 int m_nb_values ;
00099 T_pBodyValue m_value_table ;
00100 } T_BodyValueDef, *T_pBodyValueDef ;
00101
00102
00103
00104 typedef struct _struct_management_session_id {
00105 int m_msg_id_id ;
00106 T_MsgIdType m_msg_id_type ;
00107 T_TypeType m_msg_id_value_type ;
00108 } T_ManagementSessionId, *T_pManagementSessionId;
00109
00110 typedef list_t<T_ManagementSessionId> T_ManagementSessionIdList, *T_pManagementSessionIdList ;
00111
00112
00113
00114 typedef struct _struct_update_ctxt_value {
00115 int m_nb_ctxt_id ;
00116 int *m_ctxt_id_setted ;
00117 } T_UpdateCtxtValue , *T_pUpdateCtxtValue ;
00118
00119 typedef struct _struct_update_ctxt_position {
00120 int m_nb_ctxt_pos ;
00121 int m_ctxt_id_pos ;
00122 } T_UpdateCtxtPosition , *T_pUpdateCtxtPosition ;
00123
00124
00125 C_ProtocolTlv() ;
00126 virtual void construction_data( C_XmlData *P_def,
00127 char **P_name,
00128 T_pContructorResult P_res) ;
00129
00130 ~C_ProtocolTlv() ;
00131
00132 virtual C_MessageFrame* decode_message (unsigned char *P_buffer,
00133 size_t *P_size,
00134 C_ProtocolFrame::T_pMsgError P_error) ;
00135
00136 C_ProtocolFrame::T_MsgError encode_message (C_MessageFrame *P_msg,
00137 unsigned char *P_buffer,
00138 size_t *P_buffer_size);
00139
00140 virtual C_MessageFrame* create_new_message (C_MessageFrame *P_msg);
00141 virtual C_MessageFrame* create_new_message (void *P_xml,
00142 T_pInstanceDataList P_list,
00143 int *P_nb_value);
00144 char* message_name();
00145 char* message_component_name() ;
00146 T_pNameAndIdList message_name_list () ;
00147 T_pNameAndIdList message_component_name_list () ;
00148
00149 char* message_name(int P_headerId);
00150
00151 void log_buffer (char *P_header, unsigned char *P_buf, size_t P_size);
00152
00153
00154
00155 int find_field (char *P_name);
00156 T_TypeType get_field_type (int P_id,
00157 int P_sub_id);
00158 bool check_sub_entity_needed (int P_id) ;
00159
00160 int retrieve_field_id(int P_id, T_pMsgIdType P_type);
00161
00162 void update_stats (T_ProtocolStatDataType P_type,
00163 T_ProtocolStatDataAction P_action,
00164 int P_id) ;
00165
00166
00167
00168
00169
00170 T_MsgIdType get_msg_id_type () ;
00171 int get_msg_id () ;
00172 T_TypeType get_msg_id_value_type () ;
00173
00174 T_MsgIdType get_out_of_session_id_type () ;
00175 int get_out_of_session_id () ;
00176
00177
00178 int get_header_type_id_body () ;
00179
00180 int get_header_type_id () ;
00181 int get_header_length_id () ;
00182 int get_header_length_index () ;
00183 unsigned long get_nb_field_header () ;
00184 unsigned long get_header_size () ;
00185 T_pHeaderField get_header_field_description (int P_id);
00186 T_pHeaderField get_header_field_description (char *P_name);
00187
00188 T_pHeaderValue get_header_value_description (int P_id) ;
00189
00190 T_pTypeDef get_type_description (int P_id);
00191 T_pTypeDef get_type_description (char *P_name);
00192
00193 int get_header_body_type_id () ;
00194 int get_header_body_length_id () ;
00195 int get_header_body_length_index () ;
00196 unsigned long get_nb_field_header_body () ;
00197 unsigned long get_header_body_size () ;
00198 T_pHeaderField get_header_body_field_description (int P_id);
00199 T_pHeaderField get_header_body_field_description (char *P_name);
00200
00201 T_pHeaderBodyValue get_header_body_value_description (int P_id);
00202
00203 unsigned long get_m_max_nb_field_header () ;
00204
00205
00206 char* get_header_name();
00207 char* get_header_body_name () ;
00208
00209 int get_header_value_id (char* P_name);
00210 int get_header_body_value_id (char* P_name);
00211
00212 int set_body_value(int P_id, char* P_value,
00213 int P_nb, T_pBodyValue P_res,
00214 bool *P_del = NULL);
00215
00216 int set_body_sub_value(int P_index,
00217 int P_id,
00218 char* P_value,
00219 T_pBodyValue P_res);
00220 void set_body_value(T_pBodyValue P_res, T_pBodyValue P_val);
00221
00222 void delete_header_value(T_pValueData P_res);
00223 void delete_body_value(T_pBodyValue P_res);
00224 void reset_grouped_body_value(T_pBodyValue P_res);
00225
00226
00227 void encode_header (int P_id, unsigned char*P_buf, size_t *P_size) ;
00228
00229
00230 void encode_header (int P_id,
00231 T_pValueData P_headerVal,
00232 unsigned char*P_buf, size_t *P_size,
00233 C_ProtocolContext *P_ctxt_protocol,
00234 C_ProtocolFrame::T_pMsgError P_error);
00235
00236 virtual C_ProtocolFrame::T_MsgError encode_body (int P_nbVal,
00237 T_pBodyValue P_val,
00238 unsigned char *P_buf,
00239 size_t *P_size,
00240 C_ProtocolContext *P_ctxt_protocol );
00241
00242 int decode_header (unsigned char **P_buf,
00243 size_t P_size,
00244 T_pValueData P_valDec,
00245 int *P_headerId,
00246 C_ProtocolContext *P_ctxt_protocol);
00247
00248 virtual int decode_body (unsigned char **P_buf,
00249 T_pBodyValue P_valDec,
00250 int *P_nbValDec,
00251 int *P_headerId,
00252 C_ProtocolContext *P_ctxt_protocol);
00253
00254
00255 C_ProtocolContext* create_protocol_context() ;
00256
00257 void delete_protocol_context(C_ProtocolContext** P_protocol_ctxt) ;
00258 void reset_protocol_context(C_ProtocolContext* P_protocol_context) ;
00259
00260
00261 void update_ctxt_values (C_ProtocolContext *P_protocol_context,
00262 unsigned char *P_buf_pos,
00263 int P_field_id,
00264 int P_size,
00265 T_pUpdateCtxtValue P_ctxt_id_v_table,
00266 T_pUpdateCtxtPosition P_ctxt_p_table) ;
00267
00268
00269 int update_ctxt_values_decode (C_ProtocolContext *P_protocol_context,
00270 int P_field_id,
00271 int P_size,
00272 T_pUpdateCtxtValue P_ctxt_id_v_table) ;
00273
00274
00275
00276
00277 void propagate_ctxt_global (C_ProtocolContext *P_protocol_context);
00278
00279
00280
00281 int find_header_field_id (char *P_name) ;
00282 int find_header_body_id (char *P_name) ;
00283 int find_body_value_id (char *P_name) ;
00284
00285 void get_header_values (int P_id, T_pValueData P_val);
00286 void set_header_values (T_pValueData P_dest, T_pValueData P_orig) ;
00287 void set_header_value (int P_id, T_pValueData P_dest, T_pValueData P_orig) ;
00288 void set_body_values (int P_nb, T_pBodyValue P_dest, T_pBodyValue P_orig);
00289
00290 void reset_header_values (int P_nb, T_pValueData P_val);
00291 void reset_body_values (int P_nb, T_pBodyValue P_val);
00292
00293 void get_body_values (int P_id, T_pBodyValue P_val, int *P_nbVal);
00294 virtual void get_body_value (T_pValueData P_dest, T_pBodyValue P_orig);
00295 virtual void set_body_value (T_pBodyValue P_dest, T_pValueData P_orig);
00296
00297
00298 virtual T_ManagementSessionId* get_manage_session_elt (int P_id);
00299 virtual int get_nb_management_session () ;
00300
00301 virtual bool check_present_session (int P_msg_id,int P_id) ;
00302 virtual bool find_present_session (int P_msg_id,int P_id) ;
00303
00304
00305 iostream_output& print_header(iostream_output& P_stream,
00306 int P_headerId,
00307 T_pValueData P_val) ;
00308 virtual iostream_output& print_body (iostream_output& P_stream,
00309 int P_nb,
00310 T_pBodyValue P_val,
00311 int P_level = 0) ;
00312
00313 T_TypeType get_body_value_type (int P_id);
00314 T_TypeType get_header_value_type (int P_id);
00315
00316 void reset_value_data (T_pValueData P_val) ;
00317 void convert_to_string (T_pValueData P_res,
00318 T_pValueData P_val) ;
00319
00320 void set_padding (unsigned long P_value);
00321 bool get_header_length_excluded ();
00322
00323 unsigned long get_msg_length_start ();
00324 bool get_msg_length_start_detected ();
00325
00326 bool get_complex_header_presence ();
00327 char* get_header_body_field_separator();
00328
00329
00330 int analyze_setfield(C_XmlData *P_data,
00331 int *P_fieldId,
00332 unsigned long *P_fieldValueUl) ;
00333
00334
00335
00336 protected:
00337
00338
00339 typedef map_t<string_t, int> T_LengthIdMap, *T_pLengthIdMap ;
00340 typedef list_t<int> T_IdCtxtList, *T_pIdCtxtList ;
00341
00342 T_pLengthIdMap m_length_map ;
00343 int m_length_max ;
00344 int m_nb_protocol_ctxt_values ;
00345
00346
00347 T_pUpdateCtxtValue m_header_ctxt_v_table ;
00348 T_pUpdateCtxtValue m_header_body_ctxt_v_table ;
00349
00350
00351 T_pUpdateCtxtPosition m_header_ctxt_p_table ;
00352 T_pUpdateCtxtPosition m_header_body_ctxt_p_table ;
00353
00354
00355 int update_ctxt_v_field (T_pUpdateCtxtValue P_ctxt_id_v_table,
00356 int P_nb_field,
00357 T_pProtocolCounterData P_ctxt_table,
00358 int P_nb_ctxt_table,
00359 T_pUpdateCtxtValue P_ctxt_global_v_table,
00360 int P_counter_last_id);
00361
00362
00363
00364
00365
00366
00367
00368 int ctrl_length (char *P_length_name, bool P_header) ;
00369
00370 int update_field_length (int P_length_id,
00371 int P_field_id,
00372 T_pProtocolCounterDataList P_length_list,
00373 bool P_header) ;
00374
00375
00376 void propagate_ctxt_local (C_ProtocolContext *P_protocol_context,
00377 int P_id_begin,
00378 int P_id_end,
00379 T_pHeaderField P_field_table,
00380 T_pProtocolCounterData P_ctxt_table);
00381
00382
00383 void update_ctxt_length (C_ProtocolContext *P_protocol_context,
00384 unsigned long P_valueSize);
00385
00386
00387 int update_ctxt_length_decode (C_ProtocolContext *P_protocol_context,
00388 unsigned long P_data_size) ;
00389
00390
00391 int add_length (char *P_length_name) ;
00392 int check_length (char *P_length_name);
00393 char* is_variable(char* P_varibleString) ;
00394 int add_counter_id (char *P_value_string, bool P_header) ;
00395
00396
00397 char *m_header_name ;
00398 T_pHeaderField m_header_field_table ;
00399 T_pIdMap m_header_id_map ;
00400
00401 char *m_header_type_name ;
00402 int m_header_type_id_body ;
00403
00404 int m_header_type_id;
00405 int m_header_length_id ;
00406 int m_header_length_index ;
00407 unsigned long m_nb_field_header, m_max_nb_field_header ;
00408 unsigned long m_header_size ;
00409
00410 int m_transport_type ;
00411
00412 unsigned long m_msg_length_start ;
00413 bool m_msg_length_start_detected ;
00414
00415 T_pProtocolCounterData m_header_length_table ;
00416 int m_nb_header_length_table ;
00417 int m_nb_header_length ;
00418 int m_counter_id_last_length ;
00419
00420 int m_ctxt_id_data_size ;
00421
00422 T_pProtocolCounterData m_header_body_length_table ;
00423 int m_nb_header_body_length_table ;
00424 int m_nb_header_body_length ;
00425
00426
00427 char *m_header_body_name ;
00428 T_pHeaderField m_header_body_field_table ;
00429 T_pIdMap m_header_body_id_map ;
00430
00431 int m_header_body_type_id, m_header_body_length_id ;
00432 int m_header_body_length_index;
00433 unsigned long m_nb_field_header_body ;
00434 unsigned long m_max_nb_field_header_body;
00435 unsigned long m_header_body_size ;
00436
00437 int m_header_body_start_optional_id ;
00438
00439 bool m_header_complex_type_presence ;
00440
00441
00442 T_pNameAndIdList m_message_name_list ;
00443 T_pNameAndIdList m_message_comp_name_list ;
00444
00445
00446
00447 char *m_header_body_field_separator ;
00448 int m_session_id_position ;
00449
00450
00451 T_pTypeDef m_type_def_table ;
00452 unsigned long m_nb_types, m_max_nb_types ;
00453 T_pIdMap m_type_id_map ;
00454
00455
00456 unsigned long m_nb_header_values ;
00457 T_pHeaderValue m_header_value_table ;
00458 T_pIdMap m_header_value_id_map ;
00459 T_pDecodeMap m_header_decode_map ;
00460
00461
00462
00463
00464 T_pBodyValueDef m_body_value_table ;
00465
00466
00467 unsigned long m_nb_header_body_values ;
00468 T_pHeaderBodyValue m_header_body_value_table ;
00469 T_pIdMap m_header_body_value_id_map ;
00470 T_pDecodeMap m_header_body_decode_map ;
00471
00472
00473 T_MsgIdType m_msg_id_type ;
00474 int m_msg_id_id ;
00475 T_TypeType m_msg_id_value_type ;
00476
00477
00478 T_MsgIdType m_type_id_out_of_session ;
00479 int m_id_out_of_session ;
00480
00481
00482 unsigned long m_padding_value ;
00483 bool m_header_length_excluded ;
00484
00485 int add_counter (char *P_name, unsigned long P_init) ;
00486
00487 int add_type(char *P_name, T_TypeType P_type, unsigned long P_size);
00488
00489 int add_header_field (char *P_name,
00490 unsigned long P_size,
00491 unsigned long *P_nb_field,
00492 unsigned long *P_header_size,
00493 T_pHeaderField P_field_table,
00494 T_pIdMap P_map,
00495 int P_counter_id = -1,
00496 T_pCondPresence P_condPresence = NULL,
00497 long P_type_id = -1);
00498
00499
00500 void set_header_type_id (int P_id);
00501 void set_header_length_id (int P_id);
00502
00503 void set_header_body_type_id (int P_id);
00504 void set_header_body_length_id (int P_id);
00505
00506 int get_header_from_xml (C_XmlData *P_def);
00507 int get_types_from_xml (C_XmlData *P_def);
00508
00509 virtual int xml_interpretor(C_XmlData *P_def);
00510 virtual int analyze_header_from_xml (C_XmlData *P_def);
00511 virtual int analyze_types_from_xml (C_XmlData *P_def);
00512 virtual int analyze_body_from_xml (C_XmlData *P_def);
00513
00514 int analyze_dictionnary_from_xml (C_XmlData *P_def);
00515 virtual int analyze_sessions_id_from_xml (C_XmlData *P_def) ;
00516
00517
00518 virtual int get_header_body_values_from_xml (C_XmlData *P_def);
00519 virtual int get_header_values_from_xml (C_XmlData *P_def);
00520
00521 int get_header_body_from_xml (C_XmlData *P_def);
00522 int get_header_body_optional_from_xml (C_XmlData *P_def);
00523
00524
00525
00526
00527 int get_counter_from_xml (C_XmlData *P_def);
00528
00529 bool check_presence_needed (T_pCondPresence P_condition,
00530 unsigned long *P_values);
00531
00532 int process_grouped_type(C_XmlData *P_bodyData,
00533 int P_body_grouped_val_id,
00534 T_pBodyValue P_pBodyVal);
00535
00536 list_t<C_MessageFrame*> *m_messageList;
00537
00538 } ;
00539
00540 #endif // _C_PROTOCOLTLV_
00541
00542
00543
00544
00545
00546
00547
00548
00549