]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | |
2 | /* | |
3 | ||
4 | SNAC-related dodads... | |
5 | ||
6 | outstanding_snacs is a list of aim_snac_t structs. A SNAC should be added | |
7 | whenever a new SNAC is sent and it should remain in the list until the | |
8 | response for it has been receieved. | |
9 | ||
10 | */ | |
11 | ||
12 | #include <aim.h> | |
13 | ||
14 | struct aim_snac_t *aim_outstanding_snacs = NULL; | |
15 | u_long aim_snac_nextid = 0x00000001; | |
16 | ||
17 | u_long aim_newsnac(struct aim_snac_t *newsnac) | |
18 | { | |
19 | struct aim_snac_t *local = NULL; | |
20 | ||
21 | local = (struct aim_snac_t *)malloc(sizeof(struct aim_snac_t)); | |
22 | memcpy(local, newsnac, sizeof(struct aim_snac_t)); | |
23 | local->next = NULL; | |
24 | local->issuetime = time(&local->issuetime); | |
25 | ||
26 | if (aim_outstanding_snacs!=NULL) | |
27 | { | |
28 | struct aim_snac_t *cur = aim_outstanding_snacs; | |
29 | ||
30 | if (cur->next == NULL) | |
31 | { | |
32 | cur->next = local; | |
33 | } | |
34 | else | |
35 | { | |
36 | for (;cur->next!=NULL; cur=cur->next) | |
37 | ; | |
38 | cur->next = local; | |
39 | } | |
40 | } | |
41 | else | |
42 | { | |
43 | aim_outstanding_snacs = local; | |
44 | aim_outstanding_snacs->next = NULL; | |
45 | } | |
46 | ||
47 | return local->id; | |
48 | } | |
49 | ||
50 | /* FIXME: there's a bug in here... just don't have more than two outstanding | |
51 | SNACs and you'll be ok */ | |
52 | struct aim_snac_t *aim_remsnac(u_long id) | |
53 | { | |
54 | struct aim_snac_t *cur = aim_outstanding_snacs; | |
55 | ||
56 | if(cur) | |
57 | { | |
58 | if (cur->next) | |
59 | { | |
60 | struct aim_snac_t *ret = NULL; | |
61 | for(;(cur->next!=NULL) && (cur->id != id);cur=cur->next) | |
62 | ; | |
63 | if (cur->id == id) | |
64 | { | |
65 | ret = cur; | |
66 | cur->next = NULL; | |
67 | return ret; | |
68 | } | |
69 | else | |
70 | { | |
71 | return NULL; | |
72 | } | |
73 | } | |
74 | else | |
75 | { | |
76 | aim_outstanding_snacs = NULL; | |
77 | return cur; | |
78 | } | |
79 | } | |
80 | else | |
81 | return NULL; | |
82 | } | |
83 | ||
84 | ||
85 | /* | |
86 | This is for cleaning up old SNACs that either don't get replies or | |
87 | a reply was never received for. Garabage collection. Plain and simple. | |
88 | ||
89 | maxage is the _minimum_ age in seconds to keep SNACs | |
90 | ||
91 | */ | |
92 | int aim_cleansnacs(int maxage) | |
93 | { | |
94 | struct aim_snac_t *cur = aim_outstanding_snacs; | |
95 | time_t curtime; | |
96 | ||
97 | curtime = time(&curtime); | |
98 | ||
99 | while (cur) | |
100 | { | |
101 | #if 1 | |
102 | if ( (cur) && (((cur->issuetime) + maxage) < curtime)) | |
103 | { | |
104 | printf("aimsnac: WARNING purged obsolete snac %ul\n", (unsigned int) cur->id); | |
105 | #if 1 | |
106 | aim_remsnac(cur->id); | |
107 | #endif | |
108 | } | |
109 | #endif | |
110 | cur = cur->next; | |
111 | } | |
112 | ||
113 | return 0; | |
114 | } |