gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3508 - in GNUnet/src: applications/fs/fsui applications/fs


From: grothoff
Subject: [GNUnet-SVN] r3508 - in GNUnet/src: applications/fs/fsui applications/fs/tools include
Date: Thu, 19 Oct 2006 22:49:34 -0700 (PDT)

Author: grothoff
Date: 2006-10-19 22:49:29 -0700 (Thu, 19 Oct 2006)
New Revision: 3508

Modified:
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/fsui.h
   GNUnet/src/applications/fs/fsui/search.c
   GNUnet/src/applications/fs/fsui/serialize.c
   GNUnet/src/applications/fs/fsui/unindex.c
   GNUnet/src/applications/fs/tools/gnunet-download.c
   GNUnet/src/applications/fs/tools/gnunet-insert.c
   GNUnet/src/applications/fs/tools/gnunet-search.c
   GNUnet/src/applications/fs/tools/gnunet-unindex.c
   GNUnet/src/include/gnunet_fsui_lib.h
Log:
cleanup

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2006-10-20 05:13:40 UTC 
(rev 3507)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2006-10-20 05:49:29 UTC 
(rev 3508)
@@ -319,6 +319,7 @@
   int i;
   ResultPending * rp;
   char * buf;
+  cron_t stime;
 
   while (1) {
     READINT(big);
@@ -330,6 +331,10 @@
           0,
           sizeof(FSUI_SearchList));
     if ( (OK != read_int(fd, (int*) &list->state)) ||
+        (OK != read_int(fd, (int*) &list->maxResults)) ||
+        (OK != read_long(fd, (long long*) &list->timeout)) ||
+        (OK != read_long(fd, (long long*) &list->start_time)) ||
+        (OK != read_long(fd, (long long*) &stime)) ||
         (OK != read_int(fd, (int*) &list->anonymityLevel)) ||
         (OK != read_int(fd, (int*) &list->sizeResultsReceived)) ||
         (OK != read_int(fd, (int*) &list->sizeUnmatchedResultsReceived)) ||
@@ -339,6 +344,9 @@
       break;
     }
     fixState(&list->state);
