Annotation of libaitsess/contrib/test2.c, revision 1.3.4.1
1.2 misho 1: #include <stdio.h>
2: #include <string.h>
3: #include <aitsess.h>
1.3.4.1 ! misho 4: #include <elwix.h>
1.2 misho 5:
6:
7: int main(int argc, char **argv)
8: {
9: ait_sess_t *n = NULL;
10: array_t *inp;
11: ait_val_t *v;
12: int i;
13:
1.3.4.1 ! misho 14: inp = array_Init(argc);
1.2 misho 15: for (i = 0; i < argc; i++) {
1.3.4.1 ! misho 16: v = ait_allocVar();
1.2 misho 17: AIT_SET_STR(v, argv[i]);
1.3.4.1 ! misho 18: array_Set(inp, i, v);
1.2 misho 19: }
20:
21: /*
22: map_createSession("/tmp/abra-kadabra-123", 1003, 4096, &n);
23: if (sess_GetErrno()) {
24: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
25: return 2;
26: }
27: dat = map_attachSession(n, NULL);
28: if (!dat)
29: return 1;
30: printf("brym n=%d dat=%p dat=%s\n", n, dat, dat);
31: strcpy(dat, "nAuth=1:nStatus=0:szChanne=SIP/0765-4802:szSID=437d9371-3977e2de-099999:szUser=099999:szPass=123123:szCaller=123123123:szRadGro=ppcards:szPhone=0768:ExtCode=07:szDispl=Bulgaria:nMasterG=1:nPrice=82:nGPrice=82:nMPrice=82:nBillInc=2:nGBillIn=2:nMBillIn=2:nMCache=807901468:nCache=999338:nAccount=29297:nPricePa=1:nGPriceP=1:nMPriceP=1:WarnTime=0:GratisTi=0:ActTime=1132220092:");
32: sess_SetValue(n, "nAuth", NULL);
33: printf("begin>>> String=%s\n", dat);
34: printf("find=%d\n", sess_GetValue(n, "000", NULL, NULL));
35: if (sess_GetErrno()) {
36: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
37: return 2;
38: }
39: sess_DelValue(n, "000");
40: printf("CLOSE %p>>> String=%s\n", n->addr, n->addr);
41: strcat(dat, "Blaaaaaaaaaaaaaaaaaa da mu eb* mamataaaaa .....\n");
42: map_detachSession(n);
43: getchar();
44: freeSession(NULL, &n);
45: */
46:
47: sess_initSession(SHARED_IPC, "/tmp/abra-kadabra-321", &n);
48: if (ALLOC_MEMORY(1003, 4096, n) == -1) {
49: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
50: return 2;
51: }
52: if (sess_commitSession(n, inp) == -1) {
53: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
54: FREE_MEMORY(n);
55: sess_freeSession(&n);
56: return 2;
57: }
58: sess_freeSession(&n);
1.3.4.1 ! misho 59: for (i = 0; i < array_Size(inp); i++)
! 60: AIT_FREE_VAL(array_Get(inp, i));
! 61: array_Free(inp);
! 62: array_Destroy(&inp);
1.2 misho 63: printf("set session");
64: getchar();
65: sess_initSession(SHARED_IPC, "/tmp/abra-kadabra-321", &n);
66: ALLOC_MEMORY(1003, 4096, n);
67: if (sess_GetErrno()) {
68: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
69: return 3;
70: }
71: if (!(inp = sess_prepareSession(n, 42))) {
72: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
73: FREE_MEMORY(n);
74: sess_freeSession(&n);
75: return 3;
76: }
1.3.4.1 ! misho 77: for (i = 0; i < array_Size(inp); i++)
! 78: printf("i=%d->%s\n", i, AIT_GET_STR(array(inp, i, ait_val_t*)));
1.2 misho 79: sess_doneSession(n, &inp);
80: sess_freeSession(&n);
81: getchar();
82: sess_initSession(SHARED_IPC, "/tmp/abra-kadabra-321", &n);
83: ALLOC_MEMORY(1003, 4096, n);
84: if (sess_GetErrno()) {
85: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
86: return 4;
87: }
88: if (!(inp = sess_prepareSession(n, 0))) {
89: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
90: FREE_MEMORY(n);
91: sess_freeSession(&n);
92: return 4;
93: }
1.3.4.1 ! misho 94: AIT_FREE_VAL(array(inp, 2, ait_val_t*));
! 95: AIT_SET_STR(array(inp, 2, ait_val_t*), "djmy");
! 96: for (i = 0; i < array_Size(inp); i++)
! 97: printf("i=%d->%s\n", i, AIT_GET_STR(array(inp, i, ait_val_t*)));
1.2 misho 98: sess_commitSession(n, inp);
1.3.4.1 ! misho 99: for (i = 0; i < array_Size(inp); i++)
! 100: AIT_FREE_VAL(array_Get(inp, i));
1.2 misho 101: sess_doneSession(n, &inp);
102: sess_freeSession(&n);
103: getchar();
104: sess_initSession(SHARED_IPC, "/tmp/abra-kadabra-321", &n);
105: ALLOC_MEMORY(1003, 4096, n);
106: if (sess_GetErrno()) {
107: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
108: return 3;
109: }
110: if (!(inp = sess_prepareSession(n, 42))) {
111: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
112: FREE_MEMORY(n);
113: sess_freeSession(&n);
114: return 3;
115: }
1.3.4.1 ! misho 116: for (i = 0; i < array_Size(inp); i++)
! 117: printf("i=%d->%s\n", i, AIT_GET_STR(array(inp, i, ait_val_t*)));
1.2 misho 118: /*
1.3.4.1 ! misho 119: for (i = 0; i < array_Size(inp); i++)
! 120: AIT_FREE_VAL(array_Get(inp, i));
1.2 misho 121: */
122: sess_doneSession(n, &inp);
123: FREE_MEMORY(n);
124: sess_freeSession(&n);
125:
126: return 0;
127: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>