Changeset 1802


Ignore:
Timestamp:
Apr 5, 2015, 8:40:17 PM (6 years ago)
Author:
Gregg Young
Message:

Have newview recognize https:
as a url. Remove trailing punctuation from urls. Fix cases where ismailaddress returns TRUE in error. Fixed IP address literal case and limted domains to 3 characters in email addresses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/newview.c

    r1790 r1802  
    4444                containing an email. Fixed the mailto code to avoid a buffer over run (trap)
    4545                and to cut trailing punctuation marks from the address
     46  04 Apr 15 GKY Have https:// recognized as a url. Strip trailing punctuation from urls.
    4647
    4748***********************************************************************/
     
    200201static FATTRS Fattrs;
    201202
    202 // mailstr checks for a designated character in a string then cuts the string
    203 //to the first word that contains the character then prepends <mailto: and appends >
    204 
    205203BOOL isemailaddress(PSZ pszLine)
    206204{
    207205  CHAR *tmp;
    208   CHAR *p, *pp;
     206  CHAR *p, *pp, *q;
    209207
    210208  tmp = xmallocz(strlen(pszLine) + 1, pszSrcFile, __LINE__);
     
    213211  memcpy(tmp, pszLine, strlen(pszLine));
    214212  tmp[strlen(pszLine) + 1] = 0;
     213  chop_at_crnl(tmp);
    215214  bstripcr(tmp);
    216215  p = tmp;
    217216  p++;
    218   p = strchr(p, '@');
     217  q = p = strchr(p, '@');
    219218  if (!p) {
    220219    free(tmp);
     
    231230      continue;
    232231    else if (*p == '{') {
    233       if (!strchr(p ,'}') || pp - p > 4) {
     232      if (q != p - 1 || !strchr(p ,'}')) {
    234233        free(tmp);
    235234        return FALSE;
    236235      }
     236      else // probable IP address literal user will need to decide if it is valid
     237        break;
    237238    }
    238239    else  {
     
    245246  return TRUE;
    246247}
    247 
     248// mailstr checks for a designated character in a string then cuts the string
     249//to the first word that contains the character then prepends <mailto: and appends >
    248250PSZ mailstr(CHAR *pszSrc, CHAR *pszFindChar, LONG StrLens)
    249251{
     
    317319      p = urld->line;
    318320      do {
    319         p = strnstr(p, "http://", e - p);
     321        p = strnstr(p, "http://", e - p) ? strnstr(p, "http://", e - p) : strnstr(p, "https://", e - p);
    320322        if (p) {
    321323          strncpy(urld->url, p, min(e - p, SEARCHSTRINGLEN - 1));
    322324          urld->url[min(e - p, SEARCHSTRINGLEN - 1)] = 0;
    323325          pp = urld->url;
    324           while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
     326          while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' && *pp != '\t' &&
    325327                 *pp != '\"')
    326328            pp++;
    327           *pp = 0;
     329          *pp = 0;
     330          strip_trail_char(",.;:'>", urld->url);
    328331          WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
    329332                            MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
    330           p++;
     333         p++;
    331334        }
    332335      }
     
    339342          urld->url[min(e - p, SEARCHSTRINGLEN - 1)] = 0;
    340343          pp = urld->url;
    341           while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' &&
     344          while (*pp && *pp != ' ' && *pp != '\r' && *pp != '\n' && *pp != '\t' &&
    342345                 *pp != '\"')
    343346            pp++;
    344           *pp = 0;
     347          *pp = 0;
     348          strip_trail_char(",.;:'>", urld->url);
    345349          WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
    346                             MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
     350                            MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
    347351          p++;
    348352        }
     
    352356      if (isemailaddress(p)) {
    353357        memcpy(szUrlString, urld->line, SEARCHSTRINGLEN - 1);
    354         mailstr(szUrlString, "@", e - p);
    355         memcpy(urld->url, szUrlString, strlen( szUrlString) + 1);
     358        mailstr(szUrlString, "@", e - p);
     359        p = strrchr(szUrlString, '.');
     360        memcpy(urld->url, szUrlString, (p + 4) - &szUrlString);//strlen( szUrlString) + 1);
    356361        urld->url[strlen(szUrlString) + 1] = 0;
    357362        if (pp = strchr(urld->url, '>'))
    358363          *pp = 0;
    359364        WinSendDlgItemMsg(hwnd, URL_LISTBOX, LM_INSERTITEM,
    360                           MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
     365                          MPFROM2SHORT(LIT_END, 0), MPFROMP(urld->url));
    361366      }
    362367      *urld->url = 0;
     
    413418                              MPFROMP(urld->url));
    414419            if (*urld->url) {
    415               if (!strncmp(urld->url, "http://", 7)) {
     420              if (!strncmp(urld->url, "http://", 7) || !strncmp(urld->url, "https://", 8)) {
    416421                WinDismissDlg(hwnd, 1);
    417422                break;
     
    884889              && (!ad->markedlines
    885890                  || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
    886               && strnstr(ad->lines[whichline], "http://",
    887                          e - ad->lines[whichline])) {
     891              && (strnstr(ad->lines[whichline], "http://", e - ad->lines[whichline]) ||
     892             strnstr(ad->lines[whichline], "https://", e - ad->lines[whichline]))) {
    888893            GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
    889894            GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
     
    949954              && (!ad->markedlines
    950955                  || !(ad->markedlines[whichline] & (VF_SELECTED | VF_FOUND)))
    951               && strnstr(ad->lines[whichline], "http://",e - ad->lines[whichline])) {
     956              && (strnstr(ad->lines[whichline], "http://",e - ad->lines[whichline]) ||
     957             strnstr(ad->lines[whichline], "https://",e - ad->lines[whichline]))) {
    952958            GpiSetColor(hps, standardcolors[ad->colors[COLORS_HTTPFORE]]);
    953959            GpiSetBackColor(hps, standardcolors[ad->colors[COLORS_HTTPBACK]]);
     
    14411447                ad->ftpin = TRUE;
    14421448              if ((*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
    1443                   strstr(ad->text, "http://"))
     1449                  (strstr(ad->text, "http://") || strstr(ad->text, "https://")))
    14441450                ad->httpin = TRUE;
    14451451              if (*mailrun && !ad->ignoremail && isemailaddress(ad->text))
     
    24992505
    25002506          if ((ad->httpin && (*httprun || fHttpRunWPSDefault) &&
    2501                strnstr(ad->lines[whichline], "http://", width)) ||
     2507               (strnstr(ad->lines[whichline], "http://", width) ||
     2508               strnstr(ad->lines[whichline], "https://", width))) ||
    25022509              (ad->ftpin && (*ftprun || fFtpRunWPSDefault) &&
    25032510               strnstr(ad->lines[whichline], "ftp://", width)) ||
     
    34203427      ad->httpin = FALSE;
    34213428      if (ad->text && (*httprun || fHttpRunWPSDefault) && !ad->ignorehttp &&
    3422           strstr(ad->text, "http://"))
     3429          (strstr(ad->text, "http://") || strstr(ad->text, "https://")))
    34233430        ad->httpin = TRUE;
    34243431      IgnoreHTTP = ad->ignorehttp;
Note: See TracChangeset for help on using the changeset viewer.