+    if (stime > get_time())
+      stime = get_time();
+    list->start_time += get_time() - stime;
     buf = read_string(fd, 1024 * 1024);
     if (buf == NULL) {
       GE_BREAK(NULL, 0);       

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2006-10-20 05:13:40 UTC (rev 
3507)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2006-10-20 05:49:29 UTC (rev 
3508)
@@ -117,6 +117,16 @@
 typedef struct FSUI_SearchList {
 
   /**
+   * Desired timeout (relative) for this search
+   */
+  cron_t timeout;
+
+  /**
+   * start time of the search
+   */
+  cron_t start_time;
+
+  /**
    * Searches are kept in a simple linked list.
    */
   struct FSUI_SearchList * next;
@@ -151,6 +161,11 @@
   unsigned int anonymityLevel;
 
   /**
+   * Maximum number of results requested.
+   */
+  unsigned int maxResults;
+
+  /**
    * Of how many individual queries does the
    * boolean query consist (1 for non-boolean queries).
    */

Modified: GNUnet/src/applications/fs/fsui/search.c
===================================================================
--- GNUnet/src/applications/fs/fsui/search.c    2006-10-20 05:13:40 UTC (rev 
3507)
+++ GNUnet/src/applications/fs/fsui/search.c    2006-10-20 05:49:29 UTC (rev 
3508)
@@ -228,7 +228,8 @@
 
 static int testTerminate(void * cls) {
   FSUI_SearchList * pos = cls;
-  if (pos->state == FSUI_ACTIVE)
+  if ( (pos->state == FSUI_ACTIVE) &&
+       (pos->maxResults > pos->sizeResultsReceived) )
     return OK;
   return SYSERR;
 }
@@ -247,14 +248,14 @@
   pos->cctx = pos->ctx->ecb(pos->ctx->ecbClosure,
                            &event);
   ret = ECRS_search(pos->ctx->ectx,
-             pos->ctx->cfg,
-             pos->uri,
-             pos->anonymityLevel,
-             get_time() + cronYEARS, /* timeout!?*/
-             &spcb,
-             pos,
-             &testTerminate,
-             pos);
+                   pos->ctx->cfg,
+                   pos->uri,
+                   pos->anonymityLevel,
+                   pos->timeout,
+                   &spcb,
+                   pos,
+                   &testTerminate,
+                   pos);
   if (ret != OK) {
     pos->state = FSUI_ERROR;    
     event.type = FSUI_search_error;
@@ -270,6 +271,7 @@
     pos->ctx->ecb(pos->ctx->ecbClosure,
                  &event);
   } else if (pos->state == FSUI_ACTIVE) {
+    pos->state = FSUI_COMPLETED;
     event.type = FSUI_search_completed;
     event.data.SearchCompleted.sc.pos = pos;
     event.data.SearchCompleted.sc.cctx = pos->cctx;
@@ -289,6 +291,8 @@
 struct FSUI_SearchList *
 FSUI_startSearch(struct FSUI_Context * ctx,
                 unsigned int anonymityLevel,
+                unsigned int maxResults,
+                cron_t timeout,
                 const struct ECRS_URI * uri) {
   FSUI_SearchList * pos;
   struct GE_Context * ectx;
@@ -296,6 +300,7 @@
   ectx = ctx->ectx;
   MUTEX_LOCK(ctx->lock);
   pos = MALLOC(sizeof(FSUI_SearchList));
+  pos->maxResults = maxResults;
   pos->state = FSUI_ACTIVE;
   pos->uri = ECRS_dupUri(uri);
   pos->numberOfURIKeys = ECRS_countKeywordsOfUri(uri);
@@ -305,6 +310,8 @@
   pos->unmatchedResultsReceived = 0;
   pos->anonymityLevel = anonymityLevel;
   pos->ctx = ctx;
+  pos->start_time = get_time();
+  pos->timeout = timeout;
   pos->handle = PTHREAD_CREATE(&FSUI_searchThread,
                               pos,
                               32 * 1024);

Modified: GNUnet/src/applications/fs/fsui/serialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serialize.c 2006-10-20 05:13:40 UTC (rev 
3507)
+++ GNUnet/src/applications/fs/fsui/serialize.c 2006-10-20 05:49:29 UTC (rev 
3508)
@@ -166,8 +166,12 @@
     }
     GE_ASSERT(ctx->ectx,
              ECRS_isKeywordUri(spos->uri));
-    WRITEINT(fd, 1);
+    WRITEINT(fd, 1);    
     WRITEINT(fd, spos->state);
+    WRITEINT(fd, spos->maxResults);
+    WRITELONG(fd, spos->timeout);
+    WRITELONG(fd, spos->start_time);
+    WRITELONG(fd, get_time());
     WRITEINT(fd, spos->anonymityLevel);
     WRITEINT(fd, spos->sizeResultsReceived);
     WRITEINT(fd, spos->sizeUnmatchedResultsReceived);

Modified: GNUnet/src/applications/fs/fsui/unindex.c
===================================================================
--- GNUnet/src/applications/fs/fsui/unindex.c   2006-10-20 05:13:40 UTC (rev 
3507)
+++ GNUnet/src/applications/fs/fsui/unindex.c   2006-10-20 05:49:29 UTC (rev 
3508)
@@ -87,6 +87,7 @@
                         &tt,
                         utc);
   if (ret == OK) {
+    utc->state = FSUI_COMPLETED;
     event.type = FSUI_unindex_completed;
     event.data.UnindexCompleted.uc.pos = utc;
     event.data.UnindexCompleted.uc.cctx = utc->cctx;
@@ -95,6 +96,7 @@
     utc->ctx->ecb(utc->ctx->ecbClosure,
                  &event);
   } else if (utc->state == FSUI_ACTIVE) {
+    utc->state = FSUI_ERROR;
     event.type = FSUI_unindex_error;
     event.data.UnindexError.uc.pos = utc;
     event.data.UnindexError.uc.cctx = utc->cctx;

Modified: GNUnet/src/applications/fs/tools/gnunet-download.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-download.c  2006-10-20 05:13:40 UTC 
(rev 3507)
+++ GNUnet/src/applications/fs/tools/gnunet-download.c  2006-10-20 05:49:29 UTC 
(rev 3508)
@@ -48,6 +48,8 @@
 
 static struct FSUI_DownloadList * dl;
 
+static int errorCode;
+
 /**
  * All gnunet-download command line options
  */
@@ -75,10 +77,8 @@
  * The current incarnation just ensures that the main
  * method exits once the download is complete.
  */
-static void * progressModel(void * okVal,
+static void * progressModel(void * unused,
                            const FSUI_Event * event) {
-  int * ok = okVal;
-
   switch (event->type) {
   case FSUI_download_progress:
     if (verbose) {
@@ -96,12 +96,14 @@
     if (dl == event->data.DownloadError.dc.pos) {
       /* top-download aborted */
       PRINTF(_("Download aborted.\n"));
+      errorCode = 2;
+      GNUNET_SHUTDOWN_INITIATE();
     }
     break;
   case FSUI_download_error:
     printf(_("Error downloading: %s\n"),
           event->data.DownloadError.message);
-    *ok = SYSERR;
+    errorCode = 3;
     GNUNET_SHUTDOWN_INITIATE();
     break;
   case FSUI_download_completed:
@@ -114,7 +116,7 @@
             (((double)(get_time()-(start_time - 1)))
              / (double)cronSECONDS) );
       if (dl == event->data.DownloadProgress.dc.pos) {
-       *ok = OK;
+       errorCode = 0;
        GNUNET_SHUTDOWN_INITIATE();
       }
     }
@@ -159,18 +161,16 @@
   if ( (i == SYSERR) ||
        (0 != GC_parse_configuration(cfg,
                                    cfgFilename)) ) {    
-    GC_free(cfg);
-    GE_free_context(ectx);
-    return -1;  
+    errorCode = -1;
+    goto quit;
   }
   if (i == argc) {
     GE_LOG(ectx,
           GE_WARNING | GE_BULK | GE_USER,
           _("Not enough arguments. "
             "You must specify a GNUnet file URI\n"));
-    GC_free(cfg);
-    GE_free_context(ectx);
-    return -1;
+    errorCode = -1;
+    goto quit;
   }
   GC_get_configuration_value_number(cfg,
                                    "GNUNET",
@@ -188,9 +188,8 @@
           GE_ERROR | GE_BULK | GE_USER,
           _("URI `%s' invalid for gnunet-download.\n"),
           argv[i]);
-    GC_free(cfg);
-    GE_free_context(ectx);
-    return -1;
+    errorCode = -1;
+    goto quit;
   }
 
   try_rename = NO;
@@ -215,20 +214,25 @@
                   32, /* FIXME: support option! */
                   NO,
                   &progressModel,
-                  &ok);
+                  NULL);
   start_time = get_time();
+  errorCode = 1;
   dl = FSUI_startDownload(ctx,
                          anonymity,
                          do_recursive,
                          uri,
                          filename);
+  if (dl == NULL) {
+    FSUI_stop(ctx);
+    goto quit;
+  }
   GNUNET_SHUTDOWN_WAITFOR();
-  if (OK != ok)
+  if (errorCode == 1)
     FSUI_abortDownload(ctx, dl);
   FSUI_stopDownload(ctx, dl);
   FSUI_stop(ctx);
 
-  if ( (OK == ok) &&
+  if ( (errorCode == 0) &&
        (dl != NULL) &&
        (try_rename == YES) ) {
     char * newname = ECRS_suggestFilename(ectx,
@@ -243,11 +247,10 @@
   }
   FREE(filename);
   ECRS_freeUri(uri);
+ quit:
   GC_free(cfg);
   GE_free_context(ectx);
-  if (ok != OK)
-    return 1;
-  return 0;
+  return errorCode;
 }
 
 /* end of gnunet-download.c */

Modified: GNUnet/src/applications/fs/tools/gnunet-insert.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-insert.c    2006-10-20 05:13:40 UTC 
(rev 3507)
+++ GNUnet/src/applications/fs/tools/gnunet-insert.c    2006-10-20 05:49:29 UTC 
(rev 3508)
@@ -40,10 +40,8 @@
                      const char *format,
                      struct tm *tm);
 
-static struct SEMAPHORE * exitSignal;
+static int errorCode;
 
-static int errorCode = 0;
-
 static struct GC_Configuration * cfg;
 
 static struct GE_Context * ectx;
@@ -192,22 +190,20 @@
     FREE(fstring);
     if (ul == event->data.UploadCompleted.uc.pos) {
       postProcess(event->data.UploadCompleted.uri);
-      if (exitSignal != NULL)
-       SEMAPHORE_UP(exitSignal);
+      errorCode = 0;
+      GNUNET_SHUTDOWN_INITIATE();
     }
     break;
   case FSUI_upload_aborted:
     printf(_("\nUpload aborted.\n"));
-    errorCode = 1;
-    if (exitSignal != NULL)
-      SEMAPHORE_UP(exitSignal); /* always exit main? */
+    errorCode = 2;
+    GNUNET_SHUTDOWN_INITIATE();
     break;
   case FSUI_upload_error:
     printf(_("\nError uploading file: %s\n"),
           event->data.UploadError.message);
-    errorCode = 1;
-    if (exitSignal != NULL)
-      SEMAPHORE_UP(exitSignal); /* always exit main? */
+    errorCode = 3;
+    GNUNET_SHUTDOWN_INITIATE();
     break;
   default:
     GE_BREAK(ectx, 0);
@@ -302,7 +298,6 @@
   int i;
   char * tmp;
   unsigned long long verbose;
-  struct SEMAPHORE * es;
 
   ectx = GE_create_context_stderr(NO, 
                                  GE_WARNING | GE_ERROR | GE_FATAL |
@@ -322,6 +317,11 @@
     errorCode = -1;
     goto quit;  
   }
+  if (OK != GC_parse_configuration(cfg,
+                                  cfgFilename)) {  
+    errorCode = -1;
+    goto quit;
+  }
   if (i != argc - 1) {
     printf(_("You must specify one and only one filename for insertion.\n"));
     errorCode = -1;
@@ -380,24 +380,22 @@
     }
     if (creation_time != NULL) {
       struct tm t;
-      if ((NULL == strptime(creation_time,
+      const char * fmt;
+
 #if ENABLE_NLS
-                           nl_langinfo(D_T_FMT),
+      fmt = nl_langinfo(D_T_FMT);
 #else
-                           "%Y-%m-%d",
+      fmt = "%Y-%m-%d";
 #endif
+      if ((NULL == strptime(creation_time,
+                           fmt,
                            &t))) {
        GE_LOG_STRERROR(ectx,
                        GE_FATAL | GE_USER | GE_IMMEDIATE, 
                        "strptime");
        printf(_("Parsing time failed. Use `%s' format.\n"),
-#if ENABLE_NLS
-              nl_langinfo(D_T_FMT)
-#else
-              "%Y-%m-%d"
-#endif
-              );
-  errorCode = -1;
+              fmt);
+       errorCode = -1;
        goto quit;
       }
     }
@@ -435,7 +433,6 @@
     }
   }
 
-  exitSignal = SEMAPHORE_CREATE(0);
   /* fundamental init */
   ctx = FSUI_start(ectx,
                   cfg,
@@ -450,6 +447,7 @@
   if (! do_disable_creation_time)
     ECRS_addPublicationDateToMetaData(meta);
   start_time = get_time();
+  errorCode = 1;
   ul = FSUI_startUpload(ctx,
                        tmp,
                        (DirectoryScanCallback) &disk_directory_scan,
@@ -466,11 +464,9 @@
   ECRS_freeUri(topKeywords);
   FREE(tmp);
   if (ul != NULL) {
-    /* wait for completion */
-    SEMAPHORE_DOWN(exitSignal, YES);
-    es = exitSignal;
-    exitSignal = NULL;
-    SEMAPHORE_DESTROY(es);
+    GNUNET_SHUTDOWN_WAITFOR();
+    if (errorCode == 1)
+      FSUI_abortUpload(ctx, ul);
     FSUI_stopUpload(ctx, ul);
   }
   ECRS_freeMetaData(meta);

Modified: GNUnet/src/applications/fs/tools/gnunet-search.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-search.c    2006-10-20 05:13:40 UTC 
(rev 3507)
+++ GNUnet/src/applications/fs/tools/gnunet-search.c    2006-10-20 05:49:29 UTC 
(rev 3508)
@@ -22,9 +22,6 @@
  * @file applications/fs/tools/gnunet-search.c
  * @brief Main function to search for files on GNUnet.
  * @author Christian Grothoff
- *
- * TODO:
- * - make sure all (search related) FSUI events are handled correctly!
  */
 
 #include "platform.h"
@@ -47,14 +44,13 @@
 
 static char * output_filename;
 
-typedef struct {
-  unsigned int resultCount;
-  unsigned int max;
-  ECRS_FileInfo * fis;
-  unsigned int fiCount;
-} SearchClosure;
+static int errorCode;
 
+static ECRS_FileInfo * fis;
 
+static unsigned int fiCount;
+
+
 static int itemPrinter(EXTRACTOR_KeywordType type,
                       const char * data,
                       void * closure) {
@@ -76,48 +72,55 @@
  */
 static void * eventCallback(void * cls,
                            const FSUI_Event * event) {
-  SearchClosure * sc = cls;
   char * uri;
   char * filename;
 
-  if (0 == sc->max)
-    return NULL;
-  if (event->type != FSUI_search_result)
-    return NULL;
-
-  /* retain URIs for possible directory dump later */
-  GROW(sc->fis,
-       sc->fiCount,
-       sc->fiCount+1);
-  sc->fis[sc->fiCount-1].uri
-    = ECRS_dupUri(event->data.SearchResult.fi.uri);
-  sc->fis[sc->fiCount-1].meta
-    = ECRS_dupMetaData(event->data.SearchResult.fi.meta);
-
-  uri = ECRS_uriToString(event->data.SearchResult.fi.uri);
-  printf("%s:\n",
-        uri);
-  filename = ECRS_getFromMetaData(event->data.SearchResult.fi.meta,
-                                 EXTRACTOR_FILENAME);
-  if (filename != NULL) {
-    char * dotdot;
+  switch (event->type) {
+  case FSUI_search_error:
+    errorCode = 3;
+    GNUNET_SHUTDOWN_INITIATE();
+    break;
+  case FSUI_search_completed:
+    errorCode = 0;
+    GNUNET_SHUTDOWN_INITIATE();
+    break;
+  case FSUI_search_result:
+    /* retain URIs for possible directory dump later */
+    GROW(fis,
+        fiCount,
+        fiCount+1);
+    fis[fiCount-1].uri
+      = ECRS_dupUri(event->data.SearchResult.fi.uri);
+    fis[fiCount-1].meta
+      = ECRS_dupMetaData(event->data.SearchResult.fi.meta);
     
-    while (NULL != (dotdot = strstr(filename, "..")))
-      dotdot[0] = dotdot[1] = '_';
-    
-    printf("gnunet-download -o \"%s\" %s\n",
-          filename,
+    uri = ECRS_uriToString(event->data.SearchResult.fi.uri);
+    printf("%s:\n",
           uri);
+    filename = ECRS_getFromMetaData(event->data.SearchResult.fi.meta,
+                                   EXTRACTOR_FILENAME);
+    if (filename != NULL) {
+      char * dotdot;
+      
+      while (NULL != (dotdot = strstr(filename, "..")))
+       dotdot[0] = dotdot[1] = '_';
+      
+      printf("gnunet-download -o \"%s\" %s\n",
+            filename,
+            uri);
+    }
+    else
+      printf("gnunet-download %s\n",
+            uri);
+    printMeta(event->data.SearchResult.fi.meta);
+    printf("\n");
+    FREENONNULL(filename);
+    FREE(uri);
+    break;
+  default:
+    GE_BREAK(NULL, 0);
+    break;
   }
-  else
-    printf("gnunet-download %s\n",
-          uri);
-  printMeta(event->data.SearchResult.fi.meta);
-  printf("\n");
-  FREENONNULL(filename);
-  FREE(uri);
-  if (0 == --sc->max)
-    GNUNET_SHUTDOWN_INITIATE();
   return NULL;
 }
 
@@ -146,53 +149,84 @@
   COMMAND_LINE_OPTION_END,
 };
 
-static void run_shutdown(void * unused) {
-  GNUNET_SHUTDOWN_INITIATE();
-}
-
 /**
- * Perform a normal (non-namespace) search.
+ * The main function to search for files on GNUnet.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return return value from gnunet-search: 0: ok, -1: error
  */
-static int runSearch(const char * suri) {
-  struct FSUI_Context * ctx;
-  SearchClosure sc;
+int main(int argc,
+        const char ** argv) {
   struct ECRS_URI * uri;
-  struct FSUI_SearchList * s;
   int i;
+  struct FSUI_Context * ctx;
+  struct FSUI_SearchList * s;
 
-  if (suri == NULL) {
-    GE_BREAK(ectx, 0);
-    return SYSERR;
+  /* startup */
+  ectx = GE_create_context_stderr(NO, 
+                                 GE_WARNING | GE_ERROR | GE_FATAL |
+                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
+                                 GE_IMMEDIATE | GE_BULK);
+  GE_setDefaultContext(ectx);
+  os_init(ectx);
+  cfg = GC_create_C_impl();
+  GE_ASSERT(ectx, cfg != NULL);
+  i = gnunet_parse_options("gnunet-search [OPTIONS] [KEYWORDS]",
+                          ectx,
+                          cfg,
+                          gnunetsearchOptions,
+                          (unsigned int) argc,
+                          argv);
+  if (i == SYSERR) {
+    errorCode = -1;
+    goto quit;
   }
-  uri = ECRS_stringToUri(ectx,
-                        suri);
-  memset(&sc, 0, sizeof(SearchClosure));
-  sc.max = max_results;
-  sc.resultCount = 0;
-  if (sc.max == 0)
-    sc.max = (unsigned int)-1; /* infty */
+  if (OK != GC_parse_configuration(cfg,
+                                  cfgFilename)) {  
+    errorCode = -1;
+    goto quit;
+  }
+  /* convert args to URI */
+ uri = ECRS_parseArgvKeywordURI(ectx,
+                                argc - i,
+                                (const char**) &argv[i]);
+  if (uri == NULL) {
+    printf(_("Error converting arguments to URI!\n"));
+    errorCode = -1;
+    goto quit;
+  }
+  if (max_results == 0)
+    max_results = (unsigned int)-1; /* infty */
   ctx = FSUI_start(ectx,
                   cfg,
                   "gnunet-search",
                   4,
                   NO,
                   &eventCallback,
-                  &sc);
+                  NULL);
   if (ctx == NULL) {
     ECRS_freeUri(uri);
     return SYSERR;
   }
+  errorCode = 1;
   s = FSUI_startSearch(ctx,
                       anonymity,
+                      max_results,
+                      delay * cronSECONDS,
                       uri);
+  ECRS_freeUri(uri);
   if (s == NULL) {
-    printf(_("Starting search failed. Consult logs.\n"));
-  } else {
-    GNUNET_SHUTDOWN_WAITFOR();
-    FSUI_stopSearch(ctx,
-                   s);
+    errorCode = 2;
+    FSUI_stop(ctx);
+    goto quit;
   }
-  ECRS_freeUri(uri);
+  GNUNET_SHUTDOWN_WAITFOR();
+  if (errorCode == 1)
+    FSUI_abortSearch(ctx,    
+                    s);
+  FSUI_stopSearch(ctx,
+                   s);
   FSUI_stop(ctx);
 
   if (output_filename != NULL) {
@@ -206,8 +240,8 @@
     if (OK == ECRS_createDirectory(ectx,
                                   &data,
                                   &n,
-                                  sc.fiCount,
-                                  sc.fis,
+                                  fiCount,
+                                  fis,
                                   meta)) {
       outfile = string_expandFileName(ectx,
                                      output_filename);
@@ -221,88 +255,17 @@
     }
     FREE(output_filename);
   }
-  for (i=0;i<sc.fiCount;i++) {
-    ECRS_freeUri(sc.fis[i].uri);
-    ECRS_freeMetaData(sc.fis[i].meta);
+  for (i=0;i<fiCount;i++) {
+    ECRS_freeUri(fis[i].uri);
+    ECRS_freeMetaData(fis[i].meta);
   }
-  GROW(sc.fis,
-       sc.fiCount,
+  GROW(fis,
+       fiCount,
        0);
-  return OK;
-}
-
-/**
- * The main function to search for files on GNUnet.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return return value from gnunet-search: 0: ok, -1: error
- */
-int main(int argc,
-        const char ** argv) {
-  int ret;
-  char * suri;
-  struct ECRS_URI * uri;
-  int i;
-  struct CronManager * cron;
-
-  /* startup */
-  ectx = GE_create_context_stderr(NO, 
-                                 GE_WARNING | GE_ERROR | GE_FATAL |
-                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
-                                 GE_IMMEDIATE | GE_BULK);
-  GE_setDefaultContext(ectx);
-  os_init(ectx);
-  cfg = GC_create_C_impl();
-  GE_ASSERT(ectx, cfg != NULL);
-  i = gnunet_parse_options("gnunet-search [OPTIONS] [KEYWORDS]",
-                          ectx,
-                          cfg,
-                          gnunetsearchOptions,
-                          (unsigned int) argc,
-                          argv);
-  if (i == SYSERR) {
-    GC_free(cfg);
-    GE_free_context(ectx);
-    return -1;  
-  }
-
-  /* convert args to URI */
-  uri = ECRS_parseArgvKeywordURI(ectx,
-                                argc - i,
-                                (const char**) &argv[i]);
-  if (uri != NULL) {
-    suri = ECRS_uriToString(uri);
-    ECRS_freeUri(uri);
-  } else {
-    printf(_("Error converting arguments to URI!\n"));
-    GC_free(cfg);
-    GE_free_context(ectx);
-    return -1;
-  }
-
-  cron = cron_create(ectx);
-  cron_add_job(cron,
-              &run_shutdown,
-              cronSECONDS * delay,
-              0, /* no need to repeat */
-              NULL);
-  cron_start(cron);
-  ret = runSearch(suri);
-  FREE(suri);
-
-  cron_stop(cron);
-  cron_del_job(cron,
-              &run_shutdown,
-              0,
-              NULL);
-  cron_destroy(cron);
+ quit:
   GC_free(cfg);
   GE_free_context(ectx);
-  if (ret == OK)
-    return 0;
-  else
-    return -1;
+  return errorCode;
 }
 
 /* end of gnunet-search.c */

Modified: GNUnet/src/applications/fs/tools/gnunet-unindex.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-unindex.c   2006-10-20 05:13:40 UTC 
(rev 3507)
+++ GNUnet/src/applications/fs/tools/gnunet-unindex.c   2006-10-20 05:49:29 UTC 
(rev 3508)
@@ -181,7 +181,7 @@
     errorCode = 2;
   } else {
     GNUNET_SHUTDOWN_WAITFOR();
-    if (errorCode != 0)
+    if (errorCode == 1)
       FSUI_abortUnindex(ctx, ul);
     FSUI_stopUnindex(ctx, ul);
   }

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2006-10-20 05:13:40 UTC (rev 
3507)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2006-10-20 05:49:29 UTC (rev 
3508)
@@ -750,6 +750,8 @@
 struct FSUI_SearchList *
 FSUI_startSearch(struct FSUI_Context * ctx,
                 unsigned int anonymityLevel,
+                unsigned int maxResults,
+                cron_t timeout,
                 const struct ECRS_URI * uri); /* search.c */
 
 /**





reply via email to

[Prev in Thread] Current Thread [Next in Thread]