Changeset 8e5935d for functions.c


Ignore:
Timestamp:
Dec 12, 2008, 1:27:39 AM (15 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
4f15e8e
Parents:
80a465c
git-author:
Anders Kaseorg <andersk@mit.edu> (12/06/08 23:37:40)
git-committer:
Anders Kaseorg <andersk@mit.edu> (12/12/08 01:27:39)
Message:
Rip out the openurl function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rb9cb41b r8e5935d  
    10511051  owl_function_debugmsg("Quitting Owl");
    10521052  exit(0);
    1053 }
    1054 
    1055 void owl_function_openurl()
    1056 {
    1057   /* visit the first url in the current message */
    1058   owl_message *m;
    1059   owl_view *v;
    1060   char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];
    1061   int webbrowser;
    1062 
    1063   webbrowser = owl_global_get_webbrowser(&g);
    1064 
    1065   if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {
    1066     owl_function_error("No browser selected");
    1067     return;
    1068   }
    1069 
    1070   v=owl_global_get_current_view(&g);
    1071  
    1072   m=owl_view_get_element(v, owl_global_get_curmsg(&g));
    1073 
    1074   if (!m || owl_view_get_size(v)==0) {
    1075     owl_function_error("No current message selected");
    1076     return;
    1077   }
    1078 
    1079   text=owl_message_get_text(m);
    1080 
    1081   /* First look for a good URL */ 
    1082   if ((ptr1=strstr(text, "http://"))!=NULL) {
    1083     ptr2=strpbrk(ptr1, " \n\t");
    1084     if (ptr2) {
    1085       strncpy(url, ptr1, ptr2-ptr1+1);
    1086       url[ptr2-ptr1+1]='\0';
    1087     } else {
    1088       strcpy(url, ptr1);
    1089     }
    1090 
    1091     /* if we had <http strip a trailing > */
    1092     if (ptr1>text && ptr1[-1]=='<') {
    1093       if (url[strlen(url)-1]=='>') {
    1094         url[strlen(url)-1]='\0';
    1095       }
    1096     }
    1097   } else if ((ptr1=strstr(text, "https://"))!=NULL) {
    1098     /* Look for an https URL */ 
    1099     ptr2=strpbrk(ptr1, " \n\t");
    1100     if (ptr2) {
    1101       strncpy(url, ptr1, ptr2-ptr1+1);
    1102       url[ptr2-ptr1+1]='\0';
    1103     } else {
    1104       strcpy(url, ptr1);
    1105     }
    1106    
    1107     /* if we had <http strip a trailing > */
    1108     if (ptr1>text && ptr1[-1]=='<') {
    1109       if (url[strlen(url)-1]=='>') {
    1110         url[strlen(url)-1]='\0';
    1111       }
    1112     }
    1113   } else if ((ptr1=strstr(text, "www."))!=NULL) {
    1114     /* if we can't find a real url look for www.something */
    1115     ptr2=strpbrk(ptr1, " \n\t");
    1116     if (ptr2) {
    1117       strncpy(url, ptr1, ptr2-ptr1+1);
    1118       url[ptr2-ptr1+1]='\0';
    1119     } else {
    1120       strcpy(url, ptr1);
    1121     }
    1122   } else {
    1123     owl_function_beep();
    1124     owl_function_error("Could not find URL to open.");
    1125     return;
    1126   }
    1127 
    1128   /* Make sure there aren't any quotes or \'s in the url */
    1129   for (ptr1 = url; *ptr1; ptr1++) {
    1130     if (*ptr1 == '"' || *ptr1 == '\\') {
    1131       owl_function_beep();
    1132       owl_function_error("URL contains invalid characters.");
    1133       return;
    1134     }
    1135   }
    1136  
    1137   /* NOTE: There are potentially serious security issues here... */
    1138 
    1139   /* open the page */
    1140   owl_function_makemsg("Opening %s", url);
    1141   if (webbrowser == OWL_WEBBROWSER_NETSCAPE) {
    1142     snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url);
    1143     system(tmpbuff);
    1144   } else if (webbrowser == OWL_WEBBROWSER_GALEON) {
    1145     snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url);
    1146     system(tmpbuff);
    1147   } else if (webbrowser == OWL_WEBBROWSER_OPERA) {
    1148     snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url);
    1149     system(tmpbuff);
    1150   }
    11511053}
    11521054
Note: See TracChangeset for help on using the changeset viewer.