Advertisement
Guest User

erika

a guest
Jan 19th, 2009
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. /*
  2. * logging.h
  3. *
  4. * provide logging functions for Microservices
  5. */
  6. #ifndef __inc_logging_
  7. #define __inc_logging_ 1
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "libpq-fe.h"
  12. #include <gcrypt.h>
  13. #include <string.h>
  14. #include <assert.h>
  15. #include <sys/time.h>
  16.  
  17. #define MAXLOGSIZE 1024
  18. #define BUFFER_MAXSIZE 2048
  19. #define MAXFILENAMELEN 1024
  20. #define HASH_TYPE GCRY_MD_MD5
  21. #define HASH_NAME "md5"
  22.  
  23. // int debug = 1;
  24. PGconn *conn;
  25.  
  26. /** close database connection
  27. */
  28. void exit_nicely ( );
  29.  
  30. /** query database - TODO umstricken
  31. * @param const char* query
  32. */
  33. PGresult* pquery ( const char *query );
  34.  
  35. /** create a sexp for the sign parameters
  36. * @param gcry_sexp_t *sign_parms holds the result (parameters for signing)
  37. * @param const char *plain holds the string to be signed
  38. */
  39. void make_sign_parameters ( gcry_sexp_t *sign_parms, const char *plain );
  40.  
  41. /** verifies a signature
  42. * @param char *message plain text message
  43. * @param gcry_sexp_t sig signature of which the validity is to be checked
  44. * @param gcry_sexp_t pubkey public key that will be used for the check
  45. */
  46. gcry_error_t verifysig ( char* message, gcry_sexp_t sig, gcry_sexp_t pubkey );
  47.  
  48. /** write a sexp in GCRY_FMT_ADVANCED Format to *filename
  49. * @param const char *filename holds the filename to be written to
  50. * @param gcry_sexp_t *sexp holds the sexp to be written
  51. */
  52. int write_sexptofile ( const char *filename, gcry_sexp_t *sexp );
  53.  
  54. /** reads a sexp from a file given by handle
  55. * @param FILE *handle is the file handle of the for reading opened file
  56. * @param gcry_sexp_t *sexp holds the result
  57. */
  58. int read_sexpfromfile ( const char *filename , gcry_sexp_t *sexp );
  59.  
  60. /** obtains a keypair either through generating it or by reading ot from the files in the global skey and pkey variables
  61. * @param gcry_sexp_t *skey is a sexp that will hold the secret key after reading
  62. * @param gcry_sexp_t *pubkey a sexp that will hold the public key after reading
  63. */
  64.  
  65. void obtainkeys ( gcry_sexp_t* skey, gcry_sexp_t* pubkey );
  66.  
  67. /** sign a message using a given skey and store result in *sig
  68. * @param const char *message is the plain text message to be signed
  69. * @param gcry_sexp_t *sig is a pointer to where the signature sexp will be stored
  70. * @param gcry_sexp_t *skey is a pointer to the secret key that will be used for signing
  71. */
  72. gcry_error_t sign ( const char *message, gcry_sexp_t *sig, gcry_sexp_t *skey );
  73.  
  74. /** sets the string *target to the content of *fname
  75. * @param char *target is the target to be written to
  76. * @param const char *fname holds the new filename
  77. */
  78. int setfname ( char *target, const char *fname );
  79.  
  80. /** logs a message to a postgresql server. the primary key will be auto incremented and is not included in the log. A Time is automatically created and logged with the rest of the data
  81. * @param const char *user
  82. * @param const char *service
  83. * @param const char *dig_obj
  84. * @param const char *message
  85. */
  86. int logmessage ( const char *user, const char *service, const char *dig_obj, const char *message );
  87.  
  88. /** converts the null terminated string id to a long long
  89. * @param char *id
  90. */
  91. long long stringtolong(const char *id);
  92.  
  93. // sexp ausgeben
  94. void
  95. print_sexp(gcry_sexp_t sexp);
  96.  
  97.  
  98. // returning something negative on an internal error
  99. // if verification fails it will return the ID of the first failed row
  100. // will start verification at id so this can resume a verification if it failed previously
  101. long long verifyrows ( char * dig_obj, unsigned long long id );
  102.  
  103. // ATM this function is full of shit
  104. void print_pgresult ( PGresult **res );
  105.  
  106. long long mypow(long long i, long long j);
  107. #endif
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement