2004-03-16 04:23:43 +01:00
|
|
|
%{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2003 Mike McCormack for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2005-10-29 13:08:05 +02:00
|
|
|
#include "winuser.h"
|
2004-03-16 04:23:43 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
2004-07-10 00:25:34 +02:00
|
|
|
#include "msipriv.h"
|
2005-10-29 13:08:05 +02:00
|
|
|
#include "action.h"
|
2004-03-16 04:23:43 +01:00
|
|
|
|
|
|
|
#define YYLEX_PARAM info
|
|
|
|
#define YYPARSE_PARAM info
|
|
|
|
|
2005-05-29 22:08:12 +02:00
|
|
|
static int COND_error(const char *str);
|
2004-03-16 04:23:43 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
|
|
|
typedef struct tag_yyinput
|
|
|
|
{
|
2004-07-10 00:25:34 +02:00
|
|
|
MSIPACKAGE *package;
|
2004-03-16 04:23:43 +01:00
|
|
|
LPCWSTR str;
|
|
|
|
INT n;
|
|
|
|
MSICONDITION result;
|
|
|
|
} COND_input;
|
|
|
|
|
2004-06-29 01:57:11 +02:00
|
|
|
struct cond_str {
|
|
|
|
LPCWSTR data;
|
|
|
|
INT len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LPWSTR COND_GetString( struct cond_str *str );
|
2004-07-29 04:36:06 +02:00
|
|
|
static LPWSTR COND_GetLiteral( struct cond_str *str );
|
2004-03-16 04:23:43 +01:00
|
|
|
static int COND_lex( void *COND_lval, COND_input *info);
|
2005-10-29 13:08:05 +02:00
|
|
|
static const WCHAR szEmpty[] = { 0 };
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
static INT compare_int( INT a, INT operator, INT b );
|
|
|
|
static INT compare_string( LPCWSTR a, INT operator, LPCWSTR b );
|
|
|
|
|
|
|
|
static INT compare_and_free_strings( LPWSTR a, INT op, LPWSTR b )
|
|
|
|
{
|
|
|
|
INT r;
|
|
|
|
|
|
|
|
r = compare_string( a, op, b );
|
|
|
|
msi_free( a );
|
|
|
|
msi_free( b );
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-11-14 12:24:14 +01:00
|
|
|
static BOOL num_from_prop( LPCWSTR p, INT *val )
|
|
|
|
{
|
|
|
|
INT ret = 0, sign = 1;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return FALSE;
|
|
|
|
if (*p == '-')
|
|
|
|
{
|
|
|
|
sign = -1;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (!*p)
|
|
|
|
return FALSE;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if( *p < '0' || *p > '9' )
|
|
|
|
return FALSE;
|
|
|
|
ret = ret*10 + (*p - '0');
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*val = ret*sign;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
%}
|
|
|
|
|
|
|
|
%pure-parser
|
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
2004-06-29 01:57:11 +02:00
|
|
|
struct cond_str str;
|
2004-03-16 04:23:43 +01:00
|
|
|
LPWSTR string;
|
|
|
|
INT value;
|
|
|
|
}
|
|
|
|
|
|
|
|
%token COND_SPACE COND_EOF COND_SPACE
|
2005-10-29 13:08:05 +02:00
|
|
|
%token COND_OR COND_AND COND_NOT COND_XOR COND_IMP COND_EQV
|
|
|
|
%token COND_LT COND_GT COND_EQ COND_NE COND_GE COND_LE
|
|
|
|
%token COND_ILT COND_IGT COND_IEQ COND_INE COND_IGE COND_ILE
|
|
|
|
%token COND_LPAR COND_RPAR COND_TILDA COND_SS COND_ISS
|
|
|
|
%token COND_ILHS COND_IRHS COND_LHS COND_RHS
|
2004-03-16 04:23:43 +01:00
|
|
|
%token COND_PERCENT COND_DOLLARS COND_QUESTION COND_AMPER COND_EXCLAM
|
2004-07-29 04:36:06 +02:00
|
|
|
%token <str> COND_IDENT <str> COND_NUMBER <str> COND_LITER
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
%nonassoc COND_ERROR COND_EOF
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2004-06-28 22:34:35 +02:00
|
|
|
%type <value> expression boolean_term boolean_factor
|
2005-10-29 13:08:05 +02:00
|
|
|
%type <value> value_i integer operator
|
|
|
|
%type <string> identifier symbol_s value_s literal
|
2004-03-16 04:23:43 +01:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
condition:
|
2005-10-29 13:08:05 +02:00
|
|
|
expression
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
|
|
|
cond->result = $1;
|
|
|
|
}
|
2005-10-28 12:41:05 +02:00
|
|
|
| /* empty */
|
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
|
|
|
cond->result = MSICONDITION_NONE;
|
|
|
|
}
|
2004-03-16 04:23:43 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
expression:
|
|
|
|
boolean_term
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| expression COND_OR boolean_term
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
$$ = $1 || $3;
|
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| expression COND_IMP boolean_term
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = !$1 || $3;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| expression COND_XOR boolean_term
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = ( $1 || $3 ) && !( $1 && $3 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| expression COND_EQV boolean_term
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = ( $1 && $3 ) || ( !$1 && !$3 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
boolean_term:
|
|
|
|
boolean_factor
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| boolean_term COND_AND boolean_factor
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = $1 && $3;
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
boolean_factor:
|
|
|
|
COND_NOT boolean_factor
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = $2 ? 0 : 1;
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| value_i
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = $1 ? 1 : 0;
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| value_s
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = ($1 && $1[0]) ? 1 : 0;
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| value_i operator value_i
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = compare_int( $1, $2, $3 );
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| symbol_s operator value_i
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-11-14 12:24:14 +01:00
|
|
|
int num;
|
2005-11-14 13:29:10 +01:00
|
|
|
if (num_from_prop( $1, &num ))
|
|
|
|
$$ = compare_int( num, $2, $3 );
|
|
|
|
else
|
|
|
|
$$ = ($2 == COND_NE || $2 == COND_INE );
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| value_i operator symbol_s
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-11-14 12:24:14 +01:00
|
|
|
int num;
|
2005-11-14 13:29:10 +01:00
|
|
|
if (num_from_prop( $3, &num ))
|
|
|
|
$$ = compare_int( $1, $2, num );
|
|
|
|
else
|
|
|
|
$$ = ($2 == COND_NE || $2 == COND_INE );
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| symbol_s operator symbol_s
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = compare_and_free_strings( $1, $2, $3 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| symbol_s operator literal
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = compare_and_free_strings( $1, $2, $3 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| literal operator symbol_s
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = compare_and_free_strings( $1, $2, $3 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| literal operator literal
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = compare_and_free_strings( $1, $2, $3 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| literal operator value_i
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2004-06-28 22:34:35 +02:00
|
|
|
$$ = 0;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| value_i operator literal
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2004-06-28 22:34:35 +02:00
|
|
|
$$ = 0;
|
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
| COND_LPAR expression COND_RPAR
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = $2;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
operator:
|
2004-06-28 22:34:35 +02:00
|
|
|
/* common functions */
|
2005-11-03 10:55:30 +01:00
|
|
|
COND_EQ { $$ = COND_EQ; }
|
|
|
|
| COND_NE { $$ = COND_NE; }
|
|
|
|
| COND_LT { $$ = COND_LT; }
|
|
|
|
| COND_GT { $$ = COND_GT; }
|
|
|
|
| COND_LE { $$ = COND_LE; }
|
|
|
|
| COND_GE { $$ = COND_GE; }
|
|
|
|
| COND_SS { $$ = COND_SS; }
|
|
|
|
| COND_IEQ { $$ = COND_IEQ; }
|
|
|
|
| COND_INE { $$ = COND_INE; }
|
|
|
|
| COND_ILT { $$ = COND_ILT; }
|
|
|
|
| COND_IGT { $$ = COND_IGT; }
|
|
|
|
| COND_ILE { $$ = COND_ILE; }
|
|
|
|
| COND_IGE { $$ = COND_IGE; }
|
|
|
|
| COND_ISS { $$ = COND_ISS; }
|
|
|
|
| COND_LHS { $$ = COND_LHS; }
|
|
|
|
| COND_RHS { $$ = COND_RHS; }
|
|
|
|
| COND_ILHS { $$ = COND_ILHS; }
|
|
|
|
| COND_IRHS { $$ = COND_IRHS; }
|
2004-03-16 04:23:43 +01:00
|
|
|
;
|
|
|
|
|
2004-06-28 22:34:35 +02:00
|
|
|
value_s:
|
2005-10-29 13:08:05 +02:00
|
|
|
symbol_s
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| literal
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
literal:
|
2004-07-29 04:36:06 +02:00
|
|
|
COND_LITER
|
|
|
|
{
|
|
|
|
$$ = COND_GetLiteral(&$1);
|
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
2004-06-28 22:34:35 +02:00
|
|
|
;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
value_i:
|
|
|
|
integer
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| COND_DOLLARS identifier
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
|
|
|
INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
MSI_GetComponentStateW(cond->package, $2, &install, &action );
|
2004-03-16 04:23:43 +01:00
|
|
|
$$ = action;
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( $2 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
| COND_QUESTION identifier
|
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
|
|
|
INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
MSI_GetComponentStateW(cond->package, $2, &install, &action );
|
2004-03-16 04:23:43 +01:00
|
|
|
$$ = install;
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( $2 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
| COND_AMPER identifier
|
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
|
|
|
INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
MSI_GetFeatureStateW(cond->package, $2, &install, &action );
|
2004-03-16 04:23:43 +01:00
|
|
|
$$ = action;
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( $2 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
| COND_EXCLAM identifier
|
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
|
|
|
INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
MSI_GetFeatureStateW(cond->package, $2, &install, &action );
|
2004-03-16 04:23:43 +01:00
|
|
|
$$ = install;
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( $2 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-06-28 22:34:35 +02:00
|
|
|
symbol_s:
|
|
|
|
identifier
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
COND_input* cond = (COND_input*) info;
|
2004-06-28 22:34:35 +02:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = msi_dup_property( cond->package, $1 );
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( $1 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2004-06-28 22:34:35 +02:00
|
|
|
| COND_PERCENT identifier
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
UINT len = GetEnvironmentVariableW( $2, NULL, 0 );
|
2005-10-29 13:08:05 +02:00
|
|
|
$$ = NULL;
|
|
|
|
if (len++)
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
$$ = msi_alloc( len*sizeof (WCHAR) );
|
2005-10-29 13:08:05 +02:00
|
|
|
GetEnvironmentVariableW( $2, $$, len );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( $2 );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-06-28 22:34:35 +02:00
|
|
|
identifier:
|
|
|
|
COND_IDENT
|
|
|
|
{
|
2004-06-29 01:57:11 +02:00
|
|
|
$$ = COND_GetString(&$1);
|
2004-06-28 22:34:35 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
integer:
|
|
|
|
COND_NUMBER
|
|
|
|
{
|
2004-06-29 01:57:11 +02:00
|
|
|
LPWSTR szNum = COND_GetString(&$1);
|
2004-03-16 04:23:43 +01:00
|
|
|
if( !szNum )
|
|
|
|
YYABORT;
|
|
|
|
$$ = atoiW( szNum );
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( szNum );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
2004-07-06 20:50:02 +02:00
|
|
|
static int COND_IsAlpha( WCHAR x )
|
|
|
|
{
|
|
|
|
return( ( ( x >= 'A' ) && ( x <= 'Z' ) ) ||
|
|
|
|
( ( x >= 'a' ) && ( x <= 'z' ) ) ||
|
|
|
|
( ( x == '_' ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int COND_IsNumber( WCHAR x )
|
|
|
|
{
|
2004-07-19 23:49:15 +02:00
|
|
|
return( (( x >= '0' ) && ( x <= '9' )) || (x =='-') || (x =='.') );
|
2004-07-06 20:50:02 +02:00
|
|
|
}
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
static WCHAR *strstriW( const WCHAR *str, const WCHAR *sub )
|
|
|
|
{
|
|
|
|
LPWSTR strlower, sublower, r;
|
|
|
|
strlower = CharLowerW( strdupW( str ) );
|
|
|
|
sublower = CharLowerW( strdupW( sub ) );
|
|
|
|
r = strstrW( strlower, sublower );
|
|
|
|
if (r)
|
|
|
|
r = (LPWSTR)str + (r - strlower);
|
|
|
|
msi_free( strlower );
|
|
|
|
msi_free( sublower );
|
|
|
|
return r;
|
|
|
|
}
|
2004-07-06 20:50:02 +02:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
static INT compare_string( LPCWSTR a, INT operator, LPCWSTR b )
|
|
|
|
{
|
2005-11-02 20:58:01 +01:00
|
|
|
/* null and empty string are equivalent */
|
|
|
|
if (!a) a = szEmpty;
|
|
|
|
if (!b) b = szEmpty;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
/* a or b may be NULL */
|
|
|
|
switch (operator)
|
|
|
|
{
|
|
|
|
case COND_LT:
|
|
|
|
return -1 == lstrcmpW( a, b );
|
|
|
|
case COND_GT:
|
|
|
|
return 1 == lstrcmpW( a, b );
|
|
|
|
case COND_EQ:
|
|
|
|
return 0 == lstrcmpW( a, b );
|
|
|
|
case COND_NE:
|
|
|
|
return 0 != lstrcmpW( a, b );
|
|
|
|
case COND_GE:
|
|
|
|
return -1 != lstrcmpW( a, b );
|
|
|
|
case COND_LE:
|
|
|
|
return 1 != lstrcmpW( a, b );
|
|
|
|
case COND_SS: /* substring */
|
2005-11-02 20:58:01 +01:00
|
|
|
return strstrW( a, b ) ? 1 : 0;
|
2005-10-29 13:08:05 +02:00
|
|
|
case COND_ILT:
|
|
|
|
return -1 == lstrcmpiW( a, b );
|
|
|
|
case COND_IGT:
|
|
|
|
return 1 == lstrcmpiW( a, b );
|
|
|
|
case COND_IEQ:
|
|
|
|
return 0 == lstrcmpiW( a, b );
|
|
|
|
case COND_INE:
|
|
|
|
return 0 != lstrcmpiW( a, b );
|
|
|
|
case COND_IGE:
|
|
|
|
return -1 != lstrcmpiW( a, b );
|
|
|
|
case COND_ILE:
|
|
|
|
return 1 != lstrcmpiW( a, b );
|
|
|
|
case COND_ISS:
|
2005-11-02 20:58:01 +01:00
|
|
|
return strstriW( a, b ) ? 1 : 0;
|
2005-10-29 13:08:05 +02:00
|
|
|
case COND_LHS:
|
|
|
|
case COND_RHS:
|
|
|
|
case COND_ILHS:
|
|
|
|
case COND_IRHS:
|
|
|
|
ERR("unimplemented string comparison\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("invalid integer operator\n");
|
2004-06-28 22:34:35 +02:00
|
|
|
return 0;
|
2005-10-29 13:08:05 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
static INT compare_int( INT a, INT operator, INT b )
|
|
|
|
{
|
|
|
|
switch (operator)
|
|
|
|
{
|
|
|
|
case COND_LT:
|
|
|
|
case COND_ILT:
|
|
|
|
return a < b;
|
|
|
|
case COND_GT:
|
|
|
|
case COND_IGT:
|
|
|
|
return a > b;
|
|
|
|
case COND_EQ:
|
|
|
|
case COND_IEQ:
|
|
|
|
return a == b;
|
|
|
|
case COND_NE:
|
|
|
|
case COND_INE:
|
|
|
|
return a != b;
|
|
|
|
case COND_GE:
|
|
|
|
case COND_IGE:
|
|
|
|
return a >= b;
|
|
|
|
case COND_LE:
|
|
|
|
case COND_ILE:
|
|
|
|
return a >= b;
|
|
|
|
case COND_SS:
|
|
|
|
case COND_ISS:
|
|
|
|
return ( a & b ) ? 1 : 0;
|
|
|
|
case COND_RHS:
|
|
|
|
return ( ( a & 0xffff ) == b ) ? 1 : 0;
|
|
|
|
case COND_LHS:
|
|
|
|
return ( ( (a>>16) & 0xffff ) == b ) ? 1 : 0;
|
|
|
|
default:
|
|
|
|
ERR("invalid integer operator\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2004-03-16 04:23:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
static int COND_IsIdent( WCHAR x )
|
|
|
|
{
|
2004-06-28 22:34:35 +02:00
|
|
|
return( COND_IsAlpha( x ) || COND_IsNumber( x ) || ( x == '_' )
|
|
|
|
|| ( x == '#' ) || (x == '.') );
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
static int COND_GetOperator( COND_input *cond )
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
const WCHAR str[4];
|
|
|
|
int id;
|
|
|
|
} table[] = {
|
|
|
|
{ {'~','=',0}, COND_IEQ },
|
|
|
|
{ {'~','>','=',0}, COND_ILE },
|
|
|
|
{ {'~','>','<',0}, COND_ISS },
|
|
|
|
{ {'~','>','>',0}, COND_IRHS },
|
|
|
|
{ {'~','>',0}, COND_ILT },
|
|
|
|
{ {'~','<','>',0}, COND_INE },
|
|
|
|
{ {'~','<','=',0}, COND_IGE },
|
|
|
|
{ {'~','<','<',0}, COND_ILHS },
|
|
|
|
{ {'~','<',0}, COND_IGT },
|
|
|
|
{ {'>','=',0}, COND_GE },
|
|
|
|
{ {'>','<',0}, COND_SS },
|
|
|
|
{ {'>','>',0}, COND_LHS },
|
|
|
|
{ {'>',0}, COND_GT },
|
|
|
|
{ {'<','>',0}, COND_NE },
|
|
|
|
{ {'<','=',0}, COND_LE },
|
|
|
|
{ {'<','<',0}, COND_RHS },
|
|
|
|
{ {'<',0}, COND_LT },
|
|
|
|
{ {0}, 0 }
|
|
|
|
};
|
|
|
|
LPCWSTR p = &cond->str[cond->n];
|
|
|
|
int i = 0, len;
|
|
|
|
|
|
|
|
while ( 1 )
|
|
|
|
{
|
|
|
|
len = lstrlenW( table[i].str );
|
|
|
|
if ( !len || 0 == strncmpW( table[i].str, p, len ) )
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
cond->n += len;
|
|
|
|
return table[i].id;
|
|
|
|
}
|
|
|
|
|
2004-06-29 01:57:11 +02:00
|
|
|
static int COND_GetOne( struct cond_str *str, COND_input *cond )
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2004-06-29 01:57:11 +02:00
|
|
|
int rc, len = 1;
|
2005-10-29 13:08:05 +02:00
|
|
|
WCHAR ch;
|
2004-06-28 22:34:35 +02:00
|
|
|
|
2004-06-29 01:57:11 +02:00
|
|
|
str->data = &cond->str[cond->n];
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2004-06-29 01:57:11 +02:00
|
|
|
ch = str->data[0];
|
2005-10-29 13:08:05 +02:00
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
switch( ch )
|
|
|
|
{
|
2004-06-29 01:57:11 +02:00
|
|
|
case 0: return 0;
|
2004-06-28 22:34:35 +02:00
|
|
|
case '(': rc = COND_LPAR; break;
|
|
|
|
case ')': rc = COND_RPAR; break;
|
|
|
|
case '&': rc = COND_AMPER; break;
|
|
|
|
case '!': rc = COND_EXCLAM; break;
|
|
|
|
case '$': rc = COND_DOLLARS; break;
|
|
|
|
case '?': rc = COND_QUESTION; break;
|
|
|
|
case '%': rc = COND_PERCENT; break;
|
|
|
|
case ' ': rc = COND_SPACE; break;
|
|
|
|
case '=': rc = COND_EQ; break;
|
2005-10-29 13:08:05 +02:00
|
|
|
break;
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
case '~':
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
rc = COND_GetOperator( cond );
|
|
|
|
if (!rc)
|
|
|
|
rc = COND_ERROR;
|
|
|
|
return rc;
|
|
|
|
default:
|
|
|
|
rc = 0;
|
|
|
|
}
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
if ( rc )
|
|
|
|
{
|
|
|
|
cond->n += len;
|
|
|
|
return rc;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
2004-06-29 01:57:11 +02:00
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
if (ch == '"' )
|
2004-06-29 01:57:11 +02:00
|
|
|
{
|
2005-10-29 13:08:05 +02:00
|
|
|
LPCWSTR p = strchrW( str->data + 1, '"' );
|
|
|
|
if (!p)
|
|
|
|
return COND_ERROR;
|
|
|
|
len = p - str->data + 1;
|
|
|
|
rc = COND_LITER;
|
|
|
|
}
|
|
|
|
else if( COND_IsAlpha( ch ) )
|
|
|
|
{
|
|
|
|
static const WCHAR szNot[] = {'N','O','T',0};
|
|
|
|
static const WCHAR szAnd[] = {'A','N','D',0};
|
|
|
|
static const WCHAR szXor[] = {'X','O','R',0};
|
|
|
|
static const WCHAR szEqv[] = {'E','Q','V',0};
|
|
|
|
static const WCHAR szImp[] = {'I','M','P',0};
|
|
|
|
static const WCHAR szOr[] = {'O','R',0};
|
|
|
|
|
|
|
|
while( COND_IsIdent( str->data[len] ) )
|
|
|
|
len++;
|
|
|
|
rc = COND_IDENT;
|
|
|
|
|
|
|
|
if ( len == 3 )
|
|
|
|
{
|
|
|
|
if ( !strncmpiW( str->data, szNot, len ) )
|
|
|
|
rc = COND_NOT;
|
|
|
|
else if( !strncmpiW( str->data, szAnd, len ) )
|
|
|
|
rc = COND_AND;
|
|
|
|
else if( !strncmpiW( str->data, szXor, len ) )
|
|
|
|
rc = COND_XOR;
|
|
|
|
else if( !strncmpiW( str->data, szEqv, len ) )
|
|
|
|
rc = COND_EQV;
|
|
|
|
else if( !strncmpiW( str->data, szImp, len ) )
|
|
|
|
rc = COND_IMP;
|
|
|
|
}
|
|
|
|
else if( (len == 2) && !strncmpiW( str->data, szOr, len ) )
|
2004-06-29 01:57:11 +02:00
|
|
|
rc = COND_OR;
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2005-10-29 13:08:05 +02:00
|
|
|
else if( COND_IsNumber( ch ) )
|
|
|
|
{
|
|
|
|
while( COND_IsNumber( str->data[len] ) )
|
|
|
|
len++;
|
|
|
|
rc = COND_NUMBER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Got unknown character %c(%x)\n",ch,ch);
|
|
|
|
return COND_ERROR;
|
|
|
|
}
|
2004-06-29 01:57:11 +02:00
|
|
|
|
|
|
|
cond->n += len;
|
|
|
|
str->len = len;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int COND_lex( void *COND_lval, COND_input *cond )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct cond_str *str = COND_lval;
|
|
|
|
|
|
|
|
do {
|
|
|
|
rc = COND_GetOne( str, cond );
|
|
|
|
} while (rc == COND_SPACE);
|
2004-06-28 22:34:35 +02:00
|
|
|
|
|
|
|
return rc;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
|
2004-06-29 01:57:11 +02:00
|
|
|
static LPWSTR COND_GetString( struct cond_str *str )
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2004-06-29 01:57:11 +02:00
|
|
|
LPWSTR ret;
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
ret = msi_alloc( (str->len+1) * sizeof (WCHAR) );
|
2004-06-29 01:57:11 +02:00
|
|
|
if( ret )
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2005-04-18 12:30:55 +02:00
|
|
|
memcpy( ret, str->data, str->len * sizeof(WCHAR));
|
2004-06-29 01:57:11 +02:00
|
|
|
ret[str->len]=0;
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
2004-06-29 01:57:11 +02:00
|
|
|
TRACE("Got identifier %s\n",debugstr_w(ret));
|
|
|
|
return ret;
|
2004-03-16 04:23:43 +01:00
|
|
|
}
|
|
|
|
|
2004-07-29 04:36:06 +02:00
|
|
|
static LPWSTR COND_GetLiteral( struct cond_str *str )
|
|
|
|
{
|
|
|
|
LPWSTR ret;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
ret = msi_alloc( (str->len-1) * sizeof (WCHAR) );
|
2004-07-29 04:36:06 +02:00
|
|
|
if( ret )
|
|
|
|
{
|
|
|
|
memcpy( ret, str->data+1, (str->len-2) * sizeof(WCHAR) );
|
|
|
|
ret[str->len - 2]=0;
|
|
|
|
}
|
|
|
|
TRACE("Got literal %s\n",debugstr_w(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-05-29 22:08:12 +02:00
|
|
|
static int COND_error(const char *str)
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
2005-10-28 12:41:05 +02:00
|
|
|
TRACE("%s\n", str );
|
2004-03-16 04:23:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
MSICONDITION MSI_EvaluateConditionW( MSIPACKAGE *package, LPCWSTR szCondition )
|
2004-03-16 04:23:43 +01:00
|
|
|
{
|
|
|
|
COND_input cond;
|
|
|
|
MSICONDITION r;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
TRACE("%s\n", debugstr_w( szCondition ) );
|
|
|
|
|
2005-10-28 12:41:05 +02:00
|
|
|
if ( szCondition == NULL )
|
|
|
|
return MSICONDITION_NONE;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
cond.package = package;
|
2004-03-16 04:23:43 +01:00
|
|
|
cond.str = szCondition;
|
|
|
|
cond.n = 0;
|
2005-10-28 12:41:05 +02:00
|
|
|
cond.result = MSICONDITION_ERROR;
|
2004-03-16 04:23:43 +01:00
|
|
|
|
2005-10-28 12:41:05 +02:00
|
|
|
if ( !COND_parse( &cond ) )
|
2004-03-16 04:23:43 +01:00
|
|
|
r = cond.result;
|
|
|
|
else
|
|
|
|
r = MSICONDITION_ERROR;
|
|
|
|
|
2005-10-29 13:08:05 +02:00
|
|
|
TRACE("%i <- %s\n", r, debugstr_w(szCondition));
|
2004-03-16 04:23:43 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
MSICONDITION WINAPI MsiEvaluateConditionW( MSIHANDLE hInstall, LPCWSTR szCondition )
|
|
|
|
{
|
|
|
|
MSIPACKAGE *package;
|
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
|
|
|
|
if( !package)
|
2005-10-28 12:41:05 +02:00
|
|
|
return MSICONDITION_ERROR;
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_EvaluateConditionW( package, szCondition );
|
|
|
|
msiobj_release( &package->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
MSICONDITION WINAPI MsiEvaluateConditionA( MSIHANDLE hInstall, LPCSTR szCondition )
|
|
|
|
{
|
|
|
|
LPWSTR szwCond = NULL;
|
|
|
|
MSICONDITION r;
|
|
|
|
|
2005-10-28 12:41:05 +02:00
|
|
|
szwCond = strdupAtoW( szCondition );
|
|
|
|
if( szCondition && !szwCond )
|
|
|
|
return MSICONDITION_ERROR;
|
2004-03-16 04:23:43 +01:00
|
|
|
|
|
|
|
r = MsiEvaluateConditionW( hInstall, szwCond );
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( szwCond );
|
2004-03-16 04:23:43 +01:00
|
|
|
return r;
|
|
|
|
}
|