gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r22609 - gnunet/src/gns


From: gnunet
Subject: [GNUnet-SVN] r22609 - gnunet/src/gns
Date: Wed, 11 Jul 2012 17:26:13 +0200

Author: schanzen
Date: 2012-07-11 17:26:13 +0200 (Wed, 11 Jul 2012)
New Revision: 22609

Modified:
   gnunet/src/gns/gnunet-gns-proxy.c
Log:
-fix compile

Modified: gnunet/src/gns/gnunet-gns-proxy.c
===================================================================
--- gnunet/src/gns/gnunet-gns-proxy.c   2012-07-11 15:17:17 UTC (rev 22608)
+++ gnunet/src/gns/gnunet-gns-proxy.c   2012-07-11 15:26:13 UTC (rev 22609)
@@ -618,6 +618,15 @@
 static void
 run_httpds (void);
 
+/**
+ * Task run whenever HTTP server operations are pending.
+ *
+ * @param cls unused
+ * @param tc sched context
+ */
+static void
+do_httpd (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 /**
  * Task that simply runs MHD main loop
@@ -635,77 +644,11 @@
 }
 
 
-/**
- * Process cURL download bits
- *
- * @param ptr buffer with data
- * @param size size of a record
- * @param nmemb number of records downloaded
- * @param ctx context
- * @return number of processed bytes
- */
-static size_t
-callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
+static void
+run_mhd_now (struct MhdHttpList *hd)
 {
-  const char *cbuf = ptr;
-  size_t total;
-  struct ProxyCurlTask *ctask = ctx;
-  
-  if (NULL == ctask->response)
-  {
-    /* FIXME: get total size from curl (if available) */
-    ctask->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
-                                                        20 /* 20 bytes IO 
buffers!? */,
-                                                        &mhd_content_cb,
-                                                        ctask,
-                                                        NULL);
-    
-  }
-
-  //MHD_run (httpd);
-  ctask->ready_to_queue = GNUNET_YES;
-  /*if (ctask->con_status == MHD_NO)
-  {
-    MHD_queue_response (ctask->connection,
-                        MHD_HTTP_OK,
-                       ctask->response);
-    ctask->con_status = MHD_YES;
-  }*/
-  total = size*nmemb;
-
-  if (total == 0)
-  {
-    return total;
-  }
-
-  if (total > sizeof (ctask->buffer))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "CURL gave us too much data to handle (%d)!\n",
-                total);
-    return 0;
-  }
-  
-  if (ctask->buf_status == BUF_WAIT_FOR_MHD)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "CURL: Waiting for MHD (%s)\n", ctask->url);
-    return CURL_WRITEFUNC_PAUSE;
-  }
-
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "CURL: Copying to MHD (%s, %d)\n", ctask->url, total);
-  memcpy (ctask->buffer, cbuf, total);
-  ctask->bytes_in_buffer = total;
-  ctask->buffer_ptr = ctask->buffer;
-
-  ctask->buf_status = BUF_WAIT_FOR_MHD;
-
-  //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-  //            "cURL chunk:\n%s\n", (char*)ctask->buffer);
-  run_mhd_now (ctask->mhd);
-  return total;
+  GNUNET_SCHEDULER_cancel (hd->httpd_task);
+  hd->httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, hd);
 }
 
 /**
@@ -988,8 +931,81 @@
   return copied;
 }
 
+/**
+ * Process cURL download bits
+ *
+ * @param ptr buffer with data
+ * @param size size of a record
+ * @param nmemb number of records downloaded
+ * @param ctx context
+ * @return number of processed bytes
+ */
+static size_t
+callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
+{
+  const char *cbuf = ptr;
+  size_t total;
+  struct ProxyCurlTask *ctask = ctx;
+  
+  if (NULL == ctask->response)
+  {
+    /* FIXME: get total size from curl (if available) */
+    ctask->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
+                                                        20 /* 20 bytes IO 
buffers!? */,
+                                                        &mhd_content_cb,
+                                                        ctask,
+                                                        NULL);
+    
+  }
 
