[476] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r605 - trunk/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:06:35 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Sun, 11 Feb 2007 10:36:01 -0500 (EST)

Author: asedeno
Date: 2007-02-11 10:36:00 -0500 (Sun, 11 Feb 2007)
New Revision: 605

Modified:
   trunk/owl/zephyr.c
Log:
Load zephyr subscriptions in chunks.



Modified: trunk/owl/zephyr.c
===================================================================
--- trunk/owl/zephyr.c	2007-02-11 05:31:33 UTC (rev 604)
+++ trunk/owl/zephyr.c	2007-02-11 15:36:00 UTC (rev 605)
@@ -71,6 +71,24 @@
 #endif
 }
 
+int owl_zephyr_loadsubs_helper(ZSubscription_t subs[], int count)
+{
+  int i, ret = 0;
+  /* sub without defaults */
+  if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) {
+    owl_function_error("Error subscribing to zephyr notifications.");
+    ret=-2;
+  }
+
+  /* free stuff */
+  for (i=0; i<count; i++) {
+    owl_free(subs[i].zsub_class);
+    owl_free(subs[i].zsub_classinst);
+    owl_free(subs[i].zsub_recipient);
+  }
+  return ret;
+}
+
 /* Load zephyr subscriptions form 'filename'.  If 'filename' is NULL,
  * the default file $HOME/.zephyr.subs will be used.
  *
@@ -86,7 +104,7 @@
   char *tmp, *start;
   char buffer[1024], subsfile[1024];
   ZSubscription_t subs[3001];
-  int count, ret, i;
+  int count, ret;
   struct stat statbuff;
 
   if (filename==NULL) {
@@ -102,7 +120,6 @@
   }
 
   ZResetAuthentication();
-  /* need to redo this to do chunks, not just bail after 3000 */
   count=0;
   file=fopen(subsfile, "r");
   if (!file) return(-1);
@@ -115,7 +132,14 @@
       start=buffer;
     }
     
-    if (count >= 3000) break; /* also tell the user */
+    if (count >= 3000) {
+      ret = owl_zephyr_loadsubs_helper(subs, count);
+      if (ret != 0) {
+	fclose(file);
+	return(ret);
+      }
+      count=0;
+    }
     
     /* add it to the list of subs */
     if ((tmp=(char *) strtok(start, ",\n\r"))==NULL) continue;
@@ -134,20 +158,8 @@
   }
   fclose(file);
 
-  /* sub without defaults */
-  ret=0;
-  if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) {
-    owl_function_error("Error subscribing to zephyr notifications.");
-    ret=-2;
-  }
+  ret=owl_zephyr_loadsubs_helper(subs, count);
 
-  /* free stuff */
-  for (i=0; i<count; i++) {
-    owl_free(subs[i].zsub_class);
-    owl_free(subs[i].zsub_classinst);
-    owl_free(subs[i].zsub_recipient);
-  }
-
   return(ret);
 #else
   return(0);


home help back first fref pref prev next nref lref last post