Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: XTHCURL

XTHCURL.m

Go to the documentation of this file.
  1. XTHCURL ;HCIOFO/SG - HTTP 1.0 CLIENT (URL TOOLS) ;07/29/10 14:01
  1. ;;7.3;TOOLKIT;**123**;Apr 25, 1995;Build 5
  1. ;Per VHA Directive 2004-038, this routine should not be modified
  1. Q
  1. ;
  1. ;***** ENCODES THE STRING
  1. ;
  1. ; STR String to be encoded
  1. ;
  1. ENCODE(STR) ;
  1. N CH,I
  1. F I=1:1 S CH=$E(STR,I) Q:CH="" I CH?1CP D
  1. . I CH="." Q
  1. . I CH=" " S $E(STR,I)="+" Q
  1. . S $E(STR,I)="%"_$$RJ^XLFSTR($$CNV^XLFUTL($A(CH),16),2,"0"),I=I+2
  1. Q STR
  1. ;
  1. ;##### CREATES URL FROM COMPONENTS
  1. ;
  1. ; HOST Host name
  1. ; [PORT] Port number (80, by default)
  1. ; [PATH] Resource path ("/", by default)
  1. ;
  1. ; [.QUERY] Reference to a local variable containing values of
  1. ; the query parameters: QUERY(Name)=Value.
  1. ;
  1. ; Return values:
  1. ; <0 Error Descriptor
  1. ; ... Resulting URL
  1. ;
  1. MAKEURL(HOST,PORT,PATH,QUERY) ;
  1. N NAME,QSTR,VAL
  1. S:HOST'["://" HOST="http://"_HOST
  1. S PORT=$S($G(PORT)>0:":"_(+PORT),1:"")
  1. ;---
  1. S (NAME,QSTR)=""
  1. F S NAME=$O(QUERY(NAME)) Q:NAME="" D
  1. . S VAL=$G(QUERY(NAME))
  1. . S QSTR=QSTR_"&"_$$ENCODE(NAME)_"="_$$ENCODE(VAL)
  1. S:QSTR'="" $E(QSTR,1)="?"
  1. ;---
  1. S:$G(PATH)="" PATH="/"
  1. Q HOST_PORT_$$NORMPATH($G(PATH)_QSTR)
  1. ;
  1. ;##### RETURNS "NORMALIZED" PATH
  1. ;
  1. ; PATH Source path
  1. ;
  1. NORMPATH(PATH) ;
  1. N LAST
  1. ;--- Make sure the path has a leading slash if it
  1. ;--- is not empty and has no query string
  1. I $E(PATH,1)'="/" S:$E(PATH,1)'="?" PATH="/"_PATH
  1. ;--- Append a trailing slash to the path if it has
  1. ;--- neither a file name nor a query string
  1. S LAST=$L(PATH,"/"),LAST=$P(PATH,"/",LAST)
  1. I LAST'="",LAST'["?",LAST'["." S PATH=PATH_"/"
  1. Q PATH
  1. ;
  1. ;##### PARSES THE URL INTO COMPONENTS
  1. ;
  1. ; URL Source URL
  1. ;
  1. ; .HOST Reference to a local variable for the host name
  1. ; .PORT Reference to a local variable for the port number
  1. ; .PATH Reference to a local variable for the path
  1. ;
  1. ; Return values:
  1. ; <0 Error Descriptor
  1. ; 0 Ok
  1. ;
  1. PARSEURL(URL,HOST,PORT,PATH) ;
  1. S:$F(URL,"://") URL=$P(URL,"://",2,999)
  1. S HOST=$TR($P(URL,"/")," ")
  1. S PATH=$$NORMPATH($P(URL,"/",2,999))
  1. S PORT=$P(HOST,":",2),HOST=$P(HOST,":")
  1. Q:HOST?." " $$ERROR^XTHC10(1,URL)
  1. S:PORT'>0 PORT=80
  1. Q 0