/************************************************/ /* */ /* emaginer.UploadSite.pkg */ /* */ /* Emaginer site upload service */ /* (can be used for scs uploads) */ /* */ /* by Loïc Berthelot, sept. 2000 */ /* */ /* ver 0.9 */ /* */ /************************************************/ /*************************************************************/ /* */ /* C O N S T A N T S */ /* */ /*************************************************************/ var SITEDEF_MODE_EMAGINER = 8;; var SITEDEF_MODE_SCS = 16;; /*************************************************************/ /* */ /* V A R I A B L E S */ /* */ /*************************************************************/ /*************************************************************/ /* */ /* E R R O R C O D E S */ /* */ /*************************************************************/ typeof SITEDEF_OK = [I S];; typeof SITEDEF_OK_STATE = [I S];; typeof SITEDEF_OK_PARSED_PARAM = [I S];; typeof SITEDEF_OK_FINISH = [I S];; typeof SITEDEF_ERR_DMS_NOT_FOUND = [I S];; typeof SITEDEF_ERR_MISSING_PARAM = [I S];; typeof SITEDEF_ERR_PARAM_NOT_FOUND = [I S];; typeof SITEDEF_ERR_BAD_MODE = [I S];; typeof SITEDEF_ERR_SERVER_NOT_FOUND = [I S];; typeof SITEDEF_ERR_NO_LOGIN = [I S];; typeof SITEDEF_ERR_NO_PASSWD = [I S];; typeof SITEDEF_ERR_NO_URL = [I S];; typeof SITEDEF_ERR_IN_TRANSFER = [I S];; typeof SITEDEF_ERR_CONNEXION_LOST = [I S];; typeof SITEDEF_ERR_REGISTRATION_FAILED = [I S];; typeof SITEDEF_ERR_INVALID_LOGIN = [I S];; typeof SITEDEF_ERR_PARSER_NIL = [I S];; /***************************/ /* Site Definition */ /***************************/ struct SiteDef = [ wzdChn_SiteDef : Chn, mode_SiteDef : I, dms_SiteDef : S, url_SiteDef : S, login_SiteDef : S, passwd_SiteDef : S, errCode_SiteDef : I, errMsg_SiteDef : S, errLog_SiteDef : [S r1], /* list of (parameter_name parameter_value) */ /* (parameter name, values count, list of values */ nbParams_SiteDef : I, paramsList_SiteDef : [[S I [S r1]] r1], /* parsing struct */ parserCb_SiteDef : fun [SiteDef] I, stateCb_SiteDef : fun [SiteDef I S] I, httpChn_SiteDef : Http_Chn /*Chn*/ ] mkSiteDef;; typeof sitedef = SiteDef ;; fun _INCRsiteDefNbParams (sitedef) = set sitedef.nbParams_SiteDef = sitedef.nbParams_SiteDef + 1; 1;; /***************************************************************/ /***************************************************************/ /** **/ /** I N T E R N A L F U N C T I O N S **/ /** **/ /***************************************************************/ /***************************************************************/ proto _ADDsiteDefLog = fun [SiteDef S] I;; /*******************************************/ /* _siteDefErr [ SiteDef [I S] S] I */ /* */ /* build an error code, and set it into */ /* the siteDef struct. */ /* */ /*******************************************/ fun _siteDefErr (sitedef, code, msg) = { let code -> [codeNum codeMsg] in { if code == SITEDEF_OK_FINISH then UPLOAD_OnUploadProcessTerminated UploadInfo 1 else if code == SITEDEF_ERR_DMS_NOT_FOUND || code == SITEDEF_ERR_MISSING_PARAM || code == SITEDEF_ERR_BAD_MODE || code == SITEDEF_ERR_NO_LOGIN || code == SITEDEF_ERR_NO_PASSWD || code == SITEDEF_ERR_NO_URL || code == SITEDEF_ERR_IN_TRANSFER || code == SITEDEF_ERR_CONNEXION_LOST || code == SITEDEF_ERR_REGISTRATION_FAILED || code == SITEDEF_ERR_CONNEXION_LOST || code == SITEDEF_ERR_INVALID_LOGIN || code == SITEDEF_ERR_PARSER_NIL then UPLOAD_OnUploadProcessTerminated UploadInfo 0 else nil ; set sitedef.errCode_SiteDef = codeNum ; let if (msg != nil) then msg else codeMsg -> newMsg in if (newMsg == nil) then nil else ( set sitedef.errMsg_SiteDef = newMsg; _ADDsiteDefLog sitedef newMsg; exec sitedef.stateCb_SiteDef with [sitedef codeNum newMsg]; 1; ); } ; };; proto _internalGETsiteDefParams = fun [SiteDef S [[S I [S r1]] r1]] [S I [S r1]];; /*******************************************/ /* _siteDefCheckParam [SiteDef S] */ /* */ /* check the value of the parameter */ /* and add a log message. */ /* */ /*******************************************/ fun _siteDefCheckParam (sitedef, paramname) = let _internalGETsiteDefParams sitedef paramname sitedef.paramsList_SiteDef -> paramsList in let if (paramsList == nil) then [SITEDEF_ERR_MISSING_PARAM (strcatn "!! UPLOAD_SITE ERROR : parameter \""::paramname::"\" is missing !"::nil)] else let paramsList -> [_ nb values] in let hd values -> lastValue in if ((lastValue == nil) || (!strcmp lastValue "")) then [SITEDEF_ERR_MISSING_PARAM (strcatn "!! UPLOAD_SITE ERROR : one parameter \""::paramname::"\" is missing !"::nil)] else [SITEDEF_OK (strcatn "UPLOAD_SITE : parameter found \""::paramname::"\", value =\""::lastValue::"\""::nil)] -> [code codeMsg] in _siteDefErr sitedef code codeMsg;; proto _GETsiteDefDms = fun [SiteDef] S;; /* check dms file */ fun _siteDefCheckDmsFile (sitedef) = let if ((_checkpack (_GETsiteDefDms (sitedef))) == nil) then [ SITEDEF_ERR_DMS_NOT_FOUND (strcat strcat "!! UPLOAD_SITE ERROR : DMS file \"" (_GETsiteDefDms (sitedef)) "\" not found !!") ] else [ SITEDEF_OK (strcat strcat "UPLOAD_SITE : DMS file \"" (_GETsiteDefDms (sitedef)) "\" has been found") ] -> [code msg] in ( _siteDefErr sitedef code msg; 1; );; proto _GETsiteDefMode = fun [SiteDef] I;; /* check upload mode */ fun _siteDefCheckMode (sitedef) = let _GETsiteDefMode sitedef -> mode in let if ((mode == SITEDEF_MODE_EMAGINER) || (mode == SITEDEF_MODE_SCS)) then let if (mode == SITEDEF_MODE_EMAGINER) then "SITEDEF_MODE_EMAGINER" else "SITEDEF_MODE_SCS" -> modeStr in [ SITEDEF_OK (strcat strcat "UPLOAD_SITE : transmission mode = \"" modeStr "\"") ] else let SITEDEF_ERR_BAD_MODE -> [codeNum codeMsg] in [ SITEDEF_ERR_BAD_MODE codeMsg ] -> [code msg] in ( _siteDefErr sitedef code msg; 1; );; /* internal get params function */ fun _internalGETsiteDefParams (sitedef, paramname, paramsList) = if (paramsList == nil) then ( _siteDefErr sitedef SITEDEF_ERR_PARAM_NOT_FOUND (strcat strcat "!!UPLOAD_SITE WARNING : parameter \"" paramname "\" not found!"); nil; ) else ( let hd paramsList -> firstParam in let firstParam -> [name nb values] in if (!strcmpi name paramname) then firstParam else _internalGETsiteDefParams sitedef paramname (tl paramsList); );; /* internal add param function */ fun _internalADDsiteDefParam (paramsList, currentParamsList, paramname, paramvalue) = if (currentParamsList == nil) then [paramname 1 paramvalue::nil]::nil else let hd currentParamsList -> [name nb values] in if (!strcmpi name paramname) then [name (nb+1) (listcat values paramvalue::nil)]::(tl currentParamsList) else [name nb values]::(_internalADDsiteDefParam paramsList (tl currentParamsList) paramname paramvalue);; /***************************************************************/ /***************************************************************/ /** **/ /** E X T E R N A L F U N C T I O N S **/ /** **/ /** READ STRUCT **/ /** **/ /***************************************************************/ /***************************************************************/ /* fun [SiteDef] I */ fun _GETsiteDefMode (sitedef) = sitedef.mode_SiteDef;; /* fun [SiteDef] S */ fun _GETsiteDefDms (sitedef) = sitedef.dms_SiteDef;; /* fun [SiteDef] S */ fun _GETsiteDefUrl (sitedef) = sitedef.url_SiteDef;; /* fun [SiteDef] S */ fun _GETsiteDefLogin (sitedef) = sitedef.login_SiteDef;; /* fun [SiteDef] S */ fun _GETsiteDefPasswd (sitedef) = sitedef.passwd_SiteDef;; /* fun [SiteDef] I */ fun _GETsiteDefErrCode (sitedef) = sitedef.errCode_SiteDef;; /* fun [SiteDef] S */ fun _GETsiteDefErrMsg (sitedef) = sitedef.errMsg_SiteDef;; /* fun [SiteDef] [S r1] */ fun _GETsiteDefLog (sitedef) = sitedef.errLog_SiteDef;; /* fun [SiteDef S] S */ fun _GETsiteDefParam (sitedef, paramname) = let _internalGETsiteDefParams sitedef paramname sitedef.paramsList_SiteDef -> [_ _ [firstValue _]] in firstValue;; /* fun [SiteDef S] [S r1] */ fun _GETsiteDefParams (sitedef, paramname) = let _internalGETsiteDefParams sitedef paramname sitedef.paramsList_SiteDef -> param in if (param == nil) then nil else let param -> [_ _ values] in values;; fun _internalGETsiteDefAllParamsNames (paramsList) = if (paramsList == nil) then nil else let hd paramsList -> [name _ _] in name::(_internalGETsiteDefAllParamsNames (tl paramsList));; /* fun [SiteDef] [S r1] */ fun _GETsiteDefAllParamsNames (sitedef) = _internalGETsiteDefAllParamsNames sitedef.paramsList_SiteDef;; fun _internalGETsiteDefAllParamsValues (paramsList) = if (paramsList == nil) then nil else let hd paramsList -> [_ _ values] in listcat values (_internalGETsiteDefAllParamsValues (tl paramsList));; /* fun [SiteDef] [S r1] */ fun _GETsiteDefAllParamsValues (sitedef) = _internalGETsiteDefAllParamsValues sitedef.paramsList_SiteDef;; /* fun [SiteDef] I */ fun _EXECsiteDefParser (sitedef) = if (sitedef.parserCb_SiteDef == nil) then _siteDefErr sitedef SITEDEF_ERR_PARSER_NIL nil else exec sitedef.parserCb_SiteDef with [sitedef];; /* fun [SiteDef] Http_Chn */ fun _GETsiteDefHttpChn (sitedef) = sitedef.httpChn_SiteDef;; /* fun [SiteDef] Chn */ fun _GETsiteDefWzdChn (sitedef) = sitedef.wzdChn_SiteDef;; /***************************************************************/ /***************************************************************/ /** **/ /** E X T E R N A L F U N C T I O N S **/ /** **/ /** WRITE STRUCT **/ /** **/ /***************************************************************/ /***************************************************************/ /* fun [SiteDef S] I */ fun _SETsiteDefDms (sitedef, dms) = set sitedef.dms_SiteDef = dms;; /* fun [SiteDef S] I */ fun _SETsiteDefUrl (sitedef, url) = set sitedef.url_SiteDef = url;; /* fun [SiteDef S] I */ fun _SETsiteDefLogin (sitedef, login) = set sitedef.login_SiteDef = login;; /* fun [SiteDef S] I */ fun _SETsiteDefPass (sitedef, pass) = set sitedef.passwd_SiteDef = pass;; /* fun [SiteDef [S S r1]] I */ fun _SETsiteDefParamsList (sitedef, paramsList) = set sitedef.paramsList_SiteDef = paramsList;; /* fun [SiteDef [S S]] I */ fun _ADDsiteDefParam (sitedef, param, value) = set sitedef.paramsList_SiteDef = _internalADDsiteDefParam sitedef.paramsList_SiteDef sitedef.paramsList_SiteDef param value; _siteDefCheckParam sitedef param;; /* fun [SiteDef S] I */ fun _ADDsiteDefLog (sitedef, msg) = set sitedef.errLog_SiteDef = listcat sitedef.errLog_SiteDef (strcat "\n" msg)::nil; 1;; /* fun [SiteDef fun[SiteDef] I] I */ fun _SETsiteDefParserCb (sitedef, cb) = if (cb == nil) then ( _siteDefErr sitedef SITEDEF_ERR_PARSER_NIL nil; 0; ) else ( set sitedef.parserCb_SiteDef = cb; 1; );; /****************************************************************/ /****************************************************************/ /** **/ /** E X T E R N A L M A I N F U N C T I O N S **/ /** **/ /****************************************************************/ /****************************************************************/ fun _UploadSiteInitErrorCodes() = set SITEDEF_OK = [1 " : OK"]; set SITEDEF_OK_PARSED_PARAM = [1 nil]; set SITEDEF_OK_STATE = [2 nil]; set SITEDEF_OK_FINISH = [3 nil]; set SITEDEF_ERR_DMS_NOT_FOUND = [-1 nil]; set SITEDEF_ERR_MISSING_PARAM = [-3 nil]; set SITEDEF_ERR_PARAM_NOT_FOUND = [-4 nil]; set SITEDEF_ERR_BAD_MODE = [-5 "!! : UPLOAD MODE must be \"SITEDEF_MODE_EMAGINER\" or \"SITEDEF_MODE_SCS\" !"]; set SITEDEF_ERR_SERVER_NOT_FOUND = [-6 "!! : server not found!"]; set SITEDEF_ERR_NO_LOGIN = [-7 "!! : login unreadable !"]; set SITEDEF_ERR_NO_PASSWD = [-8 "!! : password unreadable !"]; set SITEDEF_ERR_NO_URL = [-9 "!! : url unreadable !"]; /* upload error codes */ set SITEDEF_ERR_IN_TRANSFER = [-10 nil]; set SITEDEF_ERR_CONNEXION_LOST = [-11 "!! : CONNEXION LOST !"]; set SITEDEF_ERR_REGISTRATION_FAILED = [-12 "!! : registration failed !"]; set SITEDEF_ERR_INVALID_LOGIN = [-13 "!! : invalid login or password"]; set SITEDEF_ERR_PARSER_NIL = [-14 "!! : parser NIL!"]; 1;; /************************************************************/ /* UploadSiteInit [Chn I S S S S fun [SiteDef I S]] SiteDef */ /* */ /* initialise sitedef struct et returns its */ /* reference. */ /* */ /************************************************************/ fun UploadSiteInit (wzdchn, mode, dms, url, login, pass, stateCb) = _UploadSiteInitErrorCodes; let mkSiteDef [wzdchn mode dms url login pass nil nil nil 0 nil nil stateCb nil] -> sitedef in ( _siteDefCheckMode sitedef; _siteDefCheckDmsFile sitedef; sitedef; );; fun my_printState (sitedef, errCode, errMsg) = { let _getmodifypack "dms/scs2/scsupload.log" -> wfile in { _appendpack strcat errMsg "\n" wfile ; if errCode >= 0 then nil else { /*UPLOAD_OnUploadProcessTerminated UploadInfo 0 ;*/ ERRORS_AddError 1 53 (_locSCS "errorlabel-UPLOADERROR" errMsg::nil); } ; } ; 0 };; /***********************************************/ /* UploadSiteStart [] I */ /* */ /* upload a site to server */ /* */ /***********************************************/ fun UploadSiteStart (sitedef) = if (sitedef == nil) then 0 else ( let _getmodifypack "dms/scs2/scsupload.log" -> wfile in _createpack "" wfile ; let _GETsiteDefLogin sitedef -> login in let _GETsiteDefPasswd sitedef -> passwd in let _GETsiteDefUrl sitedef -> url in if ((login == nil) || ((strlen login) <= 0)) then _siteDefErr sitedef SITEDEF_ERR_NO_LOGIN nil else if ((passwd == nil) || ((strlen passwd) <= 0)) then _siteDefErr sitedef SITEDEF_ERR_NO_PASSWD nil else if ((url == nil) || ((strlen url) <= 0)) then { _siteDefErr sitedef SITEDEF_ERR_NO_URL nil ; } else ( set sitedef.httpChn_SiteDef = http_openchannel url "_load\ \"dms/scs2/GUI/upload/scs.clientContact.pkg\"" _envchannel _channel; if (sitedef.httpChn_SiteDef == nil) then { _siteDefErr sitedef SITEDEF_ERR_SERVER_NOT_FOUND (strcat strcat "!! UPLOAD_SITE ERROR : server \"" url "\" not found!") ; } else _siteDefErr sitedef SITEDEF_OK (strcat strcat "UPLOAD_SITE : channel opened on server \"" url "\""); ); );; fun UPLOADCENTER_LaunchUploadProcess(Info) = { /*_fooS strcatn "- Url upload = "::Info.m_CurrentHostingProvider.URLUpload:: "\n- Login = "::Info.m_CurrentHostingProvider.sLogin:: "\n- Password = "::Info.m_CurrentHostingProvider.sPassword:: " -\n"::nil ;*/ set sitedef = UploadSiteInit _channel SITEDEF_MODE_SCS Info.m_DMSfileToUpload Info.m_CurrentHostingProvider.URLUpload Info.m_CurrentHostingProvider.sLogin Info.m_CurrentHostingProvider.sPassword @my_printState ; UploadSiteStart sitedef ; 0 } ;; fun _closed () = { if UploadInfo.m_IsUploadInProgress == 0 then nil else UPLOAD_OnUploadProcessTerminated UploadInfo 0 ; 0 } ;;