1*badc9ebbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*badc9ebbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*badc9ebbSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*badc9ebbSAndrew Rist * distributed with this work for additional information 6*badc9ebbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*badc9ebbSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*badc9ebbSAndrew Rist * "License"); you may not use this file except in compliance 9*badc9ebbSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*badc9ebbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*badc9ebbSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*badc9ebbSAndrew Rist * software distributed under the License is distributed on an 15*badc9ebbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*badc9ebbSAndrew Rist * KIND, either express or implied. See the License for the 17*badc9ebbSAndrew Rist * specific language governing permissions and limitations 18*badc9ebbSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*badc9ebbSAndrew Rist *************************************************************/ 21*badc9ebbSAndrew Rist 22*badc9ebbSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <stdlib.h> 25cdf0e10cSrcweir #include <stdio.h> 26cdf0e10cSrcweir #include <string.h> 27cdf0e10cSrcweir #include <unistd.h> 28cdf0e10cSrcweir #include <process.h> 29cdf0e10cSrcweir #include <time.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #define INCL_DOS 32cdf0e10cSrcweir #define INCL_DOSERRORS 33cdf0e10cSrcweir #define INCL_PM 34cdf0e10cSrcweir #include <os2.h> 35cdf0e10cSrcweir 36cdf0e10cSrcweir // OOo uses popen() to start us, so we cannot show PM dialogs. 37cdf0e10cSrcweir // log message to disk. 38cdf0e10cSrcweir void logMessage( char* msg) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir PPIB pib; 41cdf0e10cSrcweir CHAR szApplicationName[_MAX_PATH]; 42cdf0e10cSrcweir CHAR szDrive[_MAX_PATH]; 43cdf0e10cSrcweir CHAR szDir[_MAX_PATH]; 44cdf0e10cSrcweir CHAR szFileName[_MAX_PATH]; 45cdf0e10cSrcweir CHAR szExt[_MAX_PATH]; 46cdf0e10cSrcweir FILE* log; 47cdf0e10cSrcweir time_t timeOfDay; 48cdf0e10cSrcweir struct tm* localTime; 49cdf0e10cSrcweir 50cdf0e10cSrcweir // get executable fullpath 51cdf0e10cSrcweir DosGetInfoBlocks(NULL, &pib); 52cdf0e10cSrcweir DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName); 53cdf0e10cSrcweir _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt ); 54cdf0e10cSrcweir // log name 55cdf0e10cSrcweir _makepath( szApplicationName, szDrive, szDir, szFileName, (".LOG") ); 56cdf0e10cSrcweir log = fopen( szApplicationName, "a"); 57cdf0e10cSrcweir if (!log) 58cdf0e10cSrcweir return; 59cdf0e10cSrcweir time( &timeOfDay); 60cdf0e10cSrcweir localTime = localtime( &timeOfDay); 61cdf0e10cSrcweir fprintf( log, "%04d/%02d/%02d %02d:%02d:%02d %s\n", 62cdf0e10cSrcweir localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, 63cdf0e10cSrcweir localTime->tm_hour, localTime->tm_min, localTime->tm_sec, msg); 64cdf0e10cSrcweir fclose( log); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir // dump comand line arguments 68cdf0e10cSrcweir void dumpArgs( int argc, char *argv[] ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir int i; 71cdf0e10cSrcweir 72cdf0e10cSrcweir logMessage( "Start of command line arguments dump:"); 73cdf0e10cSrcweir for( i=0; i<argc; i++) 74cdf0e10cSrcweir logMessage( argv[i]); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir /* 78cdf0e10cSrcweir * The intended use of this tool is to pass the argument to 79cdf0e10cSrcweir * the default URL exe. 80cdf0e10cSrcweir */ 81cdf0e10cSrcweir int main(int argc, char *argv[] ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir APIRET rc; 84cdf0e10cSrcweir RESULTCODES result = {0}; 85cdf0e10cSrcweir char szAppFromINI[_MAX_PATH]; 86cdf0e10cSrcweir char szDirFromINI[_MAX_PATH]; 87cdf0e10cSrcweir char szCmdLine[1024]; 88cdf0e10cSrcweir char szFail[ _MAX_PATH]; 89cdf0e10cSrcweir ULONG ulSID; 90cdf0e10cSrcweir PID pid; 91cdf0e10cSrcweir 92cdf0e10cSrcweir // check parameters 93cdf0e10cSrcweir if (argc != 2) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir logMessage( "Usage: open-url <url>"); 96cdf0e10cSrcweir dumpArgs( argc, argv); 97cdf0e10cSrcweir return -1; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir // check configuration 101cdf0e10cSrcweir rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS", 102cdf0e10cSrcweir "DefaultBrowserExe", "", 103cdf0e10cSrcweir szAppFromINI, sizeof(szAppFromINI)); 104cdf0e10cSrcweir rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS", 105cdf0e10cSrcweir "DefaultWorkingDir", "", 106cdf0e10cSrcweir szDirFromINI, sizeof(szDirFromINI)); 107cdf0e10cSrcweir if (*szAppFromINI == 0 || *szDirFromINI == 0) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir logMessage( "Unable to find default url handler in USER.INI; exiting."); 110cdf0e10cSrcweir dumpArgs( argc, argv); 111cdf0e10cSrcweir return -1; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // get default parameter list 115cdf0e10cSrcweir rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS", 116cdf0e10cSrcweir "DefaultParameters", "", 117cdf0e10cSrcweir szCmdLine, sizeof(szCmdLine)); 118cdf0e10cSrcweir strcat( szCmdLine, " "); 119cdf0e10cSrcweir strcat( szCmdLine, argv[1]); 120cdf0e10cSrcweir 121cdf0e10cSrcweir // change default directory 122cdf0e10cSrcweir _chdir( szDirFromINI); 123cdf0e10cSrcweir 124cdf0e10cSrcweir // start default handler 125cdf0e10cSrcweir STARTDATA SData; 126cdf0e10cSrcweir CHAR szObjBuf[CCHMAXPATH]; 127cdf0e10cSrcweir 128cdf0e10cSrcweir SData.Length = sizeof(STARTDATA); 129cdf0e10cSrcweir SData.Related = SSF_RELATED_INDEPENDENT; 130cdf0e10cSrcweir SData.FgBg = (1) ? SSF_FGBG_FORE : SSF_FGBG_BACK; 131cdf0e10cSrcweir SData.TraceOpt = SSF_TRACEOPT_NONE; 132cdf0e10cSrcweir 133cdf0e10cSrcweir SData.PgmTitle = (PSZ)szAppFromINI; 134cdf0e10cSrcweir 135cdf0e10cSrcweir SData.PgmName = (PSZ)szAppFromINI; 136cdf0e10cSrcweir SData.PgmInputs = (PSZ)szCmdLine; 137cdf0e10cSrcweir 138cdf0e10cSrcweir SData.TermQ = NULL; 139cdf0e10cSrcweir SData.Environment = 0; 140cdf0e10cSrcweir SData.InheritOpt = SSF_INHERTOPT_PARENT; 141cdf0e10cSrcweir SData.SessionType = SSF_TYPE_PM; 142cdf0e10cSrcweir SData.IconFile = 0; 143cdf0e10cSrcweir SData.PgmHandle = 0; 144cdf0e10cSrcweir 145cdf0e10cSrcweir SData.PgmControl = SSF_CONTROL_VISIBLE; 146cdf0e10cSrcweir 147cdf0e10cSrcweir SData.InitXPos = 30; 148cdf0e10cSrcweir SData.InitYPos = 40; 149cdf0e10cSrcweir SData.InitXSize = 200; 150cdf0e10cSrcweir SData.InitYSize = 140; 151cdf0e10cSrcweir SData.Reserved = 0; 152cdf0e10cSrcweir SData.ObjectBuffer = szFail; 153cdf0e10cSrcweir SData.ObjectBuffLen = (ULONG)sizeof(szFail); 154cdf0e10cSrcweir 155cdf0e10cSrcweir rc = DosStartSession( &SData, &ulSID, &pid); 156cdf0e10cSrcweir // show error dialog in case of problems 157cdf0e10cSrcweir if (rc != NO_ERROR && rc != ERROR_SMG_START_IN_BACKGROUND) { 158cdf0e10cSrcweir char szMessage[ _MAX_PATH*2]; 159cdf0e10cSrcweir sprintf( szMessage, "Execution failed! rc: %d, failing module:%s", rc, szFail); 160cdf0e10cSrcweir logMessage( szMessage); 161cdf0e10cSrcweir dumpArgs( argc, argv); 162cdf0e10cSrcweir return -1; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ok 166cdf0e10cSrcweir return 0; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169