gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37197 - in gnunet/src: include my


From: gnunet
Subject: [GNUnet-SVN] r37197 - in gnunet/src: include my
Date: Tue, 24 May 2016 18:16:01 +0200

Author: christophe.genevey
Date: 2016-05-24 18:16:01 +0200 (Tue, 24 May 2016)
New Revision: 37197

Modified:
   gnunet/src/include/gnunet_my_lib.h
   gnunet/src/my/Makefile.am
   gnunet/src/my/my.c
   gnunet/src/my/my_result_helper.c
Log:
fix result and query helper

Modified: gnunet/src/include/gnunet_my_lib.h
===================================================================
--- gnunet/src/include/gnunet_my_lib.h  2016-05-23 15:40:28 UTC (rev 37196)
+++ gnunet/src/include/gnunet_my_lib.h  2016-05-24 16:16:01 UTC (rev 37197)
@@ -299,10 +299,96 @@
  */
 #define GNUNET_MY_result_spec_auto_from_type(dst) 
GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst)))
 
+
 /**
  * FIXME.
  *
  */
+ 
+ /**
+  * Variable-size result expected
+  *
+  * @param[out] dst where to store the result, allocated
+  * @param[out] sptr where to store the size of @a dst
+  * @return array entru for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_variable_size (void **dst,
+                                    size_t *ptr_size);
+/**
+  * RSA public key expected
+  *
+  * @param name name of the field in the table
+  * @param[out] rsa where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
+
+/**
+  * RSA signature expected.
+  *
+  * @param[out] sig where to store the result;
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
+
+/**
+  * 0- terminated string exprected.
+  *
+  * @param[out] dst where to store the result, allocated
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_string (char **dst);
+
+/**
+  * Absolute time expected
+  *
+  * @param name name of the field in the table
+  * @param[out] at where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at);
+
+/**
+  * Absolute time in network byte order expected
+  *
+  * @param[out] at where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
+
+/**
+  * uint16_t expected
+  *
+  * @param[out] u16 where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint16 (uint16_t *u16);
+
+/**
+  * uint32_t expected
+  *
+  * @param[out] u32 where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint32 (uint32_t *u32);
+
+/**
+  * uint64_t expected.
+  *
+  * @param[out] u64 where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint64 (uint64_t *u64);
+
 int
 GNUNET_MY_extract_result (MYSQL_BIND * result,
                           struct GNUNET_MY_QueryParam *qp,

Modified: gnunet/src/my/Makefile.am
===================================================================
--- gnunet/src/my/Makefile.am   2016-05-23 15:40:28 UTC (rev 37196)
+++ gnunet/src/my/Makefile.am   2016-05-24 16:16:01 UTC (rev 37197)
@@ -15,7 +15,9 @@
 
 libgnunetmy_la_SOURCES = \
   my.c \
-  my_query_helper.c
+  my_query_helper.c \
+  my_result_helper.c
+
 libgnunetmy_la_LIBADD = $(MYSQL_LDFLAGS) -lmysqlclient \
  $(top_builddir)/src/mysql/libgnunetmysql.la \
  $(top_builddir)/src/util/libgnunetutil.la
@@ -22,3 +24,17 @@
 libgnunetmy_la_LDFLAGS = \
  $(GN_LIB_LDFLAGS) \
   -version-info 0:0:0
+
+TESTS = \
+ test_my
+
+check_PROGRAMS= \
+ test_my
+
+test_my_SOURCES = \
+  test_my.c
+test_my_LDADD = \
+  libgnunetmy.la \
+  $(top_builddir)/src/util/libgnunetutil.la  \
+  -lmysqlclient $(XLIB)
+

Modified: gnunet/src/my/my.c
===================================================================
--- gnunet/src/my/my.c  2016-05-23 15:40:28 UTC (rev 37196)
+++ gnunet/src/my/my.c  2016-05-24 16:16:01 UTC (rev 37197)
@@ -34,8 +34,10 @@
  * @param mc mysql context
  * @param sh handle to SELECT statment
  * @param params parameters to the statement
- * @return
+ * @return mysql result
  */
+
+ /***** FIXE THIS FUNCTION *****/
 int
 GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
                          struct GNUNET_MYSQL_StatementHandle *sh,

