Changeset 8848

Show
Ignore:
Timestamp:
05/30/11 13:39:49 (2 years ago)
Author:
bligon
Message:

Problem: mx address lookup failed when multiple protocols were used at the same time.
Added key_string() function to parse_peername(), which correctly strips the BMI mx address
from a string containing multiple protocols.
Modified File:

Tag: Orange-Branch

src/io/bmi/bmi_mx/mx.c

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/Orange-Branch/src/io/bmi/bmi_mx/mx.c

    r8831 r8848  
    536536bmx_parse_peername(const char *peername, char **hostname, uint32_t *board, uint32_t *ep_id) 
    537537{ 
    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) { 
    550556                debug(BMX_DB_INFO, "parse_peername() called with invalid parameter"); 
    551557                return -BMI_EINVAL; 
    552558        } 
    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, '/'); 
    565560        if (fs) { 
    566561                *fs = '\0'; 
    567562        } 
    568         colon1 = strchr(s, ':'); 
     563        colon1 = strchr(tmp_peername, ':'); 
    569564        if (!colon1) { 
    570565                debug(BMX_DB_INFO, "parse_peername() strchr() failed"); 
    571566        } else { 
    572                 colon2 = strrchr(s, ':'); 
     567                colon2 = strrchr(tmp_peername, ':'); 
    573568                if (colon1 == colon2) { 
    574569                        /* colon2_found == 0 */ 
     
    604599                        debug(BMX_DB_INFO, "parse_peername() too many ':' (%s %s)",  
    605600                                           colon1, colon2); 
    606                         free(s); 
     601                        free(tmp_peername); 
    607602                        return -1; 
    608603                } 
    609604        } 
    610605 
    611         host = strdup(s); 
     606        host = strdup(tmp_peername); 
    612607        if (!host) { 
    613608                debug(BMX_DB_MEM, "parse_peername() malloc() failed"); 
    614                 free(s); 
     609                free(tmp_peername); 
    615610                return -1; 
    616611        } 
     
    624619                debug(BMX_DB_WARN, "%s is not a valid hostname", host); 
    625620                free(host); 
    626                 free(s); 
     621                free(tmp_peername); 
    627622                return -1; 
    628623        } 
     
    632627                debug(BMX_DB_INFO, "%s is not a valid hostname", host); 
    633628                free(host); 
    634                 free(s); 
     629                free(tmp_peername); 
    635630                return -1; 
    636631        } 
     
    639634                debug(BMX_DB_INFO, "%s is not a valid board ID", host); 
    640635                free(host); 
    641                 free(s); 
     636                free(tmp_peername); 
    642637                return -1; 
    643638        } 
     
    646641                debug(BMX_DB_INFO, "%s is not a valid endpoint ID", host); 
    647642                free(host); 
    648                 free(s); 
     643                free(tmp_peername); 
    649644                return -1; 
    650645        } 
     
    654649        *ep_id = ep; 
    655650 
    656         free(s); 
     651        free(tmp_peername); 
    657652 
    658653        return 0;