Browse Source

- del_nonshm_lump(lump_list) added - removes from lump's tree all lumps that
are not marked as LUMPFLAG_SHMEM.

- hdr_allocs_parse(hdr) macro added - return true if the header uses
allocated memory on parse field

Bogdan-Andrei Iancu 21 years ago
parent
commit
41f45c80b4
3 changed files with 72 additions and 3 deletions
  1. 57 0
      data_lump.c
  2. 4 0
      data_lump.h
  3. 11 3
      parser/hf.h

+ 57 - 0
data_lump.c

@@ -484,6 +484,8 @@ deeperror:
 	return 0;
 }
 
+
+
 /* shallow pkg copy of a lump list
  *
  * if either original list empty or error occur returns, 0
@@ -497,6 +499,8 @@ struct lump* dup_lump_list( struct lump *l )
 	return dup_lump_list_r(l, LD_NEXT, &deep_error);
 }
 
+
+
 void free_duped_lump_list(struct lump* l)
 {
 	struct lump *r, *foo,*crt;
@@ -530,3 +534,56 @@ void free_duped_lump_list(struct lump* l)
 	}
 }
 
+
+
+void del_nonshm_lump( struct lump** lump_list )
+{
+	struct lump *r, *foo, *crt, **prev, *prev_r;
+
+	prev = lump_list;
+	crt = *lump_list;
+
+	while (crt) {
+		if (crt->flags!=LUMPFLAG_SHMEM) {
+			/* unlink it */
+			foo = crt;
+			crt = crt->next;
+			foo->next = 0;
+			/* update the 'next' link of the previous lump */
+			*prev = crt;
+			/* entire before/after list must be removed */
+			free_lump_list( foo );
+		} else {
+			/* check on before and prev list for non-shmem lumps */
+			r = crt->after;
+			prev_r = crt;
+			while(r){
+				foo=r; r=r->after;
+				if (foo->flags!=LUMPFLAG_SHMEM) {
+					prev_r->after = r;
+					free_lump(foo);
+					pkg_free(foo);
+				} else {
+					prev_r = foo;
+				}
+			}
+			/* before */
+			r = crt->before;
+			prev_r = crt;
+			while(r){
+				foo=r; r=r->before;
+				if (foo->flags!=LUMPFLAG_SHMEM) {
+					prev_r->before = r;
+					free_lump(foo);
+					pkg_free(foo);
+				} else {
+					prev_r = foo;
+				}
+			}
+			/* go to next lump */
+			prev = &(crt->next);
+			crt = crt->next;
+		}
+	}
+}
+

+ 4 - 0
data_lump.h

@@ -77,4 +77,8 @@ struct lump* dup_lump_list( struct lump *l );
 /* frees a shallowly duplicated lump list */
 void free_duped_lump_list(struct lump* l);
 
+
+/* remove all non-SHMEM lumps from the list */
+void del_nonshm_lump( struct lump** lump_list );
+
 #endif

+ 11 - 3
parser/hf.h

@@ -57,7 +57,7 @@
 #define HDR_CONTENTLENGTH      (1 << 11)  /* Content-Length header field */
 #define HDR_AUTHORIZATION      (1 << 12)  /* Authorization header field */
 #define HDR_EXPIRES            (1 << 13)  /* Expires header field */
-#define HDR_PROXYAUTH          (1 << 14)  /* Proxy-Authorization header field */
+#define HDR_PROXYAUTH          (1 << 14)  /* Proxy-Authorization hdr field */
 #define HDR_SUPPORTED          (1 << 15)  /* Supported  header field */
 #define HDR_PROXYREQUIRE       (1 << 16)  /* Proxy-Require header field */
 #define HDR_UNSUPPORTED        (1 << 17)  /* Unsupported header field */
@@ -69,13 +69,21 @@
 #define HDR_PRIORITY           (1 << 23)  /* Priority header field */
 #define HDR_SUBJECT            (1 << 24)  /* Subject header field */
 #define HDR_USERAGENT          (1 << 25)  /* User-Agent header field */
-#define HDR_ACCEPTDISPOSITION  (1 << 26)  /* Accept-Disposition header field */
-#define HDR_CONTENTDISPOSITION (1 << 27)  /* Content-Disposition header field */
+#define HDR_ACCEPTDISPOSITION  (1 << 26)  /* Accept-Disposition hdr field */
+#define HDR_CONTENTDISPOSITION (1 << 27)  /* Content-Disposition hdr field */
 #define HDR_DIVERSION          (1 << 28)  /* Diversion header field */
 #define HDR_RPID               (1 << 29)  /* Remote-Party-ID header field */
 #define HDR_OTHER              (1 << 30)  /* Some other header field */
 
 
+/* returns true if the header links allocated memory on parse field */
+#define hdr_allocs_parse( _hdr ) \
+	(((_hdr)->type)&(HDR_VIA|HDR_TO|HDR_FROM|HDR_CONTACT|HDR_ROUTE|\
+		HDR_RECORDROUTE|HDR_AUTHORIZATION|HDR_EXPIRES|HDR_PROXYAUTH|\
+		HDR_EVENT|HDR_ACCEPT|HDR_CONTENTDISPOSITION|HDR_DIVERSION|HDR_RPID))
+
+
+
 /* 
  * Format: name':' body 
  */