Modified: gnunet/src/my/my_result_helper.c
===================================================================
--- gnunet/src/my/my_result_helper.c    2016-05-23 15:40:28 UTC (rev 37196)
+++ gnunet/src/my/my_result_helper.c    2016-05-24 16:16:01 UTC (rev 37197)
@@ -18,30 +18,9 @@
 
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_pq_lib.h"
+#include "gnunet_my_lib.h"
 
 /**
-  * Function called to clean up memory allocated
-  * by a #GNUNET_MY_ResultConverter.
-  *
-  * @param cls closure
-  * @param rd result data to clean up
-  */
-static void
-clean_varsize_blob (void *cls,
-                    void *rs)
-{
-  void **dst = rd;
-
-  if (NULL != *dst)
-  {
-    GNUNET_free (*dst);
-    *dst = NULL;
-  }
-}
-
-
-/**
   * extract data from a Mysql database @a result at row @a row
   *
   * @param cls closure
@@ -66,8 +45,8 @@
   void *idst;
   size_t len;
 
-  MYSQL_ROW * rows;
-  MYSQL_FIELD * field;
+  MYSQL_ROW rows;
+  MYSQL_FIELD *field;
 
   rows = mysql_fetch_row (result);
 
@@ -74,7 +53,7 @@
   field = mysql_fetch_field (result);
 
   //If it's the correct field
-  if (field != fname)
+  if (field->name != fname)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
                 "Field '%s' does not exist in result",
@@ -122,7 +101,7 @@
     (void *)(dst),
     0,
     ptr_size
-  }
+  };
 
   return res;
 }
@@ -142,7 +121,7 @@
   *
   */
 static int
