update dev300-m58
[ooovba.git] / shell / source / unix / misc / open-url.c
blobc6c5a9c2c7671f0f7b437c2170b47535e05b5685
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile:$
7 * $Revision:$
9 * last change: $Author:$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include <process.h>
41 #include <time.h>
43 #define INCL_DOS
44 #define INCL_DOSERRORS
45 #define INCL_PM
46 #include <os2.h>
48 // OOo uses popen() to start us, so we cannot show PM dialogs.
49 // log message to disk.
50 void logMessage( char* msg)
52 PPIB pib;
53 CHAR szApplicationName[_MAX_PATH];
54 CHAR szDrive[_MAX_PATH];
55 CHAR szDir[_MAX_PATH];
56 CHAR szFileName[_MAX_PATH];
57 CHAR szExt[_MAX_PATH];
58 FILE* log;
59 time_t timeOfDay;
60 struct tm* localTime;
62 // get executable fullpath
63 DosGetInfoBlocks(NULL, &pib);
64 DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName);
65 _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt );
66 // log name
67 _makepath( szApplicationName, szDrive, szDir, szFileName, (".LOG") );
68 log = fopen( szApplicationName, "a");
69 if (!log)
70 return;
71 time( &timeOfDay);
72 localTime = localtime( &timeOfDay);
73 fprintf( log, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
74 localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday,
75 localTime->tm_hour, localTime->tm_min, localTime->tm_sec, msg);
76 fclose( log);
79 // dump comand line arguments
80 void dumpArgs( int argc, char *argv[] )
82 int i;
84 logMessage( "Start of command line arguments dump:");
85 for( i=0; i<argc; i++)
86 logMessage( argv[i]);
89 /*
90 * The intended use of this tool is to pass the argument to
91 * the default URL exe.
93 int main(int argc, char *argv[] )
95 APIRET rc;
96 RESULTCODES result = {0};
97 char szAppFromINI[_MAX_PATH];
98 char szDirFromINI[_MAX_PATH];
99 char szCmdLine[1024];
100 char szFail[ _MAX_PATH];
101 ULONG ulSID;
102 PID pid;
104 // check parameters
105 if (argc != 2)
107 logMessage( "Usage: open-url <url>");
108 dumpArgs( argc, argv);
109 return -1;
112 // check configuration
113 rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
114 "DefaultBrowserExe", "",
115 szAppFromINI, sizeof(szAppFromINI));
116 rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
117 "DefaultWorkingDir", "",
118 szDirFromINI, sizeof(szDirFromINI));
119 if (*szAppFromINI == 0 || *szDirFromINI == 0)
121 logMessage( "Unable to find default url handler in USER.INI; exiting.");
122 dumpArgs( argc, argv);
123 return -1;
126 // get default parameter list
127 rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
128 "DefaultParameters", "",
129 szCmdLine, sizeof(szCmdLine));
130 strcat( szCmdLine, " ");
131 strcat( szCmdLine, argv[1]);
133 // change default directory
134 _chdir( szDirFromINI);
136 // start default handler
137 STARTDATA SData;
138 CHAR szObjBuf[CCHMAXPATH];
140 SData.Length = sizeof(STARTDATA);
141 SData.Related = SSF_RELATED_INDEPENDENT;
142 SData.FgBg = (1) ? SSF_FGBG_FORE : SSF_FGBG_BACK;
143 SData.TraceOpt = SSF_TRACEOPT_NONE;
145 SData.PgmTitle = (PSZ)szAppFromINI;
147 SData.PgmName = (PSZ)szAppFromINI;
148 SData.PgmInputs = (PSZ)szCmdLine;
150 SData.TermQ = NULL;
151 SData.Environment = 0;
152 SData.InheritOpt = SSF_INHERTOPT_PARENT;
153 SData.SessionType = SSF_TYPE_PM;
154 SData.IconFile = 0;
155 SData.PgmHandle = 0;
157 SData.PgmControl = SSF_CONTROL_VISIBLE;
159 SData.InitXPos = 30;
160 SData.InitYPos = 40;
161 SData.InitXSize = 200;
162 SData.InitYSize = 140;
163 SData.Reserved = 0;
164 SData.ObjectBuffer = szFail;
165 SData.ObjectBuffLen = (ULONG)sizeof(szFail);
167 rc = DosStartSession( &SData, &ulSID, &pid);
168 // show error dialog in case of problems
169 if (rc != NO_ERROR && rc != ERROR_SMG_START_IN_BACKGROUND) {
170 char szMessage[ _MAX_PATH*2];
171 sprintf( szMessage, "Execution failed! rc: %d, failing module:%s", rc, szFail);
172 logMessage( szMessage);
173 dumpArgs( argc, argv);
174 return -1;
177 // ok
178 return 0;