version 1.1.2.1, 2013/03/13 14:17:53
|
version 1.1.2.2, 2013/03/13 14:25:32
|
Line 47 SUCH DAMAGE.
|
Line 47 SUCH DAMAGE.
|
|
|
|
|
/* |
/* |
|
* sess_initSession() - Initializing session structure, |
|
* if session file not exists creating with specified tech |
|
* |
|
* @id = Technology using in session. SHARED_IPC IPC tech or SHARED_MAP BSD MemoryMap tech |
|
* @csFName = Session filename for build key and identified |
|
* @Sess = Session item, if =NULL allocate memory for session after use must be free! |
|
* return: 0 OK new key created, -1 error: no memory or file not created, 1 OK key finded |
|
*/ |
|
int |
|
sess_initSession(int id, const char *csFName, ait_sess_t ** __restrict Sess) |
|
{ |
|
int h, ret = 0; |
|
char szStr[STRSIZ]; |
|
|
|
if (!csFName) { |
|
sess_SetErr(EINVAL, "Filename is NULL"); |
|
return -1; |
|
} |
|
if (id < SHARED_UNKNOWN || id > SHARED_MAP) { |
|
sess_SetErr(EPROTONOSUPPORT, "Session type not supported"); |
|
return -1; |
|
} |
|
|
|
if (!*Sess) { |
|
*Sess = e_malloc(sizeof(ait_sess_t)); |
|
if (!*Sess) { |
|
LOGERR; |
|
return -1; |
|
} |
|
} |
|
memset(*Sess, 0, sizeof(ait_sess_t)); |
|
strlcpy((*Sess)->name, csFName, sizeof (*Sess)->name); |
|
|
|
h = open((*Sess)->name, O_WRONLY | O_CREAT | O_EXCL, MEM_MODE); |
|
if (h == -1) { |
|
if (errno != EEXIST) { |
|
LOGERR; |
|
e_free(*Sess); |
|
return -1; |
|
} |
|
/* If key file exist, session already connected */ |
|
h = open((*Sess)->name, O_RDONLY); |
|
if (h == -1) { |
|
LOGERR; |
|
e_free(*Sess); |
|
return -1; |
|
} |
|
ret = read(h, szStr, sizeof szStr); |
|
if (ret == -1) { |
|
LOGERR; |
|
close(h); |
|
e_free(*Sess); |
|
return -1; |
|
} |
|
if (!strncmp(szStr, "IPC@", 4) && id == SHARED_IPC) { |
|
ret = 1; |
|
|
|
(*Sess)->sess.create = (int (*)(int, long, void*, ...)) ipc_createSession; |
|
(*Sess)->sess.destroy = (void (*)(void*)) ipc_destroySession; |
|
(*Sess)->sess.attach = (void* (*)(void*, void*)) ipc_attachSession; |
|
(*Sess)->sess.detach = (void (*)(void*)) ipc_detachSession; |
|
(*Sess)->sess.notSem = (void (*)(void*)) ipc_notSemaphore; |
|
(*Sess)->sess.isSemOK = (int (*)(void*)) ipc_isSemaphoreOK; |
|
(*Sess)->sess.incSem = (int (*)(void*)) ipc_incSemaphore; |
|
(*Sess)->sess.decSem = (int (*)(void*)) ipc_decSemaphore; |
|
} else if (!strncmp(szStr, "MAP@", 4) && id == SHARED_MAP) { |
|
ret = 1; |
|
|
|
(*Sess)->sess.create = (int (*)(int, long, void*, ...)) map_createSession; |
|
(*Sess)->sess.destroy = (void (*)(void*)) map_destroySession; |
|
(*Sess)->sess.attach = (void* (*)(void*, void*)) map_attachSession; |
|
(*Sess)->sess.detach = (void (*)(void*)) map_detachSession; |
|
(*Sess)->sess.notSem = (void (*)(void*)) map_notSemaphore; |
|
(*Sess)->sess.isSemOK = (int (*)(void*)) map_isSemaphoreOK; |
|
(*Sess)->sess.incSem = (int (*)(void*)) map_incSemaphore; |
|
(*Sess)->sess.decSem = (int (*)(void*)) map_decSemaphore; |
|
} else { |
|
sess_SetErr(EPROTONOSUPPORT, |
|
"Session type not supported or wrong session type"); |
|
close(h); |
|
e_free(*Sess); |
|
return -1; |
|
} |
|
/* key found */ |
|
} else { |
|
/* Build new key & new session */ |
|
if (id == SHARED_IPC) { |
|
strlcpy(szStr, "IPC@", sizeof szStr); |
|
|
|
(*Sess)->sess.create = (int (*)(int, long, void*, ...)) ipc_createSession; |
|
(*Sess)->sess.destroy = (void (*)(void*)) ipc_destroySession; |
|
(*Sess)->sess.attach = (void* (*)(void*, void*)) ipc_attachSession; |
|
(*Sess)->sess.detach = (void (*)(void*)) ipc_detachSession; |
|
(*Sess)->sess.notSem = (void (*)(void*)) ipc_notSemaphore; |
|
(*Sess)->sess.isSemOK = (int (*)(void*)) ipc_isSemaphoreOK; |
|
(*Sess)->sess.incSem = (int (*)(void*)) ipc_incSemaphore; |
|
(*Sess)->sess.decSem = (int (*)(void*)) ipc_decSemaphore; |
|
} else if (id == SHARED_MAP) { |
|
strlcpy(szStr, "MAP@", sizeof szStr); |
|
|
|
(*Sess)->sess.create = (int (*)(int, long, void*, ...)) map_createSession; |
|
(*Sess)->sess.destroy = (void (*)(void*)) map_destroySession; |
|
(*Sess)->sess.attach = (void* (*)(void*, void*)) map_attachSession; |
|
(*Sess)->sess.detach = (void (*)(void*)) map_detachSession; |
|
(*Sess)->sess.notSem = (void (*)(void*)) map_notSemaphore; |
|
(*Sess)->sess.isSemOK = (int (*)(void*)) map_isSemaphoreOK; |
|
(*Sess)->sess.incSem = (int (*)(void*)) map_incSemaphore; |
|
(*Sess)->sess.decSem = (int (*)(void*)) map_decSemaphore; |
|
} else { |
|
sess_SetErr(EINVAL, "Session type must be specified"); |
|
close(h); |
|
unlink(csFName); |
|
e_free(*Sess); |
|
return -1; |
|
} |
|
strlcat(szStr, "ELWIX_Session ("PACKAGE_STRING")\n", sizeof szStr); |
|
write(h, szStr, strlen(szStr)); |
|
|
|
ret = 0; |
|
/* new key created */ |
|
} |
|
close(h); |
|
|
|
(*Sess)->type = id; |
|
(*Sess)->zcpy = (char) ret; |
|
return ret; |
|
} |
|
|
|
/* |
|
* sess_freeSession() - Free allocated memory for session item and delete session file if present name |
|
* |
|
* @Sess = Session item |
|
* return: none |
|
*/ |
|
void |
|
sess_freeSession(ait_sess_t ** __restrict Sess) |
|
{ |
|
if (!Sess || !(*Sess)) |
|
return; |
|
|
|
if ((*Sess)->addr) |
|
DETACH_MEMORY(*Sess); |
|
|
|
/* |
|
memset(&(*Sess)->sess, 0, sizeof (*Sess)->sess); |
|
|
|
(*Sess)->type = SHARED_UNKNOWN; |
|
*/ |
|
|
|
e_free(*Sess); |
|
*Sess = NULL; |
|
} |
|
|
|
|
|
/* |
|
* map_createSession() - MMAP Created session and allocated resources |
|
* |
|
* @nSeed = Seed for securing key, if =-1 must add ready for use key |
|
* @nSize = Allocated shared memory size in bytes |
|
* @Sess = Session item |
|
* @... = If nSeed == -1 add ready for use key value |
|
* return: 0 Ok successful, -1 error: not allocated resources |
|
*/ |
|
int |
|
map_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...) |
|
{ |
|
char szSName[2][FILENAME_MAX]; |
|
va_list lst; |
|
|
|
if (!Sess || !*Sess->name) |
|
return -1; |
|
|
|
if (nSeed != -1) { |
|
/* genkey */ |
|
Sess->key = ftok(Sess->name, nSeed); |
|
if (Sess->key == -1) { |
|
LOGERR; |
|
return -1; |
|
} |
|
} else { |
|
/* get key from va_args */ |
|
va_start(lst, Sess); |
|
Sess->key = va_arg(lst, key_t); |
|
va_end(lst); |
|
} |
|
|
|
/* build semaphore & shared memory name */ |
|
memset(szSName, 0, sizeof szSName); |
|
snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); |
|
#ifdef HAVE_SHM_OPEN |
|
snprintf(szSName[1], FILENAME_MAX, "/%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#else |
|
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#endif |
|
|
|
/* create semaphore & add 1 */ |
|
Sess->id.sid = sem_open(szSName[0], O_CREAT, MEM_MODE); |
|
if (Sess->id.sid == SEM_FAILED) { |
|
LOGERR; |
|
map_destroySession(Sess); |
|
return -1; |
|
} |
|
/* if is new shared memory session, init sempahore with 1 */ |
|
if (!Sess->zcpy) |
|
sem_post(Sess->id.sid); |
|
|
|
/* create file for shared memory storage */ |
|
#ifdef HAVE_SHM_OPEN |
|
Sess->mem.fd = shm_open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
|
#else |
|
Sess->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
|
#endif |
|
if (Sess->mem.fd == -1) { |
|
LOGERR; |
|
map_destroySession(Sess); |
|
return -1; |
|
} |
|
if (!Sess->zcpy) { |
|
#ifdef HAVE_SHM_OPEN |
|
if (ftruncate(Sess->mem.fd, nSize) == -1) { |
|
LOGERR; |
|
map_destroySession(Sess); |
|
return -1; |
|
} |
|
#else |
|
/* if is new shared memory session, fill file with zeros */ |
|
if (lseek(Sess->mem.fd, nSize - 1, SEEK_SET) == -1) { |
|
LOGERR; |
|
map_destroySession(Sess); |
|
return -1; |
|
} else |
|
write(Sess->mem.fd, "", 1); |
|
lseek(Sess->mem.fd, 0, SEEK_SET); |
|
#endif |
|
} |
|
Sess->eom = nSize; |
|
|
|
return (int) Sess->zcpy; |
|
} |
|
|
|
/* |
|
* map_destroySession() - MMAP free shared resources |
|
* |
|
* @Sess = Session item |
|
* return: none |
|
*/ |
|
void |
|
map_destroySession(ait_sess_t * __restrict Sess) |
|
{ |
|
char szSName[2][FILENAME_MAX]; |
|
|
|
if (!Sess || sess_isAttached(Sess) || !*Sess->name) |
|
return; |
|
|
|
memset(szSName, 0, sizeof szSName); |
|
snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); |
|
#ifdef HAVE_SHM_UNLINK |
|
snprintf(szSName[1], FILENAME_MAX, "/%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#else |
|
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#endif |
|
|
|
if (Sess->id.sid != SEM_FAILED) { |
|
sem_close(Sess->id.sid); |
|
sem_unlink(szSName[0]); |
|
} |
|
if (Sess->mem.fd > 2) { |
|
close(Sess->mem.fd); |
|
#ifdef HAVE_SHM_UNLINK |
|
shm_unlink(szSName[1]); |
|
#else |
|
unlink(szSName[1]); |
|
#endif |
|
} |
|
unlink(Sess->name); |
|
memset(Sess->name, 0, sizeof Sess->name); |
|
Sess->eom ^= Sess->eom; |
|
Sess->key ^= Sess->key; |
|
} |
|
|
|
/* |
|
* ipc_createSession() - IPC Created session and allocated resources |
|
* |
|
* @nSeed = Seed for securing key, if =-1 must add ready for use key |
|
* @nSize = Allocated shared memory size in bytes |
|
* @Sess = Session item |
|
* @... = If nSeed == -1 add ready for use key value |
|
* return: 0 Ok successful, -1 error: not allocated resources |
|
*/ |
|
int |
|
ipc_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...) |
|
{ |
|
union semun sems; |
|
va_list lst; |
|
|
|
if (!Sess || !*Sess->name) |
|
return -1; |
|
|
|
if (nSeed != -1) { |
|
/* genkey */ |
|
Sess->key = ftok(Sess->name, nSeed); |
|
if (Sess->key == -1) { |
|
LOGERR; |
|
return -1; |
|
} |
|
} else { |
|
/* get key from va_args */ |
|
va_start(lst, Sess); |
|
Sess->key = va_arg(lst, key_t); |
|
va_end(lst); |
|
} |
|
|
|
/* create semaphore */ |
|
Sess->id.semid = semget(Sess->key, 1, MEM_MODE | IPC_CREAT); |
|
if (Sess->id.semid == -1) { |
|
LOGERR; |
|
ipc_destroySession(Sess); |
|
return -1; |
|
} |
|
/* if is new shared memory session, init sempahore with 1 */ |
|
if (!Sess->zcpy) { |
|
sems.val = 1; |
|
if (semctl(Sess->id.semid, 0, SETVAL, sems) == -1) { |
|
LOGERR; |
|
ipc_destroySession(Sess); |
|
return -1; |
|
} |
|
} |
|
|
|
/* create shared memory object */ |
|
Sess->mem.shmid = shmget(Sess->key, nSize, MEM_MODE | IPC_CREAT); |
|
if (Sess->mem.shmid == -1) { |
|
LOGERR; |
|
ipc_destroySession(Sess); |
|
return -1; |
|
} else |
|
Sess->eom = nSize; |
|
|
|
return (int) Sess->zcpy; |
|
} |
|
|
|
/* |
|
* ipc_destroySession() - IPC free shared resources |
|
* |
|
* @Sess = Session item |
|
* return: none |
|
*/ |
|
void |
|
ipc_destroySession(ait_sess_t * __restrict Sess) |
|
{ |
|
union semun sems; |
|
struct shmid_ds ds; |
|
|
|
if (!Sess || sess_isAttached(Sess)) |
|
return; |
|
|
|
if (Sess->id.semid != -1) |
|
semctl(Sess->id.semid, 0, IPC_RMID, &sems); |
|
if (Sess->mem.shmid != -1) |
|
shmctl(Sess->mem.shmid, IPC_RMID, &ds); |
|
unlink(Sess->name); |
|
memset(Sess->name, 0, sizeof Sess->name); |
|
Sess->eom ^= Sess->eom; |
|
Sess->key ^= Sess->key; |
|
} |
|
|
|
|
|
/* |
|
* map_attachSession() - MMAP Attach to shared memory & return begin address |
|
* |
|
* @s = Session item |
|
* @procMem = Custom start address (optionl) *default must be 0* |
|
* return: NULL failed attach, !=NULL begin address of memory |
|
*/ |
|
void * |
|
map_attachSession(ait_sess_t * __restrict s, void *procMem) |
|
{ |
|
if (!s) |
|
return NULL; |
|
|
|
sync(); |
|
|
|
/* attach to memory */ |
|
s->addr = mmap(procMem, s->eom, PROT_READ | PROT_WRITE, MAP_SHARED, s->mem.fd, 0); |
|
if (s->addr == MAP_FAILED) { |
|
LOGERR; |
|
s->addr = NULL; |
|
} |
|
|
|
return s->addr; |
|
} |
|
|
|
/* |
|
* map_detachSession() - MMAP Detach from shared memory |
|
* |
|
* @s = Session item |
|
* return: none |
|
*/ |
|
void |
|
map_detachSession(ait_sess_t * __restrict s) |
|
{ |
|
if (!s) |
|
return; |
|
|
|
msync(s->addr, 0, MS_SYNC | MS_INVALIDATE); |
|
|
|
if (s->addr && s->eom) { |
|
munmap(s->addr, s->eom); |
|
s->addr = NULL; |
|
} |
|
} |
|
|
|
/* |
|
* ipc_attachSession() - IPC Attach to shared memory & return begin address |
|
* |
|
* @s = Session item |
|
* @procMem = Custom start address (optionl) *default must be 0* |
|
* return: NULL failed attach, !=NULL begin address of memory |
|
*/ |
|
void * |
|
ipc_attachSession(ait_sess_t * __restrict s, void *procMem) |
|
{ |
|
if (!s) |
|
return NULL; |
|
|
|
s->addr = shmat(s->mem.shmid, procMem, 0); |
|
if (s->addr == (void*) -1) { |
|
LOGERR; |
|
s->addr = NULL; |
|
} |
|
|
|
return s->addr; |
|
} |
|
|
|
/* |
|
* ipc_detachSession() - IPC Detach from shared memory |
|
* |
|
* @s = Session item |
|
* return: none |
|
*/ |
|
void |
|
ipc_detachSession(ait_sess_t * __restrict s) |
|
{ |
|
if (!s) |
|
return; |
|
|
|
if (s->addr) { |
|
shmdt(s->addr); |
|
s->addr = NULL; |
|
} |
|
} |
|
|
|
/* |
|
* sess_isAttached() - Check for attached shared memory |
|
* |
|
* @s = Session item |
|
* return: -1 null session item, 0 not attached, 1 attached memory |
|
*/ |
|
inline int |
|
sess_isAttached(ait_sess_t * __restrict s) |
|
{ |
|
if (!s) |
|
return -1; |
|
|
|
return (s->addr ? 1 : 0); |
|
} |
|
|
|
|
|
/* |
|
* map_notSemaphore() - MMAP negative block if semaphore isn`t signaled |
|
* |
|
* @s = Session item |
|
* return: none |
|
*/ |
|
void |
|
map_notSemaphore(ait_sess_t * __restrict s) |
|
{ |
|
int i = -1; |
|
|
|
if (!s) |
|
return; |
|
|
|
sem_getvalue(s->id.sid, &i); |
|
while (i > 0) { |
|
sem_wait(s->id.sid); |
|
i--; |
|
} |
|
} |
|
|
|
/* |
|
* map_isSemaphoreOK() - MMAP Check semaphore |
|
* |
|
* @s = Session item |
|
* return: -1 error: can`t return semaphore, 0 = false, 1 = true |
|
*/ |
|
int |
|
map_isSemaphoreOK(ait_sess_t * __restrict s) |
|
{ |
|
int val = -1; |
|
|
|
if (!s) |
|
return -1; |
|
|
|
sem_getvalue(s->id.sid, &val); |
|
return (val ? 0 : 1); |
|
} |
|
|
|
/* |
|
* map_incSemaphore() - MMAP unblock semaphore, increment semaphore |
|
* |
|
* @s = Session item |
|
* return: 0 Ok, -1 error: can`t increment |
|
*/ |
|
int |
|
map_incSemaphore(ait_sess_t * __restrict s) |
|
{ |
|
if (!s) |
|
return -1; |
|
|
|
return sem_post(s->id.sid); |
|
} |
|
|
|
/* |
|
* map_decSemaphore() - MMAP block semaphore, decrement semaphore |
|
* |
|
* @s = Session item |
|
* return: 0 Ok, -1 error: can`t decrement |
|
*/ |
|
int |
|
map_decSemaphore(ait_sess_t * __restrict s) |
|
{ |
|
if (!s) |
|
return -1; |
|
|
|
return sem_wait(s->id.sid); |
|
} |
|
|
|
/* |
|
* ipc_notSemaphore() - IPC negative block if semaphore isn`t signaled |
|
* |
|
* @s = Session item |
|
* return: none |
|
*/ |
|
void |
|
ipc_notSemaphore(ait_sess_t * __restrict s) |
|
{ |
|
struct sembuf sb = { 0, 0, 0 }; |
|
|
|
if (s) |
|
semop(s->id.semid, &sb, 1); |
|
} |
|
|
|
/* |
|
* ipc_isSemaphoreOK() - IPC Check semaphore |
|
* |
|
* @s = Session item |
|
* return: -1 error: can`t return semaphore, 0 = false, 1 = true |
|
*/ |
|
int |
|
ipc_isSemaphoreOK(ait_sess_t * __restrict s) |
|
{ |
|
struct sembuf sb = { 0, 0, IPC_NOWAIT }; |
|
|
|
if (!s) |
|
return -1; |
|
|
|
return semop(s->id.semid, &sb, 1) + 1; |
|
} |
|
|
|
/* |
|
* ipc_incSemaphore() - IPC unblock semaphore, increment semaphore |
|
* |
|
* @s = Session item |
|
* return: 0 Ok, -1 error: can`t increment |
|
*/ |
|
int |
|
ipc_incSemaphore(ait_sess_t * __restrict s) |
|
{ |
|
struct sembuf sb = { 0, 1, 0 }; |
|
|
|
if (!s) |
|
return -1; |
|
|
|
return semop(s->id.semid, &sb, 1); |
|
} |
|
|
|
/* |
|
* ipc_decSemaphore() - IPC block semaphore, decrement semaphore |
|
* |
|
* @s = Session item |
|
* return: 0 Ok, -1 error: can`t decrement |
|
*/ |
|
int |
|
ipc_decSemaphore(ait_sess_t * __restrict s) |
|
{ |
|
struct sembuf sb = { 0, -1, 0 }; |
|
|
|
if (!s) |
|
return -1; |
|
|
|
return semop(s->id.semid, &sb, 1); |
|
} |
|
|
|
/* --- A/V management --- */ |
|
|
|
/* |
* 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 |
Line 55 SUCH DAMAGE.
|
Line 661 SUCH DAMAGE.
|
inline void |
inline void |
sess_FreeValues(char *** __restrict ppsVals) |
sess_FreeValues(char *** __restrict ppsVals) |
{ |
{ |
char **ptr; | str_FreeNullTerm(ppsVals); |
| |
assert(ppsVals); | |
if (!ppsVals) | |
return; | |
| |
for (ptr = *ppsVals; *ptr; ptr++) | |
e_free(*ptr); | |
e_free(*ppsVals); | |
*ppsVals = NULL; | |
} |
} |
|
|
/* |
/* |
Line 100 sess_GetValues(ait_sess_t * __restrict s, char ***ppsV
|
Line 697 sess_GetValues(ait_sess_t * __restrict s, char ***ppsV
|
} else |
} else |
memcpy(Shared, s->addr, s->eom); |
memcpy(Shared, s->addr, s->eom); |
|
|
for (i = 0, peer = strtok_r(Shared, MEM_DELIM"\r\n", &p_brk); peer; | for (i = 0, peer = strtok_r(Shared, SESS_MEM_DELIM"\r\n", &p_brk); peer; |
peer = strtok_r(NULL, MEM_DELIM"\r\n", &p_brk)) { | peer = strtok_r(NULL, SESS_MEM_DELIM"\r\n", &p_brk)) { |
if (!strchr(peer, '=')) |
if (!strchr(peer, '=')) |
continue; |
continue; |
else |
else |
Line 159 sess_GetValue(ait_sess_t * __restrict s, const char *c
|
Line 756 sess_GetValue(ait_sess_t * __restrict s, const char *c
|
} else |
} else |
memcpy(Shared, s->addr, s->eom); |
memcpy(Shared, s->addr, s->eom); |
|
|
for (i = 1, peer = strtok_r(Shared, MEM_DELIM"\r\n", &p_brk); peer; | for (i = 1, peer = strtok_r(Shared, SESS_MEM_DELIM"\r\n", &p_brk); peer; |
i++, peer = strtok_r(NULL, MEM_DELIM"\r\n", &p_brk)) { | i++, peer = strtok_r(NULL, SESS_MEM_DELIM"\r\n", &p_brk)) { |
attr = strtok_r(peer, "=\r\n", &a_brk); |
attr = strtok_r(peer, "=\r\n", &a_brk); |
if (attr && !strncmp(attr, csAttr, MAX_ATTRIBUTE - 1)) { |
if (attr && !strncmp(attr, csAttr, MAX_ATTRIBUTE - 1)) { |
val = strtok_r(NULL, "=\r\n", &a_brk); |
val = strtok_r(NULL, "=\r\n", &a_brk); |
Line 220 sess_DelValue(ait_sess_t * __restrict s, const char *c
|
Line 817 sess_DelValue(ait_sess_t * __restrict s, const char *c
|
memcpy(Shared, s->addr, s->eom); |
memcpy(Shared, s->addr, s->eom); |
} |
} |
|
|
for (i = 1, peer = strtok_r(Shared, MEM_DELIM"\r\n", &p_brk); peer; | for (i = 1, peer = strtok_r(Shared, SESS_MEM_DELIM"\r\n", &p_brk); peer; |
i++, peer = strtok_r(NULL, MEM_DELIM"\r\n", &p_brk)) { | i++, peer = strtok_r(NULL, SESS_MEM_DELIM"\r\n", &p_brk)) { |
if (!strncmp(peer, csAttr, attrlen)) |
if (!strncmp(peer, csAttr, attrlen)) |
if (peer[attrlen] == '=' || peer[attrlen] == *MEM_DELIM || !peer[attrlen] || | if (peer[attrlen] == '=' || peer[attrlen] == *SESS_MEM_DELIM || !peer[attrlen] || |
peer[attrlen] == '\r' || peer[attrlen] == '\n') |
peer[attrlen] == '\r' || peer[attrlen] == '\n') |
continue; |
continue; |
|
|
strlcat(Buffer, peer, s->eom); |
strlcat(Buffer, peer, s->eom); |
strlcat(Buffer, MEM_DELIM, s->eom); | strlcat(Buffer, SESS_MEM_DELIM, s->eom); |
} |
} |
|
|
memcpy(s->addr, Buffer, s->eom); |
memcpy(s->addr, Buffer, s->eom); |
Line 282 sess_SetValue(ait_sess_t * __restrict s, const char *c
|
Line 879 sess_SetValue(ait_sess_t * __restrict s, const char *c
|
memcpy(Shared, s->addr, s->eom); |
memcpy(Shared, s->addr, s->eom); |
} |
} |
|
|
for (i = 1, upd = 0, peer = strtok_r(Shared, MEM_DELIM"\r\n", &p_brk); peer; | for (i = 1, upd = 0, peer = strtok_r(Shared, SESS_MEM_DELIM"\r\n", &p_brk); peer; |
i++, peer = strtok_r(NULL, MEM_DELIM"\r\n", &p_brk)) { | i++, peer = strtok_r(NULL, SESS_MEM_DELIM"\r\n", &p_brk)) { |
if (!strncmp(peer, szAttr, strlen(szAttr))) { |
if (!strncmp(peer, szAttr, strlen(szAttr))) { |
upd++; |
upd++; |
if (psVal) { |
if (psVal) { |
strlcat(Buffer, szAttr, s->eom); |
strlcat(Buffer, szAttr, s->eom); |
strlcat(Buffer, psVal, s->eom); |
strlcat(Buffer, psVal, s->eom); |
strlcat(Buffer, MEM_DELIM, s->eom); | strlcat(Buffer, SESS_MEM_DELIM, s->eom); |
} else { |
} else { |
strlcat(Buffer, csAttr, s->eom); |
strlcat(Buffer, csAttr, s->eom); |
strlcat(Buffer, MEM_DELIM, s->eom); | strlcat(Buffer, SESS_MEM_DELIM, s->eom); |
def = IS_DEF; |
def = IS_DEF; |
} |
} |
continue; |
continue; |
} |
} |
|
|
strlcat(Buffer, peer, s->eom); |
strlcat(Buffer, peer, s->eom); |
strlcat(Buffer, MEM_DELIM, s->eom); | strlcat(Buffer, SESS_MEM_DELIM, s->eom); |
} |
} |
|
|
if (!upd) { |
if (!upd) { |
if (psVal) { |
if (psVal) { |
strlcat(Buffer, szAttr, s->eom); |
strlcat(Buffer, szAttr, s->eom); |
strlcat(Buffer, psVal, s->eom); |
strlcat(Buffer, psVal, s->eom); |
strlcat(Buffer, MEM_DELIM, s->eom); | strlcat(Buffer, SESS_MEM_DELIM, s->eom); |
} else { |
} else { |
strlcat(Buffer, csAttr, s->eom); |
strlcat(Buffer, csAttr, s->eom); |
strlcat(Buffer, MEM_DELIM, s->eom); | strlcat(Buffer, SESS_MEM_DELIM, s->eom); |
def = IS_DEF; |
def = IS_DEF; |
} |
} |
def |= IS_ADD; |
def |= IS_ADD; |