-extracted_fixed_blob (void *cls,
+extract_fixed_blob (void *cls,
                       MYSQL_RES * result,
                       int row,
                       const char * fname,
@@ -152,7 +131,7 @@
   size_t len;
   const char *res;
 
-  MYSQL_ROW * rows;
+  MYSQL_ROW rows;
   MYSQL_FIELD * field;
 
   rows = mysql_fetch_row (result);
@@ -160,7 +139,7 @@
   field = mysql_fetch_field (result);
 
   //If it's the correct field
-  if (field != fname)
+  if (field->name != fname)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
                 "Field '%s' does not exist in result",
@@ -235,7 +214,7 @@
 static int
 extract_rsa_public_key (void *cls,
                         MYSQL_RES *result,
-                        int rown,
+                        int row,
                         const char *fname,
                         size_t *dst_size,
                         void *dst)
@@ -244,7 +223,7 @@
   size_t len;
   const char *res;
 
-  MYSQL_ROW * rows;
+  MYSQL_ROW rows;
   MYSQL_FIELD * field;
 
   *pk = NULL;
@@ -254,7 +233,7 @@
   field = mysql_fetch_field (result);
 
   //If it's the correct field
-  if (field != fname)
+  if (field->name != fname)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
                 "Field '%s' does not exist in result",
@@ -286,26 +265,6 @@
 }
 
 /**
-  * Function called to clean up memory allocated
-  * by a #GNUNET_MY_ResultConverter
-  *
-  * @param cls closure
-  * @param rd result data to clean up
-  */
-static void
-clean_rsa_public_key (void *cls,
-                      void *rd)
-{
-  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
-  if (NULL != *pk)
-  {
-    GNUNET_CRYPTO_rsa_public_key_free (*pk);
-    *pk = NULL;
-  }
-}
-
-
-/**
   * RSA public key expected
   *
   * @param name name of the field in the table
@@ -351,7 +310,7 @@
   const char *res;
 
   
-  MYSQL_ROW * rows;
+  MYSQL_ROW rows;
   MYSQL_FIELD * field;
 
   *sig = NULL;
@@ -361,7 +320,7 @@
   field = mysql_fetch_field (result);
 
   //If it's the correct field
-  if (field == fname)
+  if (field->name == fname)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
                 "Field '%s' does not exist in result",
@@ -437,7 +396,7 @@
   size_t len;
   const char *res;
 
-  MYSQL_ROW * rows;
+  MYSQL_ROW rows;
   MYSQL_FIELD * field;
 
   *str = NULL;
@@ -544,6 +503,43 @@
               void *dst)
 {
     //TO COMPLETE 
+  uint16_t *udst = dst;
+  const uint16_t *res;
+
+  MYSQL_ROW rows;
+  MYSQL_FIELD * field;
+
+  rows = mysql_fetch_row (result);
+
+  field = mysql_fetch_field (result);
+
+  //If it's the correct field
+  if (field->name == fname)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                "Field '%s' does not exist in result",
+                fname);
+    return GNUNET_SYSERR;
+  }
+
+
+  if (rows[row] == NULL)
+  {
+    return GNUNET_SYSERR;
+  }
+
+  GNUNET_assert (NULL != dst);
+
+  if (sizeof (uint16_t) != *dst_size)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  res = (uint16_t) rows[row];
+  *udst = ntohs (*res);
+
+  return GNUNET_OK;
 }
 
 /**
@@ -566,4 +562,161 @@
 }
 
 /**
+  * Extrac data from a  MYSQL database @a result at row @a row
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in, out] dst_size where to store size of result, may be NULL
+  * @param[out] dst where to store the result
+  * @return
+  *      #GNUNET_OK if all results could be extracted
+  *      #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+  */
+static int
+extract_uint32 (void *cls,
+                MYSQL_RES * result,
+                int row,
+                const char *fname,
+                size_t *dst_size,
+                void *dst)
+{
+  uint32_t *udst = dst;
+  const uint32_t *res;
+
+  MYSQL_ROW rows;
+  MYSQL_FIELD * field;
+
+  rows = mysql_fetch_row (result);
+
+  field = mysql_fetch_field (result);
+
+  //If it's the correct field
+  if (field->name == fname)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                "Field '%s' does not exist in result",
+                fname);
+    return GNUNET_SYSERR;
+  }
+
+
+  if (rows[row] == NULL)
+  {
+    return GNUNET_SYSERR;
+  }
+
+  GNUNET_assert (NULL != dst);
+
+  if (sizeof (uint32_t) != *dst_size)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  res = (uint32_t) rows[row];
+
+  *udst = ntohl (*res);
+  return GNUNET_OK;
+}
+
+/**
+  * uint32_t expected
+  *
+  * @param[out] u32 where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint32 (uint32_t *u32)
+{
+  struct GNUNET_MY_ResultSpec res = {
+    &extract_uint32,
+    NULL,
+    (void *) u32,
+    sizeof (*u32),
+    NULL
+  };
+  return res;
+}
+
+/**
+  * Extract data from a MYSQL database @a result at row @a row
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in, out] dst_size where to store size of result, may be null
+  * @param[out] dst where to store the result
+  * @return
+  *    #GNUNET_OK if all results could be extracted
+  *    #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+  */
+static int
+extract_uint64 (void *cls,
+                MYSQL_RES * result,
+                int row, 
+                const char *fname,
+                size_t *dst_size,
+                void *dst)
+{
+  uint64_t *udst = dst;
+  const uint64_t *res;
+
+  MYSQL_ROW rows;
+  MYSQL_FIELD * field;
+
+  rows = mysql_fetch_row (result);
+
+  field = mysql_fetch_field (result);
+
+  //If it's the correct field
+  if (field->name == fname)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                "Field '%s' does not exist in result",
+                fname);
+    return GNUNET_SYSERR;
+  }
+
+
+  if (rows[row] == NULL)
+  {
+    return GNUNET_SYSERR;
+  }
+
+  GNUNET_assert (NULL != dst);
+  if (sizeof (uint64_t) != *dst_size)
+  {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+  }
+
+  res = (uint64_t) rows[row];
+  *udst = GNUNET_ntohll (*res);
+
+  return GNUNET_OK;
+}
+
+
+/**
+  * uint64_t expected.
+  *
+  * @param[out] u64 where to store the result
+  * @return array entry for the result specification to use
+  */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint64 (uint64_t *u64)
+{
+  struct GNUNET_MY_ResultSpec res = {
+    &extract_uint64,
+    NULL,
+    (void *) u64,
+    sizeof (*u64),
+    NULL
+  };
+  return res;
+}
+
 /* end of pq_result_helper.c */
\ No newline at end of file




reply via email to

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