MCPcopy Create free account
hub / github.com/3proxy/3proxy / searchcookie

Function searchcookie

src/icqpr.c:118–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117
118static int searchcookie(struct clientparam *param, struct flap_header * flap, int len, int * dif, struct tlv_header *tlv, int extra){
119 struct icq_cookie *ic;
120 char smallbuf[64];
121 struct tlv_header *bostlv = NULL;
122 struct sockaddr_in sa;
123 SASIZETYPE size = sizeof(sa);
124 int movelen = 0;
125
126 if(!icq_cookie_mutex_init){
127 pthread_mutex_init(&icq_cookie_mutex, NULL);
128 icq_cookie_mutex_init = 1;
129 }
130 pthread_mutex_lock(&icq_cookie_mutex);
131 for(ic = icq_cookies; ic; ic = ic->next)if(!strcmp((char *)param->username, ic->id))break;
132 if(!ic){
133 ic = myalloc(sizeof(struct icq_cookie));
134 memset(ic, 0, sizeof(struct icq_cookie));
135 ic->id = mystrdup((char *)param->username);
136 ic->next = icq_cookies;
137 icq_cookies = ic;
138 }
139 for(; ntohs(tlv->size) < 65500 && len >= (ntohs(tlv->size) + 4); len -= (ntohs(tlv->size) + 4), tlv = (struct tlv_header *)(tlv->data + ntohs(tlv->size))){
140 if(ntohs(tlv->type) == 0x0006){
141 if(ic->cookie)myfree(ic->cookie);
142 ic->cookie = myalloc(ntohs(tlv->size));
143 memcpy(ic->cookie, tlv->data, ntohs(tlv->size));
144 ic->size = tlv->size;
145 }
146 else if(ntohs(tlv->type) == 0x0005){
147 if(ic->connectstring)myfree(ic->connectstring);
148 ic->connectstring = myalloc(ntohs(tlv->size)+1);
149 memcpy(ic->connectstring, tlv->data, ntohs(tlv->size));
150 ic->connectstring[ntohs(tlv->size)] = 0;
151 bostlv = tlv;
152 movelen = extra + (len - 4) - ntohs(bostlv->size);
153 }
154
155 }
156 if(!ic->connectstring || !ic->cookie){
157 if(ic->cookie)myfree(ic->cookie);
158 if(ic->connectstring)myfree(ic->connectstring);
159 ic->cookie = NULL;
160 ic->connectstring = NULL;
161 ic->size = 0;
162 bostlv = NULL;
163 }
164 pthread_mutex_unlock(&icq_cookie_mutex);
165 if(bostlv){
166 if(so._getsockname(param->clisock, (struct sockaddr *)&sa, &size)==-1) return 1;
167 len = myinet_ntop(*SAFAMILY(&sa),SAADDR(&sa), smallbuf, 64);
168 if(strchr(ic->connectstring, ':'))sprintf(smallbuf+len, ":%hu", ntohs(sa.sin_port));
169 len = (int)strlen(smallbuf);
170 *dif = len - (int)ntohs(bostlv->size);
171 if(*dif != 0 && movelen > 0){
172 memmove(bostlv->data + len, bostlv->data + ntohs(bostlv->size), movelen);
173 }
174 memcpy(bostlv->data, smallbuf, len);
175 bostlv->size = htons(len);

Callers 2

icq_srvFunction · 0.85
icqprchildFunction · 0.85

Calls 3

myallocFunction · 0.85
mystrdupFunction · 0.85
myfreeFunction · 0.85

Tested by

no test coverage detected