Browse code

Replaced rpc->struct_add by rpc->printf for view functions. If the cache/blacklist contained many entries then SER had problem with number of chunks. The solution with printf is working for 8000 entries in the blacklist without any problem.

Vladimir Marek authored on 06/09/2007 15:11:09
Showing 2 changed files
... ...
@@ -86,6 +86,7 @@
86 86
 #define DEFAULT_DNS_TIMER_INTERVAL 120  /* 2 min. */
87 87
 #define DNS_HE_MAX_ADDR 10  /* maxium addresses returne in a hostent struct */
88 88
 #define MAX_CNAME_CHAIN  10
89
+#define SPACE_FORMAT "    " /* format of view output */
89 90
 
90 91
 
91 92
 static gen_lock_t* dns_hash_lock=0;
... ...
@@ -3315,87 +3316,83 @@ static char *print_type(unsigned short type)
3315 3315
 /* dumps the content of the cache in a human-readable format */
3316 3316
 void dns_cache_view(rpc_t* rpc, void* ctx)
3317 3317
 {
3318
-	int h;
3319
-	struct dns_hash_entry* e;
3320
-	struct dns_rr* rr;
3321
-	struct ip_addr ip;
3322
-	ticks_t now;
3323
-	void* handle;
3324
-	str s;
3325
-
3326
-	now=get_ticks_raw();
3327
-	LOCK_DNS_HASH();
3328
-		for (h=0; h<DNS_HASH_SIZE; h++){
3329
-			clist_foreach(&dns_hash[h], e, next){
3330
-				rpc->add(ctx, "{", &handle);
3331
-				rpc->struct_add(handle, "s", "name", e->name);
3332
-				rpc->struct_add(handle, "s", "type", print_type(e->type));
3333
-				rpc->struct_add(handle, "d", "size (bytes)", e->total_size);
3334
-				rpc->struct_add(handle, "d", "reference counter", e->refcnt.val);
3335
-				rpc->struct_add(handle, "d", "expires in (s)", (s_ticks_t)(e->expire-now)<0?-1:
3336
-									TICKS_TO_S(e->expire-now));
3337
-				rpc->struct_add(handle, "d", "last used (s)", TICKS_TO_S(now-e->last_used));
3338
-				rpc->struct_add(handle, "d", "error flags", e->err_flags);
3339
-
3340
-				for (rr=e->rr_lst; rr; rr=rr->next){
3341
-					switch(e->type){
3342
-						case T_A:
3343
-						case T_AAAA:
3344
-							if (dns_rr2ip(e->type, rr, &ip)==0){
3345
-								rpc->struct_add(handle, "s", "rr ip",
3346
-									ip_addr2a(&ip) );
3347
-							}else{
3348
-								rpc->struct_add(handle, "s", "rr ip",
3349
-									"<error: bad rr>");
3350
-							}
3351
-							break;
3352
-						case T_SRV:
3353
-							rpc->struct_add(handle, "s", "rr name",
3354
-									((struct srv_rdata*)(rr->rdata))->name);
3355
-							rpc->struct_add(handle, "d", "rr port",
3356
-									((struct srv_rdata*)(rr->rdata))->port);
3357
-							rpc->struct_add(handle, "d", "rr priority",
3358
-									((struct srv_rdata*)(rr->rdata))->priority);
3359
-							rpc->struct_add(handle, "d", "rr weight",
3360
-									((struct srv_rdata*)(rr->rdata))->weight);
3361
-							break;
3362
-						case T_NAPTR:
3363
-							rpc->struct_add(handle, "d", "rr order",
3364
-									((struct naptr_rdata*)(rr->rdata))->order);
3365
-							rpc->struct_add(handle, "d", "rr preference",
3366
-									((struct naptr_rdata*)(rr->rdata))->pref);
3367
-
3368
-							s.s = ((struct naptr_rdata*)(rr->rdata))->flags;
3369
-							s.len = ((struct naptr_rdata*)(rr->rdata))->flags_len;
3370
-							rpc->struct_add(handle, "S", "rr flags", &s);
3371
-
3372
-							s.s = ((struct naptr_rdata*)(rr->rdata))->services;
3373
-							s.len = ((struct naptr_rdata*)(rr->rdata))->services_len;
3374
-							rpc->struct_add(handle, "S", "rr service", &s);
3375
-
3376
-							s.s = ((struct naptr_rdata*)(rr->rdata))->regexp;
3377
-							s.len = ((struct naptr_rdata*)(rr->rdata))->regexp_len;
3378
-							rpc->struct_add(handle, "S", "rr regexp", &s);
3379
-
3380
-							s.s = ((struct naptr_rdata*)(rr->rdata))->repl;
3381
-							s.len = ((struct naptr_rdata*)(rr->rdata))->repl_len;
3382
-							rpc->struct_add(handle, "S", "rr replacement", &s);
3383
-							break;
3384
-						case T_CNAME:
3385
-							rpc->struct_add(handle, "s",  "rr name",
3386
-									((struct cname_rdata*)(rr->rdata))->name);
3387
-							break;
3388
-						default:
3389
-							rpc->struct_add(ctx, "ss", "resource record",
3390
-									"unknown");
3391
-					}
3392
-					rpc->struct_add(handle, "d", "rr expires in (s)", (s_ticks_t)(rr->expire-now)<0?-1:
3393
-										TICKS_TO_S(rr->expire-now));
3394
-					rpc->struct_add(handle, "d", "rr error flags", rr->err_flags);
3395
-				}
3396
-			}
3397
-		}
3398
-	UNLOCK_DNS_HASH();
3318
+  int h;
3319
+  struct dns_hash_entry* e;
3320
+  struct dns_rr* rr;
3321
+  struct ip_addr ip;
3322
+  ticks_t now;
3323
+  str s;
3324
+
3325
+  now=get_ticks_raw();
3326
+  LOCK_DNS_HASH();
3327
+  for (h=0; h<DNS_HASH_SIZE; h++){
3328
+    clist_foreach(&dns_hash[h], e, next){
3329
+      rpc->printf(ctx, "{\n%sname: %s", SPACE_FORMAT, e->name);
3330
+      rpc->printf(ctx, "%stype: %s", SPACE_FORMAT, print_type(e->type));
3331
+      rpc->printf(ctx, "%ssize (bytes): %d", SPACE_FORMAT, e->total_size);
3332
+      rpc->printf(ctx, "%sreference counter: %d", SPACE_FORMAT, e->refcnt.val);
3333
+      rpc->printf(ctx, "%sexpires in (s): %d", SPACE_FORMAT,
3334
+                   (s_ticks_t)(e->expire-now)<0?-1: TICKS_TO_S(e->expire-now));
3335
+      rpc->printf(ctx, "%slast used (s): %d", SPACE_FORMAT, TICKS_TO_S(now-e->last_used));
3336
+      rpc->printf(ctx, "%serror flags: %d", SPACE_FORMAT, e->err_flags);
3337
+
3338
+      for (rr=e->rr_lst; rr; rr=rr->next) {
3339
+        switch(e->type) {
3340
+          case T_A:
3341
+          case T_AAAA:
3342
+            if (dns_rr2ip(e->type, rr, &ip)==0){
3343
+              rpc->printf(ctx, "%srr ip: %s", SPACE_FORMAT, ip_addr2a(&ip) );
3344
+            }else{
3345
+              rpc->printf(ctx, "%srr ip: <error: bad rr>", SPACE_FORMAT);
3346
+            }
3347
+            break;
3348
+          case T_SRV:
3349
+            rpc->printf(ctx, "%srr name: %s", SPACE_FORMAT,
3350
+                                ((struct srv_rdata*)(rr->rdata))->name);
3351
+            rpc->printf(ctx, "%srr port: %d", SPACE_FORMAT,
3352
+                                ((struct srv_rdata*)(rr->rdata))->port);
3353
+            rpc->printf(ctx, "%srr priority: %d", SPACE_FORMAT,
3354
+                                ((struct srv_rdata*)(rr->rdata))->priority);
3355
+            rpc->printf(ctx, "%srr weight: %d", SPACE_FORMAT,
3356
+                                ((struct srv_rdata*)(rr->rdata))->weight);
3357
+            break;
3358
+          case T_NAPTR:
3359
+            rpc->printf(ctx, "%srr order: %d", SPACE_FORMAT,
3360
+                                ((struct naptr_rdata*)(rr->rdata))->order);
3361
+            rpc->printf(ctx, "%srr preference: %d", SPACE_FORMAT,
3362
+                                ((struct naptr_rdata*)(rr->rdata))->pref);
3363
+
3364
+            s.s = ((struct naptr_rdata*)(rr->rdata))->flags;
3365
+            s.len = ((struct naptr_rdata*)(rr->rdata))->flags_len;
3366
+            rpc->printf(ctx, "%srr flags: %.*s", SPACE_FORMAT, s.len, s.s);
3367
+
3368
+            s.s = ((struct naptr_rdata*)(rr->rdata))->services;
3369
+            s.len = ((struct naptr_rdata*)(rr->rdata))->services_len;
3370
+            rpc->printf(ctx, "%srr service: %.*s", SPACE_FORMAT, s.len, s.s);
3371
+
3372
+            s.s = ((struct naptr_rdata*)(rr->rdata))->regexp;
3373
+            s.len = ((struct naptr_rdata*)(rr->rdata))->regexp_len;
3374
+            rpc->printf(ctx, "%srr regexp: %.*s", SPACE_FORMAT, s.len, s.s);
3375
+
3376
+            s.s = ((struct naptr_rdata*)(rr->rdata))->repl;
3377
+            s.len = ((struct naptr_rdata*)(rr->rdata))->repl_len;
3378
+            rpc->printf(ctx, "%srr replacement: %.*s", SPACE_FORMAT, s.len, s.s);
3379
+            break;
3380
+          case T_CNAME:
3381
+            rpc->printf(ctx, "%srr name: %s", SPACE_FORMAT,
3382
+                              ((struct cname_rdata*)(rr->rdata))->name);
3383
+            break;
3384
+          default:
3385
+            rpc->printf(ctx, "%sresource record: unknown", SPACE_FORMAT);
3386
+        }
3387
+        rpc->printf(ctx, "%srr expires in (s): %d", SPACE_FORMAT,
3388
+                (s_ticks_t)(rr->expire-now)<0?-1 : TICKS_TO_S(rr->expire-now));
3389
+        rpc->printf(ctx, "%srr error flags: %d", SPACE_FORMAT, rr->err_flags);
3390
+      }
3391
+      rpc->printf(ctx, "}");
3392
+    }
3393
+  }
3394
+  UNLOCK_DNS_HASH();
3399 3395
 }
