2005-02-23 21:31:07 +01:00
|
|
|
/*
|
|
|
|
* IDL Compiler
|
|
|
|
*
|
2006-03-23 10:33:08 +01:00
|
|
|
* Copyright 2005-2006 Eric Kohl
|
2005-02-23 21:31:07 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-02-23 21:31:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-02-14 16:35:46 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2005-02-23 21:31:07 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
|
|
|
|
|
|
|
#include "widltypes.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
#include "typegen.h"
|
2008-04-22 12:36:38 +02:00
|
|
|
#include "expr.h"
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
static FILE* client;
|
|
|
|
static int indent = 0;
|
|
|
|
|
2009-02-06 14:31:29 +01:00
|
|
|
static void print_client( const char *format, ... ) __attribute__((format (printf, 1, 2)));
|
2007-06-15 03:29:33 +02:00
|
|
|
static void print_client( const char *format, ... )
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2007-06-15 03:29:33 +02:00
|
|
|
print(client, indent, format, va);
|
2005-02-23 21:31:07 +01:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
static void check_pointers(const var_t *func)
|
2006-03-24 17:40:17 +01:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2006-03-24 17:40:17 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (!type_get_function_args(func->type))
|
2006-03-29 12:42:29 +02:00
|
|
|
return;
|
2006-03-24 17:40:17 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
|
2006-03-24 17:40:17 +01:00
|
|
|
{
|
2006-08-29 23:27:27 +02:00
|
|
|
if (is_var_ptr(var) && cant_be_null(var))
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2006-08-12 02:33:40 +02:00
|
|
|
print_client("if (!%s)\n", var->name);
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
|
|
|
print_client("RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
|
|
|
|
indent--;
|
|
|
|
print_client("}\n\n");
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
2006-03-24 17:40:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt;
|
2006-02-07 12:31:43 +01:00
|
|
|
const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2005-02-23 21:31:07 +01:00
|
|
|
int method_count = 0;
|
|
|
|
|
2007-05-03 14:25:58 +02:00
|
|
|
if (!implicit_handle)
|
|
|
|
print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name);
|
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
const var_t *func = stmt->u.var;
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t* explicit_handle_var;
|
2008-03-27 15:03:17 +01:00
|
|
|
const var_t* explicit_generic_handle_var = NULL;
|
2008-03-26 14:47:30 +01:00
|
|
|
const var_t* context_handle_var = NULL;
|
2008-01-30 23:29:39 +01:00
|
|
|
int has_full_pointer = is_full_pointer_function(func);
|
2009-01-06 00:33:27 +01:00
|
|
|
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
|
|
|
|
const var_list_t *args = type_get_function_args(func->type);
|
2005-12-12 12:14:03 +01:00
|
|
|
|
|
|
|
/* check for a defined binding handle */
|
|
|
|
explicit_handle_var = get_explicit_handle_var(func);
|
2008-03-26 14:47:30 +01:00
|
|
|
if (!explicit_handle_var)
|
2008-03-27 15:03:17 +01:00
|
|
|
{
|
|
|
|
explicit_generic_handle_var = get_explicit_generic_handle_var(func);
|
|
|
|
if (!explicit_generic_handle_var)
|
2008-04-20 23:15:24 +02:00
|
|
|
context_handle_var = get_context_handle_var(func);
|
2005-12-12 12:14:03 +01:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) );
|
2008-09-15 18:03:56 +02:00
|
|
|
indent++;
|
|
|
|
print_client( "__DECL_EXCEPTION_FRAME\n" );
|
|
|
|
print_client("MIDL_STUB_MESSAGE _StubMsg;\n");
|
|
|
|
if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var)
|
|
|
|
{
|
|
|
|
if (!implicit_handle && explicit_generic_handle_var)
|
|
|
|
print_client("%s %s;\n",
|
|
|
|
get_explicit_generic_handle_type(explicit_generic_handle_var)->name,
|
|
|
|
explicit_generic_handle_var->name );
|
|
|
|
print_client("RPC_BINDING_HANDLE _Handle;\n");
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)) &&
|
|
|
|
decl_indirect(type_function_get_rettype(func->type)))
|
2008-09-15 18:03:56 +02:00
|
|
|
{
|
|
|
|
print_client("void *_p_%s;\n", "_RetVal" );
|
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_client( "};\n\n" );
|
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
print_client( "static void __finally_%s%s(", prefix_client, get_name(func) );
|
|
|
|
print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(func) );
|
2008-09-15 18:03:56 +02:00
|
|
|
indent++;
|
|
|
|
|
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_free(client, indent, func);
|
|
|
|
|
2008-09-15 19:40:51 +02:00
|
|
|
print_client("NdrFreeBuffer(&__frame->_StubMsg);\n");
|
2008-09-15 18:03:56 +02:00
|
|
|
|
|
|
|
if (!implicit_handle && explicit_generic_handle_var)
|
|
|
|
{
|
|
|
|
fprintf(client, "\n");
|
|
|
|
print_client("if (__frame->_Handle)\n");
|
|
|
|
indent++;
|
|
|
|
print_client("%s_unbind(__frame->%s, __frame->_Handle);\n",
|
|
|
|
get_explicit_generic_handle_type(explicit_generic_handle_var)->name,
|
|
|
|
explicit_generic_handle_var->name);
|
|
|
|
indent--;
|
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_client( "}\n\n" );
|
|
|
|
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(client, type_function_get_rettype(func->type));
|
|
|
|
if (needs_space_after(type_function_get_rettype(func->type)))
|
2007-06-06 03:50:31 +02:00
|
|
|
fprintf(client, " ");
|
2008-04-11 12:02:01 +02:00
|
|
|
if (callconv) fprintf(client, "%s ", callconv);
|
2009-01-06 00:33:27 +01:00
|
|
|
fprintf(client, "%s%s(\n", prefix_client, get_name(func));
|
2005-02-23 21:31:07 +01:00
|
|
|
indent++;
|
2009-01-06 00:33:27 +01:00
|
|
|
if (args)
|
|
|
|
write_args(client, args, iface->name, 0, TRUE);
|
2005-02-23 21:31:07 +01:00
|
|
|
else
|
|
|
|
print_client("void");
|
|
|
|
fprintf(client, ")\n");
|
|
|
|
indent--;
|
|
|
|
|
|
|
|
/* write the functions body */
|
|
|
|
fprintf(client, "{\n");
|
|
|
|
indent++;
|
2009-01-06 00:33:27 +01:00
|
|
|
print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
/* declare return value '_RetVal' */
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)))
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2009-02-06 14:31:29 +01:00
|
|
|
print_client("%s", "");
|
2009-01-06 00:35:24 +01:00
|
|
|
write_type_decl_left(client, type_function_get_rettype(func->type));
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, " _RetVal;\n");
|
|
|
|
}
|
2008-09-15 18:03:56 +02:00
|
|
|
print_client("RPC_MESSAGE _RpcMessage;\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2008-03-27 15:03:17 +01:00
|
|
|
if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var)
|
2008-09-15 18:03:56 +02:00
|
|
|
{
|
|
|
|
print_client( "__frame->_Handle = 0;\n" );
|
|
|
|
if (!implicit_handle && explicit_generic_handle_var)
|
|
|
|
print_client("__frame->%s = %s;\n",
|
|
|
|
explicit_generic_handle_var->name, explicit_generic_handle_var->name );
|
|
|
|
}
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)) &&
|
|
|
|
decl_indirect(type_function_get_rettype(func->type)))
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2008-09-15 18:03:56 +02:00
|
|
|
print_client("__frame->_p_%s = &%s;\n",
|
2007-12-10 15:24:11 +01:00
|
|
|
"_RetVal", "_RetVal");
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(func) );
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2008-01-30 23:29:39 +01:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_init(client, indent, func, FALSE);
|
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
/* check pointers */
|
|
|
|
check_pointers(func);
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("RpcTryFinally\n");
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
|
|
|
|
2008-09-15 19:40:51 +02:00
|
|
|
print_client("NdrClientInitializeNew(&_RpcMessage, &__frame->_StubMsg, &%s_StubDesc, %d);\n",
|
|
|
|
iface->name, method_count);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2009-01-06 00:33:27 +01:00
|
|
|
if (is_attr(func->attrs, ATTR_IDEMPOTENT) || is_attr(func->attrs, ATTR_BROADCAST))
|
2008-04-14 11:59:55 +02:00
|
|
|
{
|
|
|
|
print_client("_RpcMessage.RpcFlags = ( RPC_NCA_FLAGS_DEFAULT ");
|
2009-01-06 00:33:27 +01:00
|
|
|
if (is_attr(func->attrs, ATTR_IDEMPOTENT))
|
2008-04-14 11:59:55 +02:00
|
|
|
fprintf(client, "| RPC_NCA_FLAGS_IDEMPOTENT ");
|
2009-01-06 00:33:27 +01:00
|
|
|
if (is_attr(func->attrs, ATTR_BROADCAST))
|
2008-04-14 11:59:55 +02:00
|
|
|
fprintf(client, "| RPC_NCA_FLAGS_BROADCAST ");
|
|
|
|
fprintf(client, ");\n\n");
|
|
|
|
}
|
|
|
|
|
2008-04-20 23:15:24 +02:00
|
|
|
if (explicit_handle_var)
|
2005-12-12 12:14:03 +01:00
|
|
|
{
|
2008-09-15 18:03:56 +02:00
|
|
|
print_client("__frame->_Handle = %s;\n", explicit_handle_var->name);
|
2005-12-12 12:14:03 +01:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
2008-03-27 15:03:17 +01:00
|
|
|
else if (explicit_generic_handle_var)
|
|
|
|
{
|
2008-09-15 18:03:56 +02:00
|
|
|
print_client("__frame->_Handle = %s_bind(%s);\n",
|
2008-03-27 15:03:17 +01:00
|
|
|
get_explicit_generic_handle_type(explicit_generic_handle_var)->name,
|
|
|
|
explicit_generic_handle_var->name);
|
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
2008-03-26 14:47:30 +01:00
|
|
|
else if (context_handle_var)
|
|
|
|
{
|
2008-03-27 15:03:23 +01:00
|
|
|
/* if the context_handle attribute appears in the chain of types
|
|
|
|
* without pointers being followed, then the context handle must
|
|
|
|
* be direct, otherwise it is a pointer */
|
|
|
|
int is_ch_ptr = is_aliaschain_attr(context_handle_var->type, ATTR_CONTEXTHANDLE) ? FALSE : TRUE;
|
|
|
|
print_client("if (%s%s != 0)\n", is_ch_ptr ? "*" : "", context_handle_var->name);
|
2008-03-26 14:47:30 +01:00
|
|
|
indent++;
|
2008-09-15 18:03:56 +02:00
|
|
|
print_client("__frame->_Handle = NDRCContextBinding(%s%s);\n",
|
|
|
|
is_ch_ptr ? "*" : "", context_handle_var->name);
|
2008-03-26 14:47:30 +01:00
|
|
|
indent--;
|
2008-08-26 21:05:17 +02:00
|
|
|
if (is_attr(context_handle_var->attrs, ATTR_IN) &&
|
|
|
|
!is_attr(context_handle_var->attrs, ATTR_OUT))
|
|
|
|
{
|
|
|
|
print_client("else\n");
|
|
|
|
indent++;
|
|
|
|
print_client("RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);\n");
|
|
|
|
indent--;
|
|
|
|
}
|
2008-03-27 15:03:17 +01:00
|
|
|
fprintf(client, "\n");
|
2008-03-26 14:47:30 +01:00
|
|
|
}
|
2008-04-20 23:15:24 +02:00
|
|
|
else if (implicit_handle)
|
|
|
|
{
|
2008-09-15 18:03:56 +02:00
|
|
|
print_client("__frame->_Handle = %s;\n", implicit_handle);
|
2008-04-20 23:15:24 +02:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
2005-12-08 12:48:44 +01:00
|
|
|
|
2008-09-15 16:46:01 +02:00
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_BUFFERSIZE);
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2008-09-15 19:40:51 +02:00
|
|
|
print_client("NdrGetBuffer(&__frame->_StubMsg, __frame->_StubMsg.BufferLength, ");
|
2008-03-27 15:03:17 +01:00
|
|
|
if (implicit_handle || explicit_handle_var || explicit_generic_handle_var || context_handle_var)
|
2008-09-15 19:40:51 +02:00
|
|
|
fprintf(client, "__frame->_Handle);\n\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
else
|
2008-09-15 19:40:51 +02:00
|
|
|
fprintf(client,"%s__MIDL_AutoBindHandle);\n\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
/* marshal arguments */
|
2008-09-15 16:46:01 +02:00
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_MARSHAL);
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2005-03-02 14:53:50 +01:00
|
|
|
/* send/receive message */
|
2005-02-23 21:31:07 +01:00
|
|
|
/* print_client("NdrNsSendReceive(\n"); */
|
2008-09-15 14:02:26 +02:00
|
|
|
/* print_client("(unsigned char *)__frame->_StubMsg.Buffer,\n"); */
|
2005-12-12 12:12:50 +01:00
|
|
|
/* print_client("(RPC_BINDING_HANDLE *) &%s__MIDL_AutoBindHandle);\n", iface->name); */
|
2008-09-15 19:40:51 +02:00
|
|
|
print_client("NdrSendReceive(&__frame->_StubMsg, __frame->_StubMsg.Buffer);\n\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2008-09-15 19:40:51 +02:00
|
|
|
print_client("__frame->_StubMsg.BufferStart = _RpcMessage.Buffer;\n");
|
2008-09-15 14:02:26 +02:00
|
|
|
print_client("__frame->_StubMsg.BufferEnd = __frame->_StubMsg.BufferStart + _RpcMessage.BufferLength;\n");
|
2005-12-26 13:21:38 +01:00
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
if (has_out_arg_or_return(func))
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
|
|
|
fprintf(client, "\n");
|
|
|
|
|
|
|
|
print_client("if ((_RpcMessage.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
|
|
|
indent++;
|
2008-09-15 19:40:51 +02:00
|
|
|
print_client("NdrConvert(&__frame->_StubMsg, (PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n",
|
|
|
|
*proc_offset);
|
|
|
|
indent--;
|
2006-03-24 17:40:17 +01:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
/* unmarshall arguments */
|
|
|
|
fprintf(client, "\n");
|
2008-09-15 16:46:01 +02:00
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_OUT, PHASE_UNMARSHAL);
|
2006-03-24 17:40:17 +01:00
|
|
|
|
|
|
|
/* unmarshal return value */
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)))
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2009-01-06 00:35:24 +01:00
|
|
|
if (decl_indirect(type_function_get_rettype(func->type)))
|
2007-12-10 15:24:11 +01:00
|
|
|
print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
|
2009-01-06 00:35:24 +01:00
|
|
|
else if (is_ptr(type_function_get_rettype(func->type)) ||
|
|
|
|
is_array(type_function_get_rettype(func->type)))
|
2007-12-10 15:24:11 +01:00
|
|
|
print_client("%s = 0;\n", "_RetVal");
|
2008-09-15 16:46:01 +02:00
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
|
2007-12-10 15:24:11 +01:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-08 12:48:44 +01:00
|
|
|
/* update proc_offset */
|
2009-01-06 00:33:27 +01:00
|
|
|
if (args)
|
2005-12-08 12:48:44 +01:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
|
2008-04-02 13:55:34 +02:00
|
|
|
*proc_offset += get_size_procformatstring_type(var->name, var->type, var->attrs);
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)))
|
|
|
|
*proc_offset += get_size_procformatstring_type("return value", type_function_get_rettype(func->type), NULL);
|
2006-03-18 14:33:39 +01:00
|
|
|
else
|
2006-06-18 19:45:50 +02:00
|
|
|
*proc_offset += 2; /* FC_END and FC_PAD */
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
indent--;
|
|
|
|
print_client("}\n");
|
|
|
|
print_client("RpcFinally\n");
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
2009-01-06 00:33:27 +01:00
|
|
|
print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(func) );
|
2005-02-23 21:31:07 +01:00
|
|
|
indent--;
|
|
|
|
print_client("}\n");
|
|
|
|
print_client("RpcEndFinally\n");
|
|
|
|
|
|
|
|
|
|
|
|
/* emit return code */
|
2009-01-06 00:35:24 +01:00
|
|
|
if (!is_void(type_function_get_rettype(func->type)))
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
|
|
|
fprintf(client, "\n");
|
|
|
|
print_client("return _RetVal;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
indent--;
|
|
|
|
fprintf(client, "}\n");
|
|
|
|
fprintf(client, "\n");
|
|
|
|
|
|
|
|
method_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_stubdescdecl(type_t *iface)
|
|
|
|
{
|
2006-04-16 10:39:37 +02:00
|
|
|
print_client("static const MIDL_STUB_DESC %s_StubDesc;\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
print_client("static const MIDL_STUB_DESC %s_StubDesc =\n", iface->name);
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
2005-12-12 11:51:11 +01:00
|
|
|
print_client("(void *)& %s___RpcClientInterface,\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("MIDL_user_allocate,\n");
|
|
|
|
print_client("MIDL_user_free,\n");
|
2006-03-31 13:46:28 +02:00
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
2005-12-08 12:45:45 +01:00
|
|
|
if (implicit_handle)
|
|
|
|
print_client("&%s,\n", implicit_handle);
|
2005-02-23 21:31:07 +01:00
|
|
|
else
|
|
|
|
print_client("&%s__MIDL_AutoBindHandle,\n", iface->name);
|
2006-03-31 13:46:28 +02:00
|
|
|
indent--;
|
|
|
|
print_client("},\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
2006-01-27 12:53:32 +01:00
|
|
|
if (expr_eval_routines)
|
|
|
|
print_client("ExprEvalRoutines,\n");
|
|
|
|
else
|
|
|
|
print_client("0,\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
|
|
|
print_client("__MIDL_TypeFormatString.Format,\n");
|
|
|
|
print_client("1, /* -error bounds_check flag */\n");
|
|
|
|
print_client("0x10001, /* Ndr library version */\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0x50100a4, /* MIDL Version 5.1.164 */\n");
|
|
|
|
print_client("0,\n");
|
2007-06-14 01:13:04 +02:00
|
|
|
print_client("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0, /* notify & notify_flag routine table */\n");
|
|
|
|
print_client("1, /* Flags */\n");
|
|
|
|
print_client("0, /* Reserved3 */\n");
|
|
|
|
print_client("0, /* Reserved4 */\n");
|
|
|
|
print_client("0 /* Reserved5 */\n");
|
|
|
|
indent--;
|
|
|
|
print_client("};\n");
|
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_clientinterfacedecl(type_t *iface)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
|
2006-02-07 12:31:43 +01:00
|
|
|
const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2007-02-07 17:55:09 +01:00
|
|
|
const str_list_t *endpoints = get_attrp(iface->attrs, ATTR_ENDPOINT);
|
|
|
|
|
|
|
|
if (endpoints) write_endpoints( client, iface->name, endpoints );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
print_client("static const RPC_CLIENT_INTERFACE %s___RpcClientInterface =\n", iface->name );
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
|
|
|
print_client("sizeof(RPC_CLIENT_INTERFACE),\n");
|
2009-02-06 14:31:29 +01:00
|
|
|
print_client("{{0x%08x,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
|
2005-02-23 21:31:07 +01:00
|
|
|
uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
|
|
|
|
uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
|
2007-12-12 15:49:34 +01:00
|
|
|
uuid->Data4[7], MAJORVERSION(ver), MINORVERSION(ver));
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
|
|
|
|
print_client("0,\n");
|
2007-02-07 17:55:09 +01:00
|
|
|
if (endpoints)
|
|
|
|
{
|
|
|
|
print_client("%u,\n", list_count(endpoints));
|
|
|
|
print_client("(PRPC_PROTSEQ_ENDPOINT)%s__RpcProtseqEndpoint,\n", iface->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
indent--;
|
|
|
|
print_client("};\n");
|
2006-04-22 21:52:51 +02:00
|
|
|
if (old_names)
|
2008-12-01 14:39:39 +01:00
|
|
|
print_client("RPC_IF_HANDLE %s_ClientIfHandle DECLSPEC_HIDDEN = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n",
|
2006-04-22 21:52:51 +02:00
|
|
|
iface->name, iface->name);
|
|
|
|
else
|
2008-12-01 14:39:39 +01:00
|
|
|
print_client("RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec DECLSPEC_HIDDEN = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n",
|
2007-12-12 15:49:34 +01:00
|
|
|
prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver), iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_implicithandledecl(type_t *iface)
|
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-08 12:48:44 +01:00
|
|
|
if (implicit_handle)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2005-12-08 12:48:44 +01:00
|
|
|
fprintf(client, "handle_t %s;\n", implicit_handle);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void init_client(void)
|
|
|
|
{
|
|
|
|
if (client) return;
|
|
|
|
if (!(client = fopen(client_name, "w")))
|
|
|
|
error("Could not open %s for output\n", client_name);
|
|
|
|
|
2006-08-11 01:51:28 +02:00
|
|
|
print_client("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
|
2005-04-15 16:09:45 +02:00
|
|
|
print_client("#include <string.h>\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("#ifdef _ALPHA_\n");
|
2005-04-15 16:09:45 +02:00
|
|
|
print_client("#include <stdarg.h>\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("#endif\n");
|
|
|
|
fprintf(client, "\n");
|
2005-04-15 16:09:45 +02:00
|
|
|
print_client("#include \"%s\"\n", header_name);
|
2008-09-15 14:02:26 +02:00
|
|
|
print_client( "\n");
|
2008-12-01 14:39:39 +01:00
|
|
|
print_client( "#ifndef DECLSPEC_HIDDEN\n");
|
|
|
|
print_client( "#define DECLSPEC_HIDDEN\n");
|
|
|
|
print_client( "#endif\n");
|
|
|
|
print_client( "\n");
|
2008-09-15 14:05:26 +02:00
|
|
|
write_exceptions( client );
|
|
|
|
print_client( "\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_routines, unsigned int *proc_offset)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
2009-02-23 14:48:05 +01:00
|
|
|
if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
|
2008-04-24 20:06:28 +02:00
|
|
|
{
|
2009-01-06 00:33:27 +01:00
|
|
|
int has_func = 0;
|
|
|
|
const statement_t *stmt2;
|
2008-04-24 20:06:28 +02:00
|
|
|
type_t *iface = stmt->u.type;
|
|
|
|
if (!need_stub(iface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(client, "/*****************************************************************************\n");
|
|
|
|
fprintf(client, " * %s interface\n", iface->name);
|
|
|
|
fprintf(client, " */\n");
|
|
|
|
fprintf(client, "\n");
|
|
|
|
|
2009-01-06 00:35:13 +01:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt2, type_iface_get_stmts(iface))
|
2009-01-06 00:33:27 +01:00
|
|
|
{
|
|
|
|
has_func = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_func)
|
2008-04-24 20:06:28 +02:00
|
|
|
{
|
|
|
|
write_implicithandledecl(iface);
|
|
|
|
|
|
|
|
write_clientinterfacedecl(iface);
|
|
|
|
write_stubdescdecl(iface);
|
|
|
|
write_function_stubs(iface, proc_offset);
|
|
|
|
|
2008-12-26 17:22:25 +01:00
|
|
|
print_client("#if !defined(__RPC_WIN%u__)\n", pointer_size == 8 ? 64 : 32);
|
2008-04-24 20:06:28 +02:00
|
|
|
print_client("#error Invalid build platform for this stub.\n");
|
|
|
|
print_client("#endif\n");
|
|
|
|
|
|
|
|
fprintf(client, "\n");
|
|
|
|
write_stubdescriptor(iface, expr_eval_routines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (stmt->type == STMT_LIBRARY)
|
|
|
|
write_client_ifaces(stmt->u.lib->stmts, expr_eval_routines, proc_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-26 17:22:25 +01:00
|
|
|
static void write_client_routines(const statement_list_t *stmts)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2006-06-01 16:40:10 +02:00
|
|
|
unsigned int proc_offset = 0;
|
2007-10-27 00:33:13 +02:00
|
|
|
int expr_eval_routines;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_formatstringsdecl(client, indent, stmts, need_stub);
|
2007-10-27 00:33:13 +02:00
|
|
|
expr_eval_routines = write_expr_eval_routines(client, client_token);
|
|
|
|
if (expr_eval_routines)
|
|
|
|
write_expr_eval_routine_list(client, client_token);
|
|
|
|
write_user_quad_list(client);
|
2006-06-01 16:40:10 +02:00
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_client_ifaces(stmts, expr_eval_routines, &proc_offset);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
fprintf(client, "\n");
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_procformatstring(client, stmts, need_stub);
|
|
|
|
write_typeformatstring(client, stmts, need_stub);
|
2008-12-26 17:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_client(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
if (!do_client)
|
|
|
|
return;
|
|
|
|
if (do_everything && !need_stub_files(stmts))
|
|
|
|
return;
|
|
|
|
|
|
|
|
init_client();
|
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (do_win32 && do_win64)
|
|
|
|
{
|
|
|
|
fprintf(client, "\n#ifndef _WIN64\n\n");
|
|
|
|
pointer_size = 4;
|
|
|
|
write_client_routines( stmts );
|
|
|
|
fprintf(client, "\n#else /* _WIN64 */\n\n");
|
|
|
|
pointer_size = 8;
|
|
|
|
write_client_routines( stmts );
|
|
|
|
fprintf(client, "\n#endif /* _WIN64 */\n");
|
|
|
|
}
|
|
|
|
else if (do_win32)
|
|
|
|
{
|
|
|
|
pointer_size = 4;
|
|
|
|
write_client_routines( stmts );
|
|
|
|
}
|
|
|
|
else if (do_win64)
|
|
|
|
{
|
|
|
|
pointer_size = 8;
|
|
|
|
write_client_routines( stmts );
|
|
|
|
}
|
2006-06-01 16:40:10 +02:00
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
fclose(client);
|
|
|
|
}
|