Diff for /libaitsess/src/sess.c between versions 1.5 and 1.5.4.2

version 1.5, 2012/07/22 22:13:48 version 1.5.4.2, 2013/01/17 13:26:37
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 44  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF TH Line 44  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF TH
 SUCH DAMAGE.  SUCH DAMAGE.
 */  */
 #include "global.h"  #include "global.h"
 #include "aitsess.h"  
   
   
 /*  /*
 * sess_FreeValues() Free all values from value array allocated from sess_GetValues() * sess_FreeValues() - Free all values from value array allocated from sess_GetValues()
  *   *
  * @ppsVals = Array strings   * @ppsVals = Array strings
  * return: none   * return: none
Line 63  sess_FreeValues(char *** __restrict ppsVals) Line 62  sess_FreeValues(char *** __restrict ppsVals)
                 return;                  return;
   
         for (ptr = *ppsVals; *ptr; ptr++)          for (ptr = *ppsVals; *ptr; ptr++)
                io_free(*ptr);                e_free(*ptr);
        io_free(*ppsVals);        e_free(*ppsVals);
         *ppsVals = NULL;          *ppsVals = NULL;
 }  }
   
 /*  /*
 * sess_GetValues() Get all values from session shared memory * sess_GetValues() - Get all values from session shared memory
  *   *
  * @s = Session item   * @s = Session item
  * @ppsVals = Return array strings   * @ppsVals = Return array strings
 * return: -1 error: in parameter, !=-1 count of returned strings in ppsVals (must be free after use!) * return: -1 error: in parameter, !=-1 count of returned strings in ppsVals 
  *                (must be sess_FreeValues after use!)
  */   */
 int  int
 sess_GetValues(ait_sess_t * __restrict s, char ***ppsVals)  sess_GetValues(ait_sess_t * __restrict s, char ***ppsVals)
Line 84  sess_GetValues(ait_sess_t * __restrict s, char ***ppsV Line 84  sess_GetValues(ait_sess_t * __restrict s, char ***ppsV
   
         if (!s || !ppsVals)          if (!s || !ppsVals)
                 return -1;                  return -1;
        valz = io_malloc(sizeof(caddr_t));        valz = e_malloc(sizeof(caddr_t));
         if (!valz) {          if (!valz) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         } else          } else
                 *valz = NULL;                  *valz = NULL;
   
        // allocated memory & mirrored shared memory into this        /* allocated memory & mirrored shared memory into this */
        Shared = io_malloc(s->eom);        Shared = e_malloc(s->eom);
         if (!Shared) {          if (!Shared) {
                 LOGERR;                  LOGERR;
                io_free(valz);                e_free(valz);
                 return -1;                  return -1;
         } else          } else
                 memcpy(Shared, s->addr, s->eom);                  memcpy(Shared, s->addr, s->eom);
Line 107  sess_GetValues(ait_sess_t * __restrict s, char ***ppsV Line 107  sess_GetValues(ait_sess_t * __restrict s, char ***ppsV
                 else                  else
                         i++;                          i++;
   
                valz = io_realloc(valz, (i + 1) * sizeof(caddr_t));                valz = e_realloc(valz, (i + 1) * sizeof(caddr_t));
                 if (!valz) {                  if (!valz) {
                         LOGERR;                          LOGERR;
                        io_free(Shared);                        e_free(Shared);
                         return -1;                          return -1;
                 } else                  } else
                         valz[i] = NULL;                          valz[i] = NULL;
   
                valz[i - 1] = io_strdup(peer);                valz[i - 1] = e_strdup(peer);
         }          }
   
        io_free(Shared);        e_free(Shared);
         *ppsVals = valz;          *ppsVals = valz;
         return i;          return i;
 }  }
   
 /*  /*
 * sess_GetValue() Get value from session shared memory from attribute * sess_GetValue() - Get value from session shared memory from attribute
  *   *
  * @s = Session item   * @s = Session item
  * @csAttr = Attribute for search   * @csAttr = Attribute for search
  * @psVal = Return string buffer   * @psVal = Return string buffer
  * @pnLen = Length of return string buffer,    * @pnLen = Length of return string buffer, 
         // *{pnLen} input is max_size of buffer & output is really taken bytes          // *{pnLen} input is max_size of buffer & output is really taken bytes
 * return: 0 not found, -1 error: in parameter, >0 get position, if define item merged with IS_DEF * return: 0 not found, -1 error: in parameter, >0 get position, 
  *        if define item merged with IS_DEF
  */   */
 int  int
 sess_GetValue(ait_sess_t * __restrict s, const char *csAttr, char *psVal, int *pnLen)  sess_GetValue(ait_sess_t * __restrict s, const char *csAttr, char *psVal, int *pnLen)
