home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libnet / mkremote.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.9 KB  |  176 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* forks a telnet process
  19.  *
  20.  * Designed and implemented by Lou Montulli
  21.  */
  22.  
  23. /* Please leave outside of ifdef for windows precompiled headers */
  24. #include "mkutils.h"
  25.  
  26. #ifdef MOZILLA_CLIENT
  27.  
  28. #include "mkparse.h"
  29. #include "mkremote.h"
  30. #include "glhist.h"
  31. #include "mkgeturl.h"   /* for URL types */
  32. #include "merrors.h"
  33.  
  34. /*
  35.  * begin a session with a remote host.
  36.  *
  37.  * URL types permitted: Telnet, TN3270, and Rlogin
  38.  */
  39. MODULE_PRIVATE int32
  40. NET_RemoteHostLoad (ActiveEntry  * cur_entry)
  41. {
  42.     char * host_string;
  43.     int url_type;
  44.     char * cp;
  45.     char * username;
  46.     char * hostname;
  47.     char * port_string;
  48.  
  49.     TRACEMSG(("In NET_RemoteHostLoad"));
  50.  
  51.     GH_UpdateGlobalHistory(cur_entry->URL_s);
  52.  
  53.     if(cur_entry->format_out == FO_CACHE_AND_PRESENT || cur_entry->format_out == FO_PRESENT)
  54.       {
  55.         url_type = NET_URL_Type(cur_entry->URL_s->address);
  56.         host_string = NET_ParseURL(cur_entry->URL_s->address, GET_USERNAME_PART | GET_PASSWORD_PART | GET_HOST_PART);
  57.  
  58.         hostname = XP_STRCHR(host_string, '@');
  59.         port_string = XP_STRCHR(host_string, ':');
  60.  
  61.         if (hostname)
  62.             {
  63.             *hostname++ = '\0';  
  64.             username = NET_UnEscape(host_string);
  65.           }
  66.         else
  67.           {
  68.             hostname = host_string;
  69.             username = NULL;  /* no username given */
  70.           }
  71.  
  72.         if (port_string)
  73.           {
  74.             *port_string++ = '\0';  
  75.  
  76.             /* Sanity check the port part
  77.              * prevent telnet://hostname:30;rm -rf *  URL's (VERY BAD)
  78.              * only allow digits
  79.              */
  80.             for(cp=port_string; *cp != '\0'; cp++)
  81.                 if(!isdigit(*cp))
  82.                   {
  83.                     *cp = '\0';
  84.                     break;
  85.                   }
  86.           }
  87.  
  88.        
  89.         if(username)
  90.           {
  91.             /* Sanity check the username part
  92.              * prevent telnet://hostname:30;rm -rf *  URL's (VERY BAD)
  93.              * only allow alphanums
  94.              */
  95.             for(cp=username; *cp != '\0'; cp++)
  96.                 if(!isalnum(*cp))
  97.                   {
  98.                     *cp = '\0';
  99.                     break;
  100.                   }
  101.           }
  102.  
  103.         /* now sanity check the hostname part
  104.          * prevent telnet://hostname;rm -rf *  URL's (VERY BAD)
  105.          * only allow alphanumeric characters and a few symbols
  106.          */
  107.         for(cp=hostname; *cp != '\0'; cp++)
  108.         if(!isalnum(*cp) && *cp != '_' && *cp != '-' &&
  109.               *cp != '+' && *cp != ':' && *cp != '.' && *cp != '@')
  110.           {
  111.             *cp = '\0';
  112.             break;
  113.           }
  114.  
  115.         TRACEMSG(("username: %s, hostname: %s, port: %s", 
  116.                   username ? username : "(null)",
  117.                   hostname ? hostname : "(null)",
  118.                   port_string ? port_string : "(null)"));
  119.  
  120.         if(url_type == TELNET_TYPE_URL)
  121.           {
  122.             FE_ConnectToRemoteHost(cur_entry->window_id, FE_TELNET_URL_TYPE, hostname, port_string, username);
  123.           }
  124.         else if(url_type == TN3270_TYPE_URL)
  125.           {
  126.             FE_ConnectToRemoteHost(cur_entry->window_id, FE_TN3270_URL_TYPE, hostname, port_string, username);
  127.           }
  128.         else if(url_type == RLOGIN_TYPE_URL)
  129.           {
  130.             FE_ConnectToRemoteHost(cur_entry->window_id, FE_RLOGIN_URL_TYPE, hostname, port_string, username);
  131.           }
  132.         /* fall through if it wasn't any of the above url types */
  133.  
  134.         XP_FREE(host_string);
  135.       }
  136.  
  137.     cur_entry->status = MK_NO_DATA;
  138.     return -1;
  139. }
  140.  
  141. PRIVATE int32
  142. net_ProcessRemote(ActiveEntry *ce)
  143. {
  144.     XP_ASSERT(0);
  145.     return -1;
  146. }
  147.  
  148. PRIVATE int32
  149. net_InterruptRemote(ActiveEntry *ce)
  150. {
  151.     XP_ASSERT(0);
  152.     return -1;
  153. }
  154.  
  155. PRIVATE void
  156. net_CleanupRemote(void)
  157. {
  158. }
  159.  
  160. MODULE_PRIVATE void
  161. NET_InitRemoteProtocol(void)
  162. {
  163.     static NET_ProtoImpl remote_proto_impl;
  164.  
  165.     remote_proto_impl.init = NET_RemoteHostLoad;
  166.     remote_proto_impl.process = net_ProcessRemote;
  167.     remote_proto_impl.interrupt = net_InterruptRemote;
  168.     remote_proto_impl.cleanup = net_CleanupRemote;
  169.  
  170.     NET_RegisterProtocolImplementation(&remote_proto_impl, RLOGIN_TYPE_URL);
  171.     NET_RegisterProtocolImplementation(&remote_proto_impl, TELNET_TYPE_URL);
  172.     NET_RegisterProtocolImplementation(&remote_proto_impl, TN3270_TYPE_URL);
  173. }
  174.  
  175. #endif /* MOZILLA_CLIENT */
  176.