comparison libpurple/protocols/jabber/google.c @ 26757:43e1cdbc6b4b

Avoid crashing on some more atoi calls and ensure required parameters are !NULL The rewrite in google_session_handle_candidates is for readability
author Paul Aurich <paul@darkrain42.org>
date Thu, 30 Apr 2009 04:01:27 +0000
parents 5d1140b0b10a
children bb537c36d92f
comparison
equal deleted inserted replaced
26756:cfde0f7fd54f 26757:43e1cdbc6b4b
419 codec_element = xmlnode_get_next_twin(codec_element)) { 419 codec_element = xmlnode_get_next_twin(codec_element)) {
420 encoding_name = xmlnode_get_attrib(codec_element, "name"); 420 encoding_name = xmlnode_get_attrib(codec_element, "name");
421 id = xmlnode_get_attrib(codec_element, "id"); 421 id = xmlnode_get_attrib(codec_element, "id");
422 clock_rate = xmlnode_get_attrib(codec_element, "clockrate"); 422 clock_rate = xmlnode_get_attrib(codec_element, "clockrate");
423 423
424 codec = purple_media_codec_new(atoi(id), encoding_name, PURPLE_MEDIA_AUDIO, 424 if (id) {
425 clock_rate ? atoi(clock_rate) : 0); 425 codec = purple_media_codec_new(atoi(id), encoding_name, PURPLE_MEDIA_AUDIO,
426 codecs = g_list_append(codecs, codec); 426 clock_rate ? atoi(clock_rate) : 0);
427 codecs = g_list_append(codecs, codec);
428 }
427 } 429 }
428 430
429 purple_media_set_remote_codecs(session->media, "google-voice", session->remote_jid, codecs); 431 purple_media_set_remote_codecs(session->media, "google-voice", session->remote_jid, codecs);
430 432
431 g_signal_connect_swapped(G_OBJECT(session->media), "accepted", 433 g_signal_connect_swapped(G_OBJECT(session->media), "accepted",
457 static int name = 0; 459 static int name = 0;
458 char n[4]; 460 char n[4];
459 461
460 for (cand = xmlnode_get_child(sess, "candidate"); cand; cand = xmlnode_get_next_twin(cand)) { 462 for (cand = xmlnode_get_child(sess, "candidate"); cand; cand = xmlnode_get_next_twin(cand)) {
461 PurpleMediaCandidate *info; 463 PurpleMediaCandidate *info;
462 g_snprintf(n, sizeof(n), "S%d", name++); 464 const gchar *type = xmlnode_get_attrib(cand, "type");
463 info = purple_media_candidate_new(n, PURPLE_MEDIA_COMPONENT_RTP, 465 const gchar *protocol = xmlnode_get_attrib(cand, "protocol");
464 !strcmp(xmlnode_get_attrib(cand, "type"), "local") ? 466 const gchar *address = xmlnode_get_attrib(cand, "address");
465 PURPLE_MEDIA_CANDIDATE_TYPE_HOST : 467 const gchar *port = xmlnode_get_attrib(cand, "port");
466 !strcmp(xmlnode_get_attrib(cand, "type"), "stun") ? 468
467 PURPLE_MEDIA_CANDIDATE_TYPE_PRFLX : 469 if (type && address && port) {
468 !strcmp(xmlnode_get_attrib(cand, "type"), "relay") ? 470 PurpleMediaCandidateType candidate_type;
469 PURPLE_MEDIA_CANDIDATE_TYPE_RELAY : 471
470 PURPLE_MEDIA_CANDIDATE_TYPE_HOST, 472 g_snprintf(n, sizeof(n), "S%d", name++);
471 !strcmp(xmlnode_get_attrib(cand, "protocol"),"udp") ? 473
474 if (g_str_equal(type, "local"))
475 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_HOST;
476 else if (g_str_equal(type, "stun"))
477 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_PRFLX;
478 else if (g_str_equal(type, "relay"))
479 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_RELAY;
480 else
481 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_HOST;
482
483 info = purple_media_candidate_new(n, PURPLE_MEDIA_COMPONENT_RTP,
484 candidate_type,
485 purple_strequal(protocol, "udp") ?
472 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP : 486 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP :
473 PURPLE_MEDIA_NETWORK_PROTOCOL_TCP, 487 PURPLE_MEDIA_NETWORK_PROTOCOL_TCP,
474 xmlnode_get_attrib(cand, "address"), 488 address,
475 atoi(xmlnode_get_attrib(cand, "port"))); 489 atoi(port));
476 g_object_set(info, "username", xmlnode_get_attrib(cand, "username"), 490 g_object_set(info, "username", xmlnode_get_attrib(cand, "username"),
477 "password", xmlnode_get_attrib(cand, "password"), NULL); 491 "password", xmlnode_get_attrib(cand, "password"), NULL);
478 492 list = g_list_append(list, info);
479 list = g_list_append(list, info); 493 }
480 } 494 }
481 495
482 purple_media_add_remote_candidates(session->media, "google-voice", session->remote_jid, list); 496 purple_media_add_remote_candidates(session->media, "google-voice", session->remote_jid, list);
483 purple_media_candidate_list_free(list); 497 purple_media_candidate_list_free(list);
484 498
502 xmlnode_get_attrib(codec_element, "name"); 516 xmlnode_get_attrib(codec_element, "name");
503 const gchar *id = xmlnode_get_attrib(codec_element, "id"); 517 const gchar *id = xmlnode_get_attrib(codec_element, "id");
504 const gchar *clock_rate = 518 const gchar *clock_rate =
505 xmlnode_get_attrib(codec_element, "clockrate"); 519 xmlnode_get_attrib(codec_element, "clockrate");
506 520
507 PurpleMediaCodec *codec = purple_media_codec_new(atoi(id), 521 if (id && encoding_name) {
508 encoding_name, PURPLE_MEDIA_AUDIO, 522 PurpleMediaCodec *codec = purple_media_codec_new(atoi(id),
509 clock_rate ? atoi(clock_rate) : 0); 523 encoding_name, PURPLE_MEDIA_AUDIO,
510 codecs = g_list_append(codecs, codec); 524 clock_rate ? atoi(clock_rate) : 0);
525 codecs = g_list_append(codecs, codec);
526 }
511 } 527 }
512 528
513 purple_media_set_remote_codecs(session->media, "google-voice", 529 purple_media_set_remote_codecs(session->media, "google-voice",
514 session->remote_jid, codecs); 530 session->remote_jid, codecs);
515 531