View Raw SPL
/*****************************************************************************
*                                                                            *
*   WEBREADCNF.SPL Copyright (C) 2023 DSP Development Corporation            *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Reads a configuration file from a URL                                 *
*                                                                            *
*   Revisions:   30 Jul 2023  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_WEBREADCNF

    WEBREADCNF

    Purpose: Reads a configuration file from a URL.

    Syntax:  WEBREADCNF("url", update, "header")

               "url"  - A string, the URL string.

               update - Optional. An integer, redraw the application after
                        applying the new settings. 

                         0: Redraw entire screen.
 
                         1: Re-initialize graphics and redraw.
 
                         2: Re-initialize fonts, re-initialize graphics,
                            and redraw (default).
 
                         3: Re-initialize Windows, re-initialize graphics,
                            and redraw.
 
                         4: Re-initialize system colors, re-initialize graphics,
                            and redraw.

             "header" - A string, the HTML header string. Defaults to empty,
                        no header.

    Returns: Nothing, if valid, the settings are loaded.

    Example:
             writecnf("D:\temp\temp.cnf")
             webreadcnf("www.dadisp.com/files/test.cnf")
             readcnf("D:\temp\temp.cnf")

             Saves the current session settings, then reads a sample
             configuration file from the URL.

             The original settings are then restored.

    Remarks:
             WEBREADCNF reads a configuration file from a URL.

             In general, use READCNF to read a configuration file since
             READCNF will call WEBREADCNF when the filename is a URL.

    See Also:
             Readcnf
             Webreadhtml
             Writecnf
#endif


/* read configuration settings from a URL */
webreadcnf(url = {}, update = 1, header = "")
{
        local cnf, cnfile, status, err;

        if (not(isstring(url)))
        {
                error(sprintf("%s - input URL required", __FUNC__));
        }

        header = webformatheader(header);

        /* get settings as binary stream */
        (cnf, status, err) = geturl(url, "", header, "binary");

        if (status == 1)
        {
                /* save to temp binary file and load as config file */
                cnffile = getmiscpath(1, 1) + "tempcnf.cnf";

                writeb(cnffile, ubyte, 1, cnf);

                status = readcnf(cnffile, update);

                return(status);
        }
        else
        {
                error(sprintf("%s - %s", __FUNC__, err));
        }
}