1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
36 #define INCL_DOSERRORS
40 // OOo uses popen() to start us, so we cannot show PM dialogs.
41 // log message to disk.
42 void logMessage( char* msg
)
45 CHAR szApplicationName
[_MAX_PATH
];
46 CHAR szDrive
[_MAX_PATH
];
47 CHAR szDir
[_MAX_PATH
];
48 CHAR szFileName
[_MAX_PATH
];
49 CHAR szExt
[_MAX_PATH
];
54 // get executable fullpath
55 DosGetInfoBlocks(NULL
, &pib
);
56 DosQueryModuleName(pib
->pib_hmte
, sizeof(szApplicationName
), szApplicationName
);
57 _splitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
59 _makepath( szApplicationName
, szDrive
, szDir
, szFileName
, (".LOG") );
60 log
= fopen( szApplicationName
, "a");
64 localTime
= localtime( &timeOfDay
);
65 fprintf( log
, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
66 localTime
->tm_year
+1900, localTime
->tm_mon
+1, localTime
->tm_mday
,
67 localTime
->tm_hour
, localTime
->tm_min
, localTime
->tm_sec
, msg
);
71 // dump comand line arguments
72 void dumpArgs( int argc
, char *argv
[] )
76 logMessage( "Start of command line arguments dump:");
77 for( i
=0; i
<argc
; i
++)
82 * The intended use of this tool is to pass the argument to
83 * the default URL exe.
85 int main(int argc
, char *argv
[] )
88 RESULTCODES result
= {0};
89 char szAppFromINI
[_MAX_PATH
];
90 char szDirFromINI
[_MAX_PATH
];
92 char szFail
[ _MAX_PATH
];
99 logMessage( "Usage: open-url <url>");
100 dumpArgs( argc
, argv
);
104 // check configuration
105 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
106 "DefaultBrowserExe", "",
107 szAppFromINI
, sizeof(szAppFromINI
));
108 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
109 "DefaultWorkingDir", "",
110 szDirFromINI
, sizeof(szDirFromINI
));
111 if (*szAppFromINI
== 0 || *szDirFromINI
== 0)
113 logMessage( "Unable to find default url handler in USER.INI; exiting.");
114 dumpArgs( argc
, argv
);
118 // get default parameter list
119 rc
= PrfQueryProfileString(HINI_USER
, "WPURLDEFAULTSETTINGS",
120 "DefaultParameters", "",
121 szCmdLine
, sizeof(szCmdLine
));
122 strcat( szCmdLine
, " ");
123 strcat( szCmdLine
, argv
[1]);
125 // change default directory
126 _chdir( szDirFromINI
);
128 // start default handler
130 CHAR szObjBuf
[CCHMAXPATH
];
132 SData
.Length
= sizeof(STARTDATA
);
133 SData
.Related
= SSF_RELATED_INDEPENDENT
;
134 SData
.FgBg
= (1) ? SSF_FGBG_FORE
: SSF_FGBG_BACK
;
135 SData
.TraceOpt
= SSF_TRACEOPT_NONE
;
137 SData
.PgmTitle
= (PSZ
)szAppFromINI
;
139 SData
.PgmName
= (PSZ
)szAppFromINI
;
140 SData
.PgmInputs
= (PSZ
)szCmdLine
;
143 SData
.Environment
= 0;
144 SData
.InheritOpt
= SSF_INHERTOPT_PARENT
;
145 SData
.SessionType
= SSF_TYPE_PM
;
149 SData
.PgmControl
= SSF_CONTROL_VISIBLE
;
153 SData
.InitXSize
= 200;
154 SData
.InitYSize
= 140;
156 SData
.ObjectBuffer
= szFail
;
157 SData
.ObjectBuffLen
= (ULONG
)sizeof(szFail
);
159 rc
= DosStartSession( &SData
, &ulSID
, &pid
);
160 // show error dialog in case of problems
161 if (rc
!= NO_ERROR
&& rc
!= ERROR_SMG_START_IN_BACKGROUND
) {
162 char szMessage
[ _MAX_PATH
*2];
163 sprintf( szMessage
, "Execution failed! rc: %d, failing module:%s", rc
, szFail
);
164 logMessage( szMessage
);
165 dumpArgs( argc
, argv
);