modules/ud/ud_misc.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. transaction_free
  2. transaction_new
  3. UD_ack

   1 /***************************************
   2   $Revision: 1.19 $
   3 
   4   Miscellaneous functions to support UD
   5 
   6   Status: NOT REVUED, NOT TESTED
   7 
   8  Author(s):       Chris Ottrey, Andrei Robachevsky
   9 
  10   ******************/ /******************
  11   Modification History:
  12         andrei (17/01/2000) Created.
  13   ******************/ /******************
  14   Copyright (c) 2000,2001,2002                    RIPE NCC
  15  
  16   All Rights Reserved
  17   
  18   Permission to use, copy, modify, and distribute this software and its
  19   documentation for any purpose and without fee is hereby granted,
  20   provided that the above copyright notice appear in all copies and that
  21   both that copyright notice and this permission notice appear in
  22   supporting documentation, and that the name of the author not be
  23   used in advertising or publicity pertaining to distribution of the
  24   software without specific, written prior permission.
  25   
  26   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  27   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  28   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  29   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  30   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  31   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  32  ***************************************/
  33 
  34 #include "rip.h"
  35 
  36 /************************************************************
  37 * void transaction_free()                                   *
  38 *                                                           *
  39 * Frees memory allocated for a transaction                  *
  40 *                                                           *
  41 ************************************************************/
  42 
  43 void transaction_free(Transaction_t *tr) {
     /* [<][>][^][v][top][bottom][index][help] */
  44   if(tr) {
  45     g_string_free(tr->error_script, TRUE);
  46     g_string_free(tr->K, TRUE);
  47     /* free nic_handle_t structure used for NHR stuff */
  48     if(tr->nh)free_nh(tr->nh);
  49     if(tr->save){
  50             UT_free(tr->save);
  51     }
  52     if(tr->packptr)UT_free(tr->packptr);
  53     
  54     if(tr->query)g_string_free(tr->query, TRUE);
  55     if(tr->object)rpsl_object_delete(tr->object);
  56     UT_free(tr->object_txt);
  57     
  58     UT_free(tr);
  59   }  
  60 } /* transaction_free() */
  61 
  62 /************************************************************
  63 * Transaction_t *transaction_new()                          *
  64 *                                                           *
  65 * Creates a transaction                                     *
  66 *                                                           *
  67 ************************************************************/
  68 Transaction_t *transaction_new(SQ_connection_t *sql_connection, C_Type_t class_type) {
     /* [<][>][^][v][top][bottom][index][help] */
  69   Transaction_t *tr = (Transaction_t *)UT_calloc(1, sizeof(Transaction_t));
  70 
  71   tr->sql_connection = sql_connection;
  72   tr->class_type = class_type;
  73   tr->thread_upd=TR_UPDATE;
  74   tr->thread_ins=TR_INSERT;
  75   tr->succeeded = 1;
  76   tr->error_script = g_string_sized_new(STR_XL);
  77   tr->K = g_string_sized_new(STR_L);
  78   tr->sequence_id=1; /* we start from 1*/
  79   tr->packptr=UT_calloc(1, sizeof(rp_upd_pack_t));
  80   tr->query = g_string_sized_new(STR_XL);
  81   
  82   /* check memory allocations */
  83   if((tr->error_script == NULL) || (tr->K == NULL) || (tr->query == NULL)) {
  84     ER_perror(FAC_UD, UD_MEM, "cannot allocate gstring\n");
  85     die;
  86   }
  87 
  88   
  89   return tr;
  90 } /* transaction_new() */
  91 /************************************************************
  92 * int UD_ack()                                            *
  93 *
  94 * Sends an acknowledgement to DBupdate and receives a reply *                                                           *
  95 *                                                           *
  96 * Return codes:                                             *
  97 *                                                           *
  98 * 0  - OK
  99 * -1 - 
 100 ************************************************************/
 101 int UD_ack(Transaction_t* tr)
     /* [<][>][^][v][top][bottom][index][help] */
 102 {
 103 GString *g_buff;
 104 int res, error;
 105  
 106  /* if we are not in update/server mode - no ack is needed - just return */
 107  if(IS_STANDALONE(tr->mode)) return(0);
 108  if(!IS_UPDATE(tr->mode)) return(0);
 109  
 110  if ((g_buff = g_string_sized_new(STR_L)) == NULL){ 
 111       ER_perror(FAC_UD, UD_MEM, "cannot allocate gstring\n");
 112       die; 
 113  }
 114 
 115  if(tr->succeeded==0) { /* update failed */
 116    error = tr->error;
 117  }
 118  else error = 0;
 119 
 120  g_string_sprintf(g_buff, "%%ERROR %d\n%s\n", error, (tr->error_script)->str);
 121  res = SK_puts(tr->socket, g_buff->str, NULL);
 122  g_string_free(g_buff, TRUE);
 123  /* close the connection */
 124 /* Let DBupdate close the connection */
 125 /* close(tr->socket); */
 126  return(res);           
 127 }
 128 

/* [<][>][^][v][top][bottom][index][help] */