Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#ifndef _BYTEORDER_H
+#define _BYTEORDER_H
+
/*
This file implements macros for machine independent short and
int manipulation
SIVALS(buf,pos,val) - signed version of SIVAL()
RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
+RSVALS(buf,pos) - like SVALS() but for NMB byte ordering
RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
+RIVALS(buf,pos) - like IVALS() but for NMB byte ordering
RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
+RSIVALS(buf,pos,val) - like SIVALS() but for NMB ordering
it also defines lots of intermediate macros, just ignore those :-)
/* some switch macros that do both store and read to and from SMB buffers */
#define RW_PCVAL(read,inbuf,outbuf,len) \
- if (read) { PCVAL (inbuf,0,outbuf,len) } \
- else { PSCVAL(inbuf,0,outbuf,len) }
+ { if (read) { PCVAL (inbuf,0,outbuf,len); } \
+ else { PSCVAL(inbuf,0,outbuf,len); } }
-#define RW_PIVAL(read,inbuf,outbuf,len) \
- if (read) { PIVAL (inbuf,0,outbuf,len) } \
- else { PSIVAL(inbuf,0,outbuf,len) }
+#define RW_PIVAL(read,big_endian,inbuf,outbuf,len) \
+ { if (read) { if (big_endian) { RPIVAL(inbuf,0,outbuf,len); } else { PIVAL(inbuf,0,outbuf,len); } } \
+ else { if (big_endian) { RPSIVAL(inbuf,0,outbuf,len); } else { PSIVAL(inbuf,0,outbuf,len); } } }
-#define RW_PSVAL(read,inbuf,outbuf,len) \
- if (read) { PSVAL (inbuf,0,outbuf,len) } \
- else { PSSVAL(inbuf,0,outbuf,len) }
+#define RW_PSVAL(read,big_endian,inbuf,outbuf,len) \
+ { if (read) { if (big_endian) { RPSVAL(inbuf,0,outbuf,len); } else { PSVAL(inbuf,0,outbuf,len); } } \
+ else { if (big_endian) { RPSSVAL(inbuf,0,outbuf,len); } else { PSSVAL(inbuf,0,outbuf,len); } } }
#define RW_CVAL(read, inbuf, outbuf, offset) \
- if (read) (outbuf) = CVAL (inbuf,offset); \
- else SCVAL(inbuf,offset,outbuf);
+ { if (read) { (outbuf) = CVAL (inbuf,offset); } \
+ else { SCVAL(inbuf,offset,outbuf); } }
-#define RW_IVAL(read, inbuf, outbuf, offset) \
- if (read) (outbuf)= IVAL (inbuf,offset); \
- else SIVAL(inbuf,offset,outbuf);
+#define RW_IVAL(read, big_endian, inbuf, outbuf, offset) \
+ { if (read) { (outbuf) = ((big_endian) ? RIVAL(inbuf,offset) : IVAL (inbuf,offset)); } \
+ else { if (big_endian) { RSIVAL(inbuf,offset,outbuf); } else { SIVAL(inbuf,offset,outbuf); } } }
-#define RW_SVAL(read, inbuf, outbuf, offset) \
- if (read) (outbuf)= SVAL (inbuf,offset); \
- else SSVAL(inbuf,offset,outbuf);
+#define RW_SVAL(read, big_endian, inbuf, outbuf, offset) \
+ { if (read) { (outbuf) = ((big_endian) ? RSVAL(inbuf,offset) : SVAL (inbuf,offset)); } \
+ else { if (big_endian) { RSSVAL(inbuf,offset,outbuf); } else { SSVAL(inbuf,offset,outbuf); } } }
#undef CAREFUL_ALIGNMENT
#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
-#else
+#else /* CAREFUL_ALIGNMENT */
/* this handles things for architectures like the 386 that can handle
alignment errors */
#define SVALS(buf,pos) (*(const int16 *)((const char *)(buf) + (pos)))
#define IVALS(buf,pos) (*(const int32 *)((const char *)(buf) + (pos)))
+/* store single value in an SMB buffer */
#define SVALMOD(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
#define IVALMOD(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
-#define SVALMODS(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
-#define IVALMODS(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
+#define SVALSMOD(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
+#define IVALSMOD(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
-/* store single value in an SMB buffer */
#define SSVAL(buf,pos,val) SVALMOD(buf,pos)=((uint16)(val))
#define SIVAL(buf,pos,val) IVALMOD(buf,pos)=((uint32)(val))
-#define SSVALS(buf,pos,val) SVALMODS(buf,pos)=((int16)(val))
-#define SIVALS(buf,pos,val) IVALMODS(buf,pos)=((int32)(val))
-
-#endif
+#define SSVALS(buf,pos,val) SVALSMOD(buf,pos)=((int16)(val))
+#define SIVALS(buf,pos,val) IVALSMOD(buf,pos)=((int32)(val))
+#endif /* CAREFUL_ALIGNMENT */
/* macros for reading / writing arrays */
#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
#define RSVAL(buf,pos) SREV(SVAL(buf,pos))
+#define RSVALS(buf,pos) SREV(SVALS(buf,pos))
#define RIVAL(buf,pos) IREV(IVAL(buf,pos))
+#define RIVALS(buf,pos) IREV(IVALS(buf,pos))
#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
+#define RSSVALS(buf,pos,val) SSVALS(buf,pos,SREV(val))
#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))
+#define RSIVALS(buf,pos,val) SIVALS(buf,pos,IREV(val))
+
+/* reads multiple data from an SMB buffer (big-endian) */
+#define RPSVAL(buf,pos,val,len) SMBMACRO(RSVAL,buf,pos,val,len,2)
+#define RPIVAL(buf,pos,val,len) SMBMACRO(RIVAL,buf,pos,val,len,4)
+#define RPSVALS(buf,pos,val,len) SMBMACRO(RSVALS,buf,pos,val,len,2)
+#define RPIVALS(buf,pos,val,len) SMBMACRO(RIVALS,buf,pos,val,len,4)
+
+/* stores multiple data in an SMB buffer (big-endian) */
+#define RPSSVAL(buf,pos,val,len) SSMBMACRO(RSSVAL,buf,pos,val,len,2)
+#define RPSIVAL(buf,pos,val,len) SSMBMACRO(RSIVAL,buf,pos,val,len,4)
+#define RPSSVALS(buf,pos,val,len) SSMBMACRO(RSSVALS,buf,pos,val,len,2)
+#define RPSIVALS(buf,pos,val,len) SSMBMACRO(RSIVALS,buf,pos,val,len,4)
#define DBG_RW_PCVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
- RW_PCVAL(read,inbuf,outbuf,len) \
- DEBUG(10,("%s%04x %s: ", \
+ { RW_PCVAL(read,inbuf,outbuf,len) \
+ DEBUG(5,("%s%04x %s: ", \
tab_depth(depth), base,string)); \
- if (charmode) print_asc(10, (unsigned char*)(outbuf), (len)); else \
- { uint32 idx; for (idx = 0; idx < (uint32)(len); idx++) { DEBUGADD(10,("%02x ", (outbuf)[idx])); } } \
- DEBUG(10,("\n"));
+ if (charmode) print_asc(5, (unsigned char*)(outbuf), (len)); else \
+ { uint32 idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%02x ", (outbuf)[idx])); } } \
+ DEBUG(5,("\n")); }
-#define DBG_RW_PSVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
- RW_PSVAL(read,inbuf,outbuf,len) \
- DEBUG(10,("%s%04x %s: ", \
+#define DBG_RW_PSVAL(charmode,string,depth,base,read,big_endian,inbuf,outbuf,len) \
+ { RW_PSVAL(read,big_endian,inbuf,outbuf,len) \
+ DEBUG(5,("%s%04x %s: ", \
tab_depth(depth), base,string)); \
- if (charmode) print_asc(10, (unsigned char*)(outbuf), 2*(len)); else \
- { uint32 idx; for (idx = 0; idx < (uint32)(len); idx++) { DEBUGADD(10,("%04x ", (outbuf)[idx])); } } \
- DEBUG(10,("\n"));
+ if (charmode) print_asc(5, (unsigned char*)(outbuf), 2*(len)); else \
+ { uint32 idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%04x ", (outbuf)[idx])); } } \
+ DEBUG(5,("\n")); }
-#define DBG_RW_PIVAL(charmode,string,depth,base,read,inbuf,outbuf,len) \
- RW_PIVAL(read,inbuf,outbuf,len) \
- DEBUG(10,("%s%04x %s: ", \
+#define DBG_RW_PIVAL(charmode,string,depth,base,read,big_endian,inbuf,outbuf,len) \
+ { RW_PIVAL(read,big_endian,inbuf,outbuf,len) \
+ DEBUG(5,("%s%04x %s: ", \
tab_depth(depth), base,string)); \
- if (charmode) print_asc(10, (unsigned char*)(outbuf), 4*(len)); else \
- { uint32 idx; for (idx = 0; idx < (uint32)(len); idx++) { DEBUGADD(10,("%08x ", (outbuf)[idx])); } } \
- DEBUG(10,("\n"));
+ if (charmode) print_asc(5, (unsigned char*)(outbuf), 4*(len)); else \
+ { uint32 idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%08x ", (outbuf)[idx])); } } \
+ DEBUG(5,("\n")); }
#define DBG_RW_CVAL(string,depth,base,read,inbuf,outbuf) \
- RW_CVAL(read,inbuf,outbuf,0) \
- DEBUG(10,("%s%04x %s: %02x\n", \
- tab_depth(depth), base, string, outbuf));
+ { RW_CVAL(read,inbuf,outbuf,0) \
+ DEBUG(5,("%s%04x %s: %02x\n", \
+ tab_depth(depth), base, string, outbuf)); }
-#define DBG_RW_SVAL(string,depth,base,read,inbuf,outbuf) \
- RW_SVAL(read,inbuf,outbuf,0) \
- DEBUG(10,("%s%04x %s: %04x\n", \
- tab_depth(depth), base, string, outbuf));
+#define DBG_RW_SVAL(string,depth,base,read,big_endian,inbuf,outbuf) \
+ { RW_SVAL(read,big_endian,inbuf,outbuf,0) \
+ DEBUG(5,("%s%04x %s: %04x\n", \
+ tab_depth(depth), base, string, outbuf)); }
-#define DBG_RW_IVAL(string,depth,base,read,inbuf,outbuf) \
- RW_IVAL(read,inbuf,outbuf,0) \
- DEBUG(10,("%s%04x %s: %08x\n", \
- tab_depth(depth), base, string, outbuf));
+#define DBG_RW_IVAL(string,depth,base,read,big_endian,inbuf,outbuf) \
+ { RW_IVAL(read,big_endian,inbuf,outbuf,0) \
+ DEBUG(5,("%s%04x %s: %08x\n", \
+ tab_depth(depth), base, string, outbuf)); }
+#endif /* _BYTEORDER_H */
ps->align = align;
ps->offset = 0;
ps->error = False;
+ ps->bigendian = False;
ps->data = NULL;
ps->data_size = 0;
- ps->struct_end = 0xdcdcdcdc;
ps->start = 0;
ps->end = 0;
ps->next = NULL;
+ ps->struct_end = 0xdcdcdcdc;
+
if (size != 0)
{
prs_realloc_data(ps, size);
CHECK_STRUCT(ps);
}
+/*******************************************************************
+ set the packed data representation type in a parse structure
+ ********************************************************************/
+void prs_set_packtype(prs_struct *ps, const uint8 *pack_type)
+{
+ CHECK_STRUCT(ps);
+ ps->bigendian = pack_type[0] == 0x0;
+}
+
/*******************************************************************
create a parse structure
********************************************************************/
CHECK_STRUCT(ps);
CHECK_STRUCT(from);
prs_init(ps, len, from->align, from->io);
+ ps->bigendian = from->bigendian;
if (len != 0)
{
if (ps->data == NULL)
return False;
}
- DBG_RW_SVAL(name, depth, ps->offset, ps->io, q, *data16)
+ DBG_RW_SVAL(name, depth, ps->offset, ps->io, ps->bigendian, q, *data16)
ps->offset += 2;
return True;
return False;
}
- DBG_RW_IVAL(name, depth, ps->offset, ps->io, q, *data32)
+ DBG_RW_IVAL(name, depth, ps->offset, ps->io, ps->bigendian, q, *data32)
ps->offset += 4;
return True;
return False;
}
- DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, q, data16s, len)
+ DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, ps->bigendian, q, data16s, len)
ps->offset = end_offset;
return True;
return False;
}
- DBG_RW_PIVAL(charmode, name, depth, ps->offset, ps->io, q, data32s, len)
+ DBG_RW_PIVAL(charmode, name, depth, ps->offset, ps->io, ps->bigendian, q, data32s, len)
ps->offset = end_offset;
return True;
return False;
}
- DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, q, str->buffer, str->uni_str_len)
+ DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, ps->bigendian, q, str->buffer, str->uni_str_len)
ps->offset = end_offset;
return True;
return False;
}
- DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, q, str->str.buffer, str->uni_str_len)
+ DBG_RW_PSVAL(charmode, name, depth, ps->offset, ps->io, ps->bigendian, q, str->str.buffer, str->uni_str_len)
ps->offset = end_offset;
return True;
prs_debug_out(ps, "_prs_unistr error", 5);
return False;
}
- RW_SVAL(ps->io, q, str->buffer[i],0);
+ RW_SVAL(ps->io, ps->bigendian, q, str->buffer[i],0);
}
while ((((size_t)i) < sizeof(str->buffer) / sizeof(str->buffer[0])) &&
(str->buffer[i] != 0));