3400 3396
 
3401 3397
 
... ...
@@ -970,33 +970,25 @@ void dst_blst_hash_stats(rpc_t* rpc, void* ctx)
970 970
 /* dumps the content of the blacklist in a human-readable format */
971 971
 void dst_blst_view(rpc_t* rpc, void* ctx)
972 972
 {
973
-	int h;
974
-	struct dst_blst_entry* e;
975
-	ticks_t now;
976
-	struct ip_addr ip;
977
-	void* handle;
978
-
979
-	now=get_ticks_raw();
980
-		for(h=0; h<DST_BLST_HASH_SIZE; h++){
981
-			LOCK_BLST(h);
982
-			for(e=dst_blst_hash[h].first; e; e=e->next){
983
-				rpc->add(ctx, "{", &handle);
984
-				dst_blst_entry2ip(&ip, e);
985
-				rpc->struct_add(handle, "s", "protocol",
986
-							get_proto_name(e->proto));
987
-				rpc->struct_add(handle, "s", "ip",
988
-							ip_addr2a(&ip));
989
-				rpc->struct_add(handle, "d", "port",
990
-							e->port);
991
-				rpc->struct_add(handle, "d", "expires in (s)",
992
-							(s_ticks_t)(now-e->expire)<=0?
993
-							TICKS_TO_S(e->expire-now):
994
-							-TICKS_TO_S(now-e->expire));
995
-				rpc->struct_add(handle, "d", "flags",
996
-							e->flags);
997
-			}
998
-			UNLOCK_BLST(h);
999
-		}
973
+int h;
974
+  struct dst_blst_entry* e;
975
+  ticks_t now;
976
+  struct ip_addr ip;
977
+
978
+  now=get_ticks_raw();
979
+  for(h=0; h<DST_BLST_HASH_SIZE; h++) {
980
+    LOCK_BLST(h);
981
+    for(e=dst_blst_hash[h].first; e; e=e->next) {
982
+      dst_blst_entry2ip(&ip, e);
983
+      rpc->printf(ctx, "{\n    protocol: %s", get_proto_name(e->proto));
984
+      rpc->printf(ctx, "    ip: %s", ip_addr2a(&ip));
985
+      rpc->printf(ctx, "    port: %d", e->port);
986
+      rpc->printf(ctx, "    expires in (s):", (s_ticks_t)(now-e->expire)<=0?
987
+                       TICKS_TO_S(e->expire-now): -TICKS_TO_S(now-e->expire));
988
+      rpc->printf(ctx, "    flags: %d\n}", e->flags);
989
+    }
990
+    UNLOCK_BLST(h);
991
+  }
1000 992
 }
1001 993
 
1002 994
 /* deletes all the entries from the blacklist except the permanent ones