+  //MHD_run (httpd);
+  ctask->ready_to_queue = GNUNET_YES;
+  /*if (ctask->con_status == MHD_NO)
+  {
+    MHD_queue_response (ctask->connection,
+                        MHD_HTTP_OK,
+                       ctask->response);
+    ctask->con_status = MHD_YES;
+  }*/
+  total = size*nmemb;
 
+  if (total == 0)
+  {
+    return total;
+  }
+
+  if (total > sizeof (ctask->buffer))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "CURL gave us too much data to handle (%d)!\n",
+                total);
+    return 0;
+  }
+  
+  if (ctask->buf_status == BUF_WAIT_FOR_MHD)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "CURL: Waiting for MHD (%s)\n", ctask->url);
+    return CURL_WRITEFUNC_PAUSE;
+  }
+
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "CURL: Copying to MHD (%s, %d)\n", ctask->url, total);
+  memcpy (ctask->buffer, cbuf, total);
+  ctask->bytes_in_buffer = total;
+  ctask->buffer_ptr = ctask->buffer;
+
+  ctask->buf_status = BUF_WAIT_FOR_MHD;
+
+  //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  //            "cURL chunk:\n%s\n", (char*)ctask->buffer);
+  run_mhd_now (ctask->mhd);
+  return total;
+}
+
+
+
 /**
  * Task that is run when we are ready to receive more data
  * from curl
@@ -1373,15 +1389,6 @@
                           ctask);
 }
 
-/**
- * Task run whenever HTTP server operations are pending.
- *
- * @param cls unused
- * @param tc sched context
- */
-static void
-do_httpd (void *cls,
-          const struct GNUNET_SCHEDULER_TaskContext *tc);
 
 /**
  * Main MHD callback for handling requests.
@@ -1606,14 +1613,7 @@
 }
 
 
-static void
-run_mhd_now (struct MhdHttpList *hd)
-{
-  GNUNET_SCHEDULER_cancel (hd->httpd_task);
-  hd->httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, hd);
-}
 
-
 /**
  * Read data from socket
  *
@@ -1819,27 +1819,6 @@
 }
 
 /**
- * Calculate size of file
- *
- * @param filename name of file
- * @return filesize or 0 on error
- */
-static long
-get_file_size (const char* filename)
-{
-  FILE *fp;
-  long size;
-
-  if (NULL == (fp = fopen (filename, "rb")))
-    return 0; 
-  if ((0 != fseek (fp, 0, SEEK_END)) || (-1 == (size = ftell (fp))))
-    size = 0;  
-  fclose (fp);  
-  return size;
-}
-
-
-/**
  * Read file in filename
  *
  * @param filename file to read
@@ -1903,27 +1882,26 @@
  *
  * @param crt struct to store data in
  * @param certfile path to pem file
+ * @return GNUNET_OK on success
  */
-static void
+static int
 load_cert_from_file (gnutls_x509_crt_t crt, char* certfile)
 {
   gnutls_datum_t cert_data;
   cert_data.data = NULL;
   int ret;
 
-  cert_data.data = (unsigned char*)load_file (certfile, &cert_data.size);
-
+  cert_data.data = (unsigned char*) load_file (certfile, &cert_data.size);
   ret = gnutls_x509_crt_import (crt, &cert_data,
-                                 GNUTLS_X509_FMT_PEM);
+                                GNUTLS_X509_FMT_PEM);
   if (GNUTLS_E_SUCCESS != ret)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Unable to import certificate %s(ret=%d)\n", certfile, ret);
+               _("Unable to import certificate %s\n"), certfile);
     GNUNET_break (0);
   }
-
   GNUNET_free (cert_data.data);
-
+  return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
 }
 
 




reply via email to

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