The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cstringframe.c
Go to the documentation of this file.
1 
26 #include <string.h>
27 #include <projectcommon.h>
28 #include <frameset.h>
29 #include <cstringframe.h>
30 #include <frametypes.h>
31 #include <generic_tlv_min.h>
32 #include <tlvhelper.h>
33 
35 
50 FSTATIC gboolean _cstringframe_default_isvalid(const Frame *, gconstpointer, gconstpointer);
51 FSTATIC gchar* _cstringframe_toString(gconstpointer);
52 
57 
59 FSTATIC gboolean
61  gconstpointer tlvptr,
62  gconstpointer pktend)
63 {
64  gsize length;
65  const guint8* stringstart;
66  const guint8* endplace;
67  const guint8* expectedplace;
68 
69  (void)self;
70  if (tlvptr == NULL) {
71  if (NULL == self->value) {
72  return FALSE;
73  }
74  length = self->length;
75  stringstart = self->value;
76  }else{
77  length = get_generic_tlv_len(tlvptr, pktend);
78  stringstart = get_generic_tlv_value(tlvptr, pktend);
79  g_return_val_if_fail(NULL != tlvptr, FALSE);
80  g_return_val_if_fail(NULL != pktend, FALSE);
81  g_return_val_if_fail(length > 0, FALSE);
82  }
83  endplace = stringstart + length;
84  expectedplace = endplace-1;
85  return expectedplace == memchr(stringstart, 0x00, length);
86 }
87 
88 FSTATIC
89 gchar*
90 _cstringframe_toString(gconstpointer obj)
91 {
92  const CstringFrame* self = CASTTOCONSTCLASS(CstringFrame, obj);
93  return g_strdup_printf("CstringFrame(%d, \"%s\")"
94  , self->baseclass.type, (gchar*)self->baseclass.value);
95 }
96 
97 
101 cstringframe_new(guint16 frame_type,
102  gsize framesize)
103 {
104  Frame* baseframe;
105 
107  if (framesize < sizeof(CstringFrame)){
108  framesize = sizeof(CstringFrame);
109  }
110 
111  baseframe = frame_new(frame_type, framesize);
112  if (framesize == sizeof(CstringFrame)) {
113  DEBUGMSG5("%s: Constructing New CstringFrame at 0x%p", __FUNCTION__, baseframe);
114  }
117  return NEWSUBCLASS(CstringFrame, baseframe);
118 
119 }
124 cstringframe_tlvconstructor(gconstpointer tlvstart,
125  gconstpointer pktend,
126  gpointer* ignorednewpkt,
127  gpointer* ignoredpktend)
128 {
129  guint16 frametype = get_generic_tlv_type(tlvstart, pktend);
130  guint32 framelength = get_generic_tlv_len(tlvstart, pktend);
131  const guint8* framevalue = get_generic_tlv_value(tlvstart, pktend);
132  CstringFrame * ret = cstringframe_new(frametype, 0);
133  Frame * fret = CASTTOCLASS(Frame, ret);
134 
135  (void)ignorednewpkt; (void)ignoredpktend;
136  g_return_val_if_fail(ret != NULL, NULL);
137 
138  ret->baseclass.length = framelength;
139  ret->baseclass.setvalue(fret, g_memdup(framevalue, framelength), framelength, frame_default_valuefinalize);
140  return fret;
141 }
guint32 length
Frame Length.
Definition: frame.h:46
AssimObj baseclass
Base object class for our Class system.
Definition: frame.h:44
Implements minimal client-oriented Frame and Frameset capabilities.
WINEXPORT Frame * cstringframe_tlvconstructor(gconstpointer tlvstart, gconstpointer pktend, gpointer *ignorednewpkt, gpointer *ignoredpktend)
Given marshalled packet data corresponding to an CstringFrame (C-style string), return the correspond...
Definition: cstringframe.c:124
This is the base Frame class object (in-memory TLV (type, length, value)) for every general component...
Definition: frame.h:43
#define DEBUGMSG5(...)
Definition: proj_classes.h:93
Describes interfaces to C-String Frame (Cstringframe) C-Class It holds conventional zero-terminated b...
#define WINEXPORT
Definition: projectcommon.h:45
#define FSTATIC
Definition: projectcommon.h:31
DEBUGDECLARATIONS
Definition: cstringframe.c:34
guint16 get_generic_tlv_type(gconstpointer tlv_vp, gconstpointer pktend)
Return the 'Type' of the given TLV TLV entry (first two bytes)
#define BINDDEBUG(Cclass)
BINDDEBUG is for telling the class system where the debug variable for this class is - put it in the ...
Definition: proj_classes.h:82
#define __FUNCTION__
Frame * frame_new(guint16 frame_type, gsize framesize)
Construct a new frame - allowing for "derived" frame types...
Definition: frame.c:124
gboolean(* isvalid)(const Frame *self, gconstpointer tlvptr, gconstpointer pktend)
TRUE if TLV data looks valid...
Definition: frame.h:50
#define CASTTOCONSTCLASS(Cclass, obj)
Safely cast 'obj' to const C-class 'class' - verifying that it was registered as being of type class ...
Definition: proj_classes.h:71
This is our CstringFrame class object - used for holding C-style NULL terminated strings.
Definition: cstringframe.h:36
guint32 get_generic_tlv_len(gconstpointer tlv_vp, gconstpointer pktend)
Return the 'Length' of the given generic TLV entry (first 3 bytes after type)
Project common header file.
Header file defining the data layouts for our Frames.
TLV helper interfaces definitions.
FSTATIC void frame_default_valuefinalize(gpointer value)
Finalize a Frame.
Definition: frame.c:56
Provides definitions for using our generic TLV capabilities.
gconstpointer get_generic_tlv_value(gconstpointer tlv_vp, gconstpointer pktend)
Return a const pointer to the 'Value' of the given generic TLV entry.
gchar *(* toString)(gconstpointer)
Produce malloc-ed string representation.
Definition: assimobj.h:58
struct _CstringFrame CstringFrame
Definition: cstringframe.h:31
void(* setvalue)(Frame *self, gpointer value, guint32 length, GDestroyNotify valfinal)
member function for setting value
Definition: frame.h:52
FSTATIC gchar * _cstringframe_toString(gconstpointer)
Definition: cstringframe.c:90
#define CASTTOCLASS(Cclass, obj)
Safely cast 'obj' to C-class 'class' - verifying that it was registerd as being of type class ...
Definition: proj_classes.h:66
#define NEWSUBCLASS(Cclass, obj)
Definition: proj_classes.h:67
FSTATIC gboolean _cstringframe_default_isvalid(const Frame *, gconstpointer, gconstpointer)
CstringFrame class 'isvalid' member function (checks for valid C-style string)
Definition: cstringframe.c:60
WINEXPORT CstringFrame * cstringframe_new(guint16 frame_type, gsize framesize)
Construct a new CstringFrame - allowing for "derived" frame types...
Definition: cstringframe.c:101