Changeset 8848
- Timestamp:
- 05/30/11 13:39:49 (2 years ago)
- Files:
-
- 1 modified
-
branches/Orange-Branch/src/io/bmi/bmi_mx/mx.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Orange-Branch/src/io/bmi/bmi_mx/mx.c
r8831 r8848 536 536 bmx_parse_peername(const char *peername, char **hostname, uint32_t *board, uint32_t *ep_id) 537 537 { 538 int ret = 0; 539 int colon1_found = 0; 540 int colon2_found = 0; 541 char *s = NULL; 542 char *colon1 = NULL; 543 char *colon2 = NULL; 544 char *fs = NULL; 545 char *host = NULL; 546 uint32_t bd = -1; 547 uint32_t ep = 0; 548 549 if (peername == NULL || hostname == NULL || board == NULL || ep_id == NULL) { 538 int ret = 0; 539 int colon1_found = 0; 540 int colon2_found = 0; 541 char *tmp_peername = NULL; 542 char *colon1 = NULL; 543 char *colon2 = NULL; 544 char *fs = NULL; 545 char *host = NULL; 546 uint32_t bd = -1; 547 uint32_t ep = 0; 548 549 tmp_peername = string_key("mx",peername); 550 if (!tmp_peername) { 551 debug(BMX_DB_INFO, "parse_peername() called with invalid peername"); 552 return -BMI_EINVAL; 553 } 554 555 if (tmp_peername == NULL || hostname == NULL || board == NULL || ep_id == NULL) { 550 556 debug(BMX_DB_INFO, "parse_peername() called with invalid parameter"); 551 557 return -BMI_EINVAL; 552 558 } 553 554 if (peername[0] != 'm' || 555 peername[1] != 'x' || 556 peername[2] != ':' || 557 peername[3] != '/' || 558 peername[4] != '/') { 559 debug(BMX_DB_INFO, "parse_peername() peername does not start with mx://"); 560 return -1; 561 } 562 563 s = strdup(&peername[5]); 564 fs = strchr(s, '/'); 559 fs = strchr(tmp_peername, '/'); 565 560 if (fs) { 566 561 *fs = '\0'; 567 562 } 568 colon1 = strchr( s, ':');563 colon1 = strchr(tmp_peername, ':'); 569 564 if (!colon1) { 570 565 debug(BMX_DB_INFO, "parse_peername() strchr() failed"); 571 566 } else { 572 colon2 = strrchr( s, ':');567 colon2 = strrchr(tmp_peername, ':'); 573 568 if (colon1 == colon2) { 574 569 /* colon2_found == 0 */ … … 604 599 debug(BMX_DB_INFO, "parse_peername() too many ':' (%s %s)", 605 600 colon1, colon2); 606 free( s);601 free(tmp_peername); 607 602 return -1; 608 603 } 609 604 } 610 605 611 host = strdup( s);606 host = strdup(tmp_peername); 612 607 if (!host) { 613 608 debug(BMX_DB_MEM, "parse_peername() malloc() failed"); 614 free( s);609 free(tmp_peername); 615 610 return -1; 616 611 } … … 624 619 debug(BMX_DB_WARN, "%s is not a valid hostname", host); 625 620 free(host); 626 free( s);621 free(tmp_peername); 627 622 return -1; 628 623 } … … 632 627 debug(BMX_DB_INFO, "%s is not a valid hostname", host); 633 628 free(host); 634 free( s);629 free(tmp_peername); 635 630 return -1; 636 631 } … … 639 634 debug(BMX_DB_INFO, "%s is not a valid board ID", host); 640 635 free(host); 641 free( s);636 free(tmp_peername); 642 637 return -1; 643 638 } … … 646 641 debug(BMX_DB_INFO, "%s is not a valid endpoint ID", host); 647 642 free(host); 648 free( s);643 free(tmp_peername); 649 644 return -1; 650 645 } … … 654 649 *ep_id = ep; 655 650 656 free( s);651 free(tmp_peername); 657 652 658 653 return 0;
