Explorar o código

- added contional lumps support functions:
insert_cond_lump_after ( anchor, COND_TYPE, lump_type)
insert_cond_lump_before

Andrei Pelinescu-Onciul %!s(int64=22) %!d(string=hai) anos
pai
achega
73eec4b209
Modificáronse 2 ficheiros con 59 adicións e 2 borrados
  1. 54 2
      data_lump.c
  2. 5 0
      data_lump.h

+ 54 - 2
data_lump.c

@@ -28,6 +28,7 @@
  * --------
  *  2003-01-19  support for duplication lump lists added (jiri)
  *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
+ *  2003-04-01  added conditional lump suport functions (andrei)
  */
 
 
@@ -156,7 +157,7 @@ struct lump* insert_subst_lump_after( struct lump* after, enum lump_subst subst,
 										int type)
 {
 	struct lump* tmp;
-
+	
 	tmp=pkg_malloc(sizeof(struct lump));
 	if (tmp==0){
 		ser_error=E_OUT_OF_MEM;
@@ -182,7 +183,7 @@ struct lump* insert_subst_lump_before(	struct lump* before,
 										int type)
 {
 	struct lump* tmp;
-
+	
 	tmp=pkg_malloc(sizeof(struct lump));
 	if (tmp==0){
 		ser_error=E_OUT_OF_MEM;
@@ -201,6 +202,57 @@ struct lump* insert_subst_lump_before(	struct lump* before,
 
 
 
+/* inserts a  cond lump immediately after hdr 
+ * returns pointer on success, 0 on error */
+struct lump* insert_cond_lump_after( struct lump* after, enum lump_conditions c,
+										int type)
+{
+	struct lump* tmp;
+	
+	tmp=pkg_malloc(sizeof(struct lump));
+	if (tmp==0){
+		ser_error=E_OUT_OF_MEM;
+		LOG(L_ERR, "ERROR: insert_new_lump_after: out of memory\n");
+		return 0;
+	}
+	memset(tmp,0,sizeof(struct lump));
+	tmp->after=after->after;
+	tmp->type=type;
+	tmp->op=LUMP_ADD_OPT;
+	tmp->u.cond=c;
+	tmp->len=0;
+	after->after=tmp;
+	return tmp;
+}
+
+
+
+/* inserts a  conditional lump immediately before "before" 
+ * returns pointer on success, 0 on error */
+struct lump* insert_cond_lump_before(	struct lump* before, 
+										enum lump_conditions c,
+										int type)
+{
+	struct lump* tmp;
+	
+	tmp=pkg_malloc(sizeof(struct lump));
+	if (tmp==0){
+		ser_error=E_OUT_OF_MEM;
+		LOG(L_ERR,"ERROR: insert_new_lump_before: out of memory\n");
+		return 0;
+	}
+	memset(tmp,0,sizeof(struct lump));
+	tmp->before=before->before;
+	tmp->type=type;
+	tmp->op=LUMP_ADD_OPT;
+	tmp->u.cond=c;
+	tmp->len=0;
+	before->before=tmp;
+	return tmp;
+}
+
+
+
 /* removes an already existing header/data lump */
 struct lump* del_lump(struct lump** list, int offset, int len, int type)
 {

+ 5 - 0
data_lump.h

@@ -127,6 +127,11 @@ struct lump* insert_subst_lump_after(struct lump* after,  enum lump_subst subst,
 struct lump* insert_subst_lump_before(struct lump* before,enum lump_subst subst,
 									int type);
 
+/* conditional lumps */
+struct lump* insert_cond_lump_after(struct lump* after, enum lump_conditions c,
+									int type);
+struct lump* insert_cond_lump_before(struct lump* after, enum lump_conditions c,
+									int type);
 
 /* removes an already existing header */
 struct lump* del_lump(struct lump** list, int offset, int len, int type);