/* pattern-matching text; ie, legaltorrents.com */ void gtr_get_host_from_url (char * buf, size_t buflen, const char * url) { char host[1024]; const char * pch; if ((pch = strstr (url, "://"))) { const size_t hostlen = strcspn (pch+3, ":/"); const size_t copylen = MIN (hostlen, sizeof (host)-1); memcpy (host, pch+3, copylen); host[copylen] = '\0'; } else { *host = '\0'; } if (tr_addressIsIP (host)) { g_strlcpy (buf, url, buflen); } else { const char * first_dot = strchr (host, '.'); const char * last_dot = strrchr (host, '.'); if ((first_dot) && (last_dot) && (first_dot != last_dot)) g_strlcpy (buf, first_dot + 1, buflen); else g_strlcpy (buf, host, buflen); } }
/* human-readable name; ie, Legaltorrents */ static char* get_name_from_host( const char * host ) { char * name; const char * dot = strrchr( host, '.' ); if( tr_addressIsIP( host ) ) name = g_strdup( host ); else if( dot ) name = g_strndup( host, dot - host ); else name = g_strdup( host ); *name = g_ascii_toupper( *name ); return name; }
/* pattern-matching text; ie, legaltorrents.com */ char* gtr_get_host_from_url( const char * url ) { char * h = NULL; char * name; tr_urlParse( url, -1, NULL, &h, NULL, NULL ); if( tr_addressIsIP( h ) ) name = g_strdup( h ); else { const char * first_dot = strchr( h, '.' ); const char * last_dot = strrchr( h, '.' ); if( ( first_dot ) && ( last_dot ) && ( first_dot != last_dot ) ) name = g_strdup( first_dot + 1 ); else name = g_strdup( h ); } tr_free( h ); return name; }