Mercurial > pidgin
comparison src/protocols/simple/simple.c @ 11439:617e67e1c985
[gaim-migrate @ 13676]
Fixed a couple leaks and potential leaks. The retval of g_strsplit() needs to be g_strfreev()'d. Also some "declaration after code" fixes.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sun, 04 Sep 2005 18:05:48 +0000 |
parents | e1ab173ef3b5 |
children | 0d18fa6c3b41 |
comparison
equal
deleted
inserted
replaced
11438:5451fe2d89c0 | 11439:617e67e1c985 |
---|---|
295 | 295 |
296 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { | 296 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { |
297 int i=0; | 297 int i=0; |
298 char *tmp; | 298 char *tmp; |
299 char *tmp2; | 299 char *tmp2; |
300 gchar **parts; | |
300 if(!hdr) { | 301 if(!hdr) { |
301 gaim_debug_error("simple", "fill_auth: hdr==NULL\n"); | 302 gaim_debug_error("simple", "fill_auth: hdr==NULL\n"); |
302 return; | 303 return; |
303 } | 304 } |
304 | 305 |
305 if(!g_strncasecmp(hdr, "NTLM", 4)) { | 306 if(!g_strncasecmp(hdr, "NTLM", 4)) { |
306 gaim_debug_info("simple", "found NTLM\n"); | 307 gaim_debug_info("simple", "found NTLM\n"); |
307 auth->type = 2; | 308 auth->type = 2; |
308 if(!auth->nonce && !auth->nc) { | 309 if(!auth->nonce && !auth->nc) { |
309 gchar **parts = g_strsplit(hdr, " ", 0); | 310 parts = g_strsplit(hdr, " ", 0); |
310 while(parts[i]) { | 311 while(parts[i]) { |
311 if(!strncmp(parts[i],"targetname",10)) { | 312 if(!strncmp(parts[i],"targetname",10)) { |
312 auth->target = g_strndup(parts[i]+12,strlen(parts[i]+12)-1); | 313 auth->target = g_strndup(parts[i]+12,strlen(parts[i]+12)-1); |
313 } | 314 } |
314 if(!strncmp(parts[i],"realm",5)) { | 315 if(!strncmp(parts[i],"realm",5)) { |
319 auth->realm = g_strdup(tmp); | 320 auth->realm = g_strdup(tmp); |
320 *tmp2 = '"'; | 321 *tmp2 = '"'; |
321 } | 322 } |
322 i++; | 323 i++; |
323 } | 324 } |
325 g_strfreev(parts); | |
326 parts = NULL; | |
324 auth->nc = 1; | 327 auth->nc = 1; |
325 } | 328 } |
326 if(!auth->nonce && auth->nc==2) { | 329 if(!auth->nonce && auth->nc==2) { |
327 auth->nc = 3; | 330 auth->nc = 3; |
328 auth->nonce = gaim_ntlm_parse_type2(hdr+5); | 331 auth->nonce = gaim_ntlm_parse_type2(hdr+5); |
329 } | 332 } |
330 return; | 333 return; |
331 } | 334 } |
332 | 335 |
333 auth->type = 1; | 336 auth->type = 1; |
334 gchar **parts = g_strsplit(hdr, " ", 0); | 337 parts = g_strsplit(hdr, " ", 0); |
335 while(parts[i]) { | 338 while(parts[i]) { |
336 if(!strncmp(parts[i],"nonce",5)) { | 339 if(!strncmp(parts[i],"nonce",5)) { |
337 auth->nonce = g_strndup(parts[i]+7,strlen(parts[i]+7)-1); | 340 auth->nonce = g_strndup(parts[i]+7,strlen(parts[i]+7)-1); |
338 } | 341 } |
339 if(!strncmp(parts[i],"realm",5)) { | 342 if(!strncmp(parts[i],"realm",5)) { |
340 auth->realm = g_strndup(parts[i]+7,strlen(parts[i]+7)-2); | 343 auth->realm = g_strndup(parts[i]+7,strlen(parts[i]+7)-2); |
341 } | 344 } |
342 i++; | 345 i++; |
343 } | 346 } |
347 g_strfreev(parts); | |
344 | 348 |
345 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce, auth->realm); | 349 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce, auth->realm); |
346 | 350 |
347 DigestCalcHA1("md5", sip->username, auth->realm, sip->password, auth->nonce, "", auth->HA1); | 351 DigestCalcHA1("md5", sip->username, auth->realm, sip->password, auth->nonce, "", auth->HA1); |
348 | 352 |
552 | 556 |
553 g_free(buf); | 557 g_free(buf); |
554 } | 558 } |
555 | 559 |
556 static void do_register_exp(struct simple_account_data *sip, int expire) { | 560 static void do_register_exp(struct simple_account_data *sip, int expire) { |
557 sip->registerstatus = 1; | |
558 | |
559 char *uri = g_strdup_printf("sip:%s",sip->servername); | 561 char *uri = g_strdup_printf("sip:%s",sip->servername); |
560 char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername); | 562 char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername); |
561 char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, sip->ip ? sip->ip : "", sip->listenport, sip->udp ? "udp" : "tcp", expire); | 563 char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, sip->ip ? sip->ip : "", sip->listenport, sip->udp ? "udp" : "tcp", expire); |
564 | |
565 sip->registerstatus = 1; | |
562 | 566 |
563 if(expire) { | 567 if(expire) { |
564 sip->reregister = time(NULL) + expire - 50; | 568 sip->reregister = time(NULL) + expire - 50; |
565 } else { | 569 } else { |
566 sip->reregister = time(NULL) + 600; | 570 sip->reregister = time(NULL) + 600; |
986 } | 990 } |
987 } else { /* response */ | 991 } else { /* response */ |
988 struct transaction *trans = transactions_find(sip, msg); | 992 struct transaction *trans = transactions_find(sip, msg); |
989 if(trans) { | 993 if(trans) { |
990 if(msg->response == 407) { | 994 if(msg->response == 407) { |
995 gchar *resend, *auth, *ptmp; | |
996 | |
991 if(sip->proxy.retries>3) return; | 997 if(sip->proxy.retries>3) return; |
992 sip->proxy.retries++; | 998 sip->proxy.retries++; |
993 /* do proxy authentication */ | 999 /* do proxy authentication */ |
994 | 1000 |
995 gchar *ptmp = sipmsg_find_header(msg,"Proxy-Authenticate"); | 1001 ptmp = sipmsg_find_header(msg, "Proxy-Authenticate"); |
996 gchar *resend; | |
997 gchar *auth; | |
998 | 1002 |
999 fill_auth(sip, ptmp, &sip->proxy); | 1003 fill_auth(sip, ptmp, &sip->proxy); |
1000 auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target); | 1004 auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target); |
1001 sipmsg_remove_header(msg, "Proxy-Authorization"); | 1005 sipmsg_remove_header(msg, "Proxy-Authorization"); |
1002 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth); | 1006 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth); |