Line 150  sess_GetValue(ait_sess_t * __restrict s, const char *c Line 151  sess_GetValue(ait_sess_t * __restrict s, const char *c
                         return -1;                          return -1;
         }          }
   
        // allocated memory & mirrored shared memory into this        /* allocated memory & mirrored shared memory into this */
        Shared = io_malloc(s->eom);        Shared = e_malloc(s->eom);
         if (!Shared) {          if (!Shared) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
Line 171  sess_GetValue(ait_sess_t * __restrict s, const char *c Line 172  sess_GetValue(ait_sess_t * __restrict s, const char *c
                         } else                          } else
                                 def = IS_DEF;                                  def = IS_DEF;
   
                        io_free(Shared);                        e_free(Shared);
                         return i | def;                          return i | def;
                 }                  }
         }          }
   
        io_free(Shared);        e_free(Shared);
         return 0;          return 0;
 }  }
   
 /*  /*
 * sess_DelValue() Delete item from session shared memory * sess_DelValue() - Delete item from session shared memory
  *   *
  * @s = Session item   * @s = Session item
  * @csAttr = Attribute for erasing   * @csAttr = Attribute for erasing
Line 203  sess_DelValue(ait_sess_t * __restrict s, const char *c Line 204  sess_DelValue(ait_sess_t * __restrict s, const char *c
         strlcpy(szAttr, csAttr, sizeof szAttr);          strlcpy(szAttr, csAttr, sizeof szAttr);
         strlcat(szAttr, "=", sizeof szAttr);          strlcat(szAttr, "=", sizeof szAttr);
   
        Buffer = io_malloc(s->eom);        Buffer = e_malloc(s->eom);
         if (!Buffer) {          if (!Buffer) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         } else          } else
                 memset(Buffer, 0, s->eom);                  memset(Buffer, 0, s->eom);
        Shared = io_malloc(s->eom);        Shared = e_malloc(s->eom);
         if (!Shared) {          if (!Shared) {
                 LOGERR;                  LOGERR;
                io_free(Buffer);                e_free(Buffer);
                 return -1;                  return -1;
         } else {          } else {
                 DEC_SEM(s);                  DEC_SEM(s);
Line 236  sess_DelValue(ait_sess_t * __restrict s, const char *c Line 237  sess_DelValue(ait_sess_t * __restrict s, const char *c
                 msync(s->addr, 0, MS_SYNC | MS_INVALIDATE);                  msync(s->addr, 0, MS_SYNC | MS_INVALIDATE);
   
         INC_SEM(s);          INC_SEM(s);
        io_free(Shared);        e_free(Shared);
        io_free(Buffer);        e_free(Buffer);
         return 0;          return 0;
 }  }
   
 /*  /*
 * sess_SetValue() Set item into session shared memory or update if find it * sess_SetValue() - Set item into session shared memory or update if exists
  *   *
  * @s = Session item   * @s = Session item
  * @csAttr = Attribute   * @csAttr = Attribute
Line 265  sess_SetValue(ait_sess_t * __restrict s, const char *c Line 266  sess_SetValue(ait_sess_t * __restrict s, const char *c
         strlcpy(szAttr, csAttr, sizeof szAttr);          strlcpy(szAttr, csAttr, sizeof szAttr);
         strlcat(szAttr, "=", sizeof szAttr);          strlcat(szAttr, "=", sizeof szAttr);
   
        Buffer = io_malloc(s->eom);        Buffer = e_malloc(s->eom);
         if (!Buffer) {          if (!Buffer) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         } else          } else
                 memset(Buffer, 0, s->eom);                  memset(Buffer, 0, s->eom);
        Shared = io_malloc(s->eom);        Shared = e_malloc(s->eom);
         if (!Shared) {          if (!Shared) {
                 LOGERR;                  LOGERR;
                io_free(Buffer);                e_free(Buffer);
                 return -1;                  return -1;
         } else {          } else {
                 DEC_SEM(s);                  DEC_SEM(s);
Line 320  sess_SetValue(ait_sess_t * __restrict s, const char *c Line 321  sess_SetValue(ait_sess_t * __restrict s, const char *c
                 msync(s->addr, 0, MS_SYNC | MS_INVALIDATE);                  msync(s->addr, 0, MS_SYNC | MS_INVALIDATE);
   
         INC_SEM(s);          INC_SEM(s);
        io_free(Shared);        e_free(Shared);
        io_free(Buffer);        e_free(Buffer);
         return upd | def;          return upd | def;
 }  }
   
   
 /*  /*
 * sess_prepareSession() Attach to shared memory and de-marshaling data * sess_prepareSession() - Attach to shared memory and de-marshaling data
  *   *
  * @s = Session   * @s = Session
  * @useDirect = Use direct shared memory if !=0 or snapshot of data to array   * @useDirect = Use direct shared memory if !=0 or snapshot of data to array
Line 342  sess_prepareSession(ait_sess_t * __restrict s, char us Line 343  sess_prepareSession(ait_sess_t * __restrict s, char us
   
         assert(s);          assert(s);
         if (!s) {          if (!s) {
                sess_SetErr(EINVAL, "Error:: invalid argument\n");                sess_SetErr(EINVAL, "Invalid argument\n");
                 return NULL;                  return NULL;
         }          }
         if (s->addr) {          if (s->addr) {
                sess_SetErr(EINVAL, "Error:: already attached memory\n");                sess_SetErr(EINVAL, "Already attached memory\n");
                 return NULL;                  return NULL;
         }          }
   
Line 358  sess_prepareSession(ait_sess_t * __restrict s, char us Line 359  sess_prepareSession(ait_sess_t * __restrict s, char us
         if (hdr->hdr_magic != SESS_AIT_MAGIC) {          if (hdr->hdr_magic != SESS_AIT_MAGIC) {
                 DETACH_MEMORY(s);                  DETACH_MEMORY(s);
   
                sess_SetErr(EINVAL, "Error:: shared memory not contains values with proper format\n");                sess_SetErr(EINVAL, "Shared memory not contains values with proper format\n");
                 return NULL;                  return NULL;
         }          }
   
         DEC_SEM(s);          DEC_SEM(s);
         s->zcpy = useDirect;          s->zcpy = useDirect;
        arr = io_map2vars(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t),         arr = ait_map2vars(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), 
                         hdr->hdr_argc, useDirect);                          hdr->hdr_argc, useDirect);
         INC_SEM(s);          INC_SEM(s);
   
Line 374  sess_prepareSession(ait_sess_t * __restrict s, char us Line 375  sess_prepareSession(ait_sess_t * __restrict s, char us
 }  }
   
 /*  /*
 * sess_doneSession() Free resources allocated with sess_prepareSession() * sess_doneSession() - Free resources allocated with sess_prepareSession()
  *   *
  * @s = Session   * @s = Session
  * @arr = Array with variables for free   * @arr = Array with variables for free
Line 385  sess_doneSession(ait_sess_t * __restrict s, array_t ** Line 386  sess_doneSession(ait_sess_t * __restrict s, array_t **
 {  {
         assert(s);          assert(s);
         if (!s) {          if (!s) {
                sess_SetErr(EINVAL, "Error:: invalid argument\n");                sess_SetErr(EINVAL, "Invalid argument\n");
                 return;                  return;
         }          }
   
         if (!s->zcpy)          if (!s->zcpy)
                io_arrayFree(*arr);                array_Free(*arr);
         else          else
                 DETACH_MEMORY(s);                  DETACH_MEMORY(s);
        io_arrayDestroy(arr);        array_Destroy(arr);
 }  }
   
 /*  /*
 * sess_commitSession() Commit data to shared memory * sess_commitSession() - Commit data to shared memory
  *   *
  * @s = Session   * @s = Session
  * @arr = Array with variables for save   * @arr = Array with variables for save
Line 411  sess_commitSession(ait_sess_t * __restrict s, array_t  Line 412  sess_commitSession(ait_sess_t * __restrict s, array_t 
   
         assert(s && arr);          assert(s && arr);
         if (!s || !arr) {          if (!s || !arr) {
                sess_SetErr(EINVAL, "Error:: invalid argument\n");                sess_SetErr(EINVAL, "Invalid argument\n");
                 return -1;                  return -1;
         }          }
   
Line 423  sess_commitSession(ait_sess_t * __restrict s, array_t  Line 424  sess_commitSession(ait_sess_t * __restrict s, array_t 
                 hdr = (sess_hdr_t*) s->addr;                  hdr = (sess_hdr_t*) s->addr;
   
         DEC_SEM(s);          DEC_SEM(s);
        if ((ret = io_vars2map(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), arr)) != -1) {        if ((ret = ait_vars2map(s->addr + sizeof(sess_hdr_t), 
                                         s->eom - sizeof(sess_hdr_t), arr)) != -1) {
                 hdr->hdr_magic = SESS_AIT_MAGIC;                  hdr->hdr_magic = SESS_AIT_MAGIC;
                hdr->hdr_argc = io_arraySize(arr);                hdr->hdr_argc = array_Size(arr);
                 ret += sizeof(sess_hdr_t);                  ret += sizeof(sess_hdr_t);
         }          }
         INC_SEM(s);          INC_SEM(s);

Removed from v.1.5  
changed lines
  Added in v.1.5.4.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>