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>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
|
|
|
#include "windef.h"
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "typelib.h"
|
|
|
|
#include "typelib_struct.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
#include "typegen.h"
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
static FILE* server;
|
|
|
|
static int indent = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static int print_server(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
va_start(va, format);
|
2006-08-11 19:15:55 +02:00
|
|
|
if (format[0] != '\n')
|
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
fprintf(server, " ");
|
2005-02-23 21:31:07 +01:00
|
|
|
r = vfprintf(server, format, va);
|
|
|
|
va_end(va);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-07 12:31:43 +01:00
|
|
|
static void write_parameters_init(const func_t *func)
|
2005-12-12 12:13:43 +01:00
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t *var;
|
2005-12-12 12:13:43 +01:00
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
2006-03-18 14:33:48 +01:00
|
|
|
if (var->type->type != RPC_FC_BIND_PRIMITIVE)
|
|
|
|
print_server("%s = 0;\n", var->name);
|
2005-12-12 12:13:43 +01:00
|
|
|
|
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
static void declare_args(const func_t *func)
|
|
|
|
{
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int i = 0;
|
|
|
|
var_t *var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
2006-03-31 13:50:46 +02:00
|
|
|
const expr_t *size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
|
|
|
int has_size = size_is && (size_is->type != EXPR_VOID);
|
|
|
|
int is_string = is_attr(var->attrs, ATTR_STRING);
|
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!out_attr && !in_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2006-03-31 13:50:46 +02:00
|
|
|
if (!in_attr && !has_size && !is_string)
|
2006-03-24 17:40:17 +01:00
|
|
|
{
|
2006-03-31 13:49:57 +02:00
|
|
|
int indirection;
|
2006-03-24 17:40:17 +01:00
|
|
|
print_server("");
|
|
|
|
write_type(server, var->type, NULL, var->tname);
|
2006-03-31 13:49:57 +02:00
|
|
|
for (indirection = 0; indirection < var->ptr_level - 1; indirection++)
|
|
|
|
fprintf(server, "*");
|
2006-03-24 17:40:17 +01:00
|
|
|
fprintf(server, " _W%u;\n", i++);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_server("");
|
|
|
|
write_type(server, var->type, var, var->tname);
|
|
|
|
fprintf(server, " ");
|
|
|
|
write_name(server, var);
|
|
|
|
write_array(server, var->array, 0);
|
|
|
|
fprintf(server, ";\n");
|
|
|
|
|
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void assign_out_args(const func_t *func)
|
|
|
|
{
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int i = 0, sep = 0;
|
|
|
|
var_t *var;
|
2006-03-29 12:42:29 +02:00
|
|
|
const expr_t *size_is;
|
|
|
|
int has_size;
|
2006-03-24 17:40:17 +01:00
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
2006-03-31 13:50:46 +02:00
|
|
|
int is_string = is_attr(var->attrs, ATTR_STRING);
|
2006-03-29 12:42:29 +02:00
|
|
|
size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
|
|
|
has_size = size_is && (size_is->type != EXPR_VOID);
|
2006-03-24 17:40:17 +01:00
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!out_attr && !in_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
|
|
|
if (!in_attr)
|
|
|
|
{
|
|
|
|
print_server("");
|
|
|
|
write_name(server, var);
|
2006-03-29 12:42:29 +02:00
|
|
|
|
|
|
|
if (has_size)
|
|
|
|
{
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int size;
|
2006-03-29 12:42:29 +02:00
|
|
|
type_t *type = var->type;
|
|
|
|
|
|
|
|
fprintf(server, " = NdrAllocate(&_StubMsg, ");
|
|
|
|
write_expr(server, size_is, 1);
|
2006-06-13 14:13:49 +02:00
|
|
|
size = get_type_memsize(type);
|
|
|
|
fprintf(server, " * %u);\n", size);
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
2006-03-31 13:50:46 +02:00
|
|
|
else if (!is_string)
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2006-03-31 13:50:10 +02:00
|
|
|
fprintf(server, " = &_W%u;\n", i);
|
|
|
|
if (var->ptr_level > 1)
|
|
|
|
print_server("_W%u = 0;\n", i);
|
|
|
|
i++;
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
sep = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep)
|
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsigned int *type_offset)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2005-12-12 12:14:03 +01:00
|
|
|
char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
|
|
|
int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
|
2006-02-07 12:31:43 +01:00
|
|
|
const func_t *func = iface->funcs;
|
|
|
|
const var_t *var;
|
|
|
|
const var_t* explicit_handle_var;
|
2005-12-08 12:48:44 +01:00
|
|
|
|
2005-12-08 12:45:45 +01:00
|
|
|
while (NEXT_LINK(func)) func = NEXT_LINK(func);
|
|
|
|
while (func)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t *def = func->def;
|
2005-12-26 13:20:59 +01:00
|
|
|
unsigned long buffer_size = 0;
|
2006-01-31 18:05:33 +01:00
|
|
|
unsigned int type_offset_func;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-12 12:14:03 +01:00
|
|
|
/* check for a defined binding handle */
|
|
|
|
explicit_handle_var = get_explicit_handle_var(func);
|
|
|
|
if (explicit_handle)
|
|
|
|
{
|
|
|
|
if (!explicit_handle_var)
|
|
|
|
{
|
|
|
|
error("%s() does not define an explicit binding handle!\n", def->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (implicit_handle)
|
|
|
|
{
|
|
|
|
if (explicit_handle_var)
|
|
|
|
{
|
|
|
|
error("%s() must not define a binding handle!\n", def->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-13 11:12:37 +01:00
|
|
|
fprintf(server, "void __RPC_STUB\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(server, "%s_", iface->name);
|
|
|
|
write_name(server, def);
|
|
|
|
fprintf(server, "(\n");
|
|
|
|
indent++;
|
|
|
|
print_server("PRPC_MESSAGE _pRpcMessage)\n");
|
|
|
|
indent--;
|
|
|
|
|
|
|
|
/* write the functions body */
|
|
|
|
fprintf(server, "{\n");
|
|
|
|
indent++;
|
|
|
|
|
|
|
|
/* declare return value '_RetVal' */
|
|
|
|
if (!is_void(def->type, NULL))
|
|
|
|
{
|
|
|
|
print_server("");
|
|
|
|
write_type(server, def->type, def, def->tname);
|
|
|
|
fprintf(server, " _RetVal;\n");
|
|
|
|
}
|
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
/* Declare arguments */
|
|
|
|
declare_args(func);
|
2005-12-08 12:48:44 +01:00
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("MIDL_STUB_MESSAGE _StubMsg;\n");
|
|
|
|
print_server("RPC_STATUS _Status;\n");
|
|
|
|
fprintf(server, "\n");
|
2005-12-08 12:48:44 +01:00
|
|
|
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("((void)(_Status));\n");
|
|
|
|
print_server("NdrServerInitializeNew(\n");
|
|
|
|
indent++;
|
|
|
|
print_server("_pRpcMessage,\n");
|
|
|
|
print_server("&_StubMsg,\n");
|
|
|
|
print_server("&%s_StubDesc);\n", iface->name);
|
|
|
|
indent--;
|
|
|
|
fprintf(server, "\n");
|
|
|
|
|
2005-12-12 12:13:43 +01:00
|
|
|
write_parameters_init(func);
|
|
|
|
|
2005-12-12 12:14:03 +01:00
|
|
|
if (explicit_handle_var)
|
|
|
|
{
|
|
|
|
print_server("%s = _pRpcMessage->Handle;\n", explicit_handle_var->name);
|
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("RpcTryFinally\n");
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
|
|
|
print_server("RpcTryExcept\n");
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
2005-12-08 12:48:44 +01:00
|
|
|
|
|
|
|
if (func->args)
|
|
|
|
{
|
|
|
|
print_server("if ((_pRpcMessage->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
|
|
|
indent++;
|
|
|
|
print_server("NdrConvert(\n");
|
|
|
|
indent++;
|
|
|
|
print_server("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
|
2006-06-18 19:45:50 +02:00
|
|
|
print_server("(PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", *proc_offset);
|
2005-12-08 12:48:44 +01:00
|
|
|
indent -= 2;
|
|
|
|
fprintf(server, "\n");
|
|
|
|
|
2006-01-31 18:05:33 +01:00
|
|
|
/* make a copy so we don't increment the type offset twice */
|
2006-06-01 16:40:10 +02:00
|
|
|
type_offset_func = *type_offset;
|
2006-01-31 18:05:33 +01:00
|
|
|
|
2006-02-07 12:32:24 +01:00
|
|
|
/* unmarshall arguments */
|
|
|
|
write_remoting_arguments(server, indent, func, &type_offset_func, PASS_IN, PHASE_UNMARSHAL);
|
2005-12-08 12:48:44 +01:00
|
|
|
}
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("if (_StubMsg.Buffer > _StubMsg.BufferEnd)\n");
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
|
|
|
print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
|
|
|
|
indent--;
|
|
|
|
print_server("}\n");
|
|
|
|
indent--;
|
|
|
|
print_server("}\n");
|
|
|
|
print_server("RpcExcept(RPC_BAD_STUB_DATA_EXCEPTION_FILTER)\n");
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
|
|
|
print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
|
|
|
|
indent--;
|
|
|
|
print_server("}\n");
|
|
|
|
print_server("RpcEndExcept\n");
|
|
|
|
fprintf(server, "\n");
|
|
|
|
|
2006-03-24 17:40:17 +01:00
|
|
|
/* Assign 'out' arguments */
|
|
|
|
assign_out_args(func);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
/* Call the real server function */
|
|
|
|
if (!is_void(def->type, NULL))
|
|
|
|
print_server("_RetVal = ");
|
|
|
|
else
|
|
|
|
print_server("");
|
|
|
|
write_name(server, def);
|
|
|
|
|
2005-12-08 12:48:44 +01:00
|
|
|
if (func->args)
|
|
|
|
{
|
|
|
|
int first_arg = 1;
|
|
|
|
|
|
|
|
fprintf(server, "(\n");
|
|
|
|
indent++;
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
|
|
|
if (first_arg)
|
|
|
|
first_arg = 0;
|
|
|
|
else
|
|
|
|
fprintf(server, ",\n");
|
|
|
|
print_server("");
|
|
|
|
write_name(server, var);
|
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
|
|
|
fprintf(server, ");\n");
|
|
|
|
indent--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(server, "();\n");
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-26 13:20:59 +01:00
|
|
|
if (func->args)
|
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t *var = func->args;
|
2005-12-26 13:20:59 +01:00
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
|
|
|
if (is_attr(var->attrs, ATTR_OUT))
|
|
|
|
{
|
|
|
|
unsigned int alignment;
|
2006-04-09 14:38:57 +02:00
|
|
|
buffer_size += get_required_buffer_size(var, &alignment, PASS_OUT);
|
2005-12-26 13:20:59 +01:00
|
|
|
buffer_size += alignment;
|
|
|
|
}
|
2006-04-09 14:38:57 +02:00
|
|
|
|
2005-12-26 13:20:59 +01:00
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
if (!is_void(def->type, NULL))
|
2005-12-26 13:20:59 +01:00
|
|
|
{
|
|
|
|
unsigned int alignment;
|
2006-04-09 14:38:57 +02:00
|
|
|
buffer_size += get_required_buffer_size(def, &alignment, PASS_RETURN);
|
2005-12-26 13:20:59 +01:00
|
|
|
buffer_size += alignment;
|
|
|
|
}
|
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
if (has_out_arg_or_return(func))
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
|
|
|
fprintf(server, "\n");
|
2006-03-29 12:42:29 +02:00
|
|
|
print_server("_StubMsg.BufferLength = %u;\n", buffer_size);
|
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
type_offset_func = *type_offset;
|
2006-03-29 12:42:29 +02:00
|
|
|
write_remoting_arguments(server, indent, func, &type_offset_func, PASS_OUT, PHASE_BUFFERSIZE);
|
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
|
|
|
|
fprintf(server, "\n");
|
|
|
|
print_server("_Status = I_RpcGetBuffer(_pRpcMessage);\n");
|
|
|
|
print_server("if (_Status)\n");
|
|
|
|
indent++;
|
|
|
|
print_server("RpcRaiseException(_Status);\n");
|
|
|
|
indent--;
|
|
|
|
fprintf(server, "\n");
|
2005-12-12 11:51:11 +01:00
|
|
|
print_server("_StubMsg.Buffer = (unsigned char *)_pRpcMessage->Buffer;\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(server, "\n");
|
2005-12-26 13:20:59 +01:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
type_offset_func = *type_offset;
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2006-02-07 12:32:24 +01:00
|
|
|
/* marshall arguments */
|
2006-06-01 16:40:10 +02:00
|
|
|
write_remoting_arguments(server, indent, func, type_offset, PASS_OUT, PHASE_MARSHAL);
|
2005-12-26 13:21:38 +01:00
|
|
|
|
2005-12-26 13:20:59 +01:00
|
|
|
/* marshall the return value */
|
|
|
|
if (!is_void(def->type, NULL))
|
2006-03-31 13:49:36 +02:00
|
|
|
print_phase_basetype(server, indent, PHASE_MARSHAL, PASS_RETURN, def, "_RetVal");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
indent--;
|
|
|
|
print_server("}\n");
|
|
|
|
print_server("RpcFinally\n");
|
|
|
|
print_server("{\n");
|
2006-03-29 12:42:29 +02:00
|
|
|
indent++;
|
|
|
|
|
|
|
|
write_remoting_arguments(server, indent, func, &type_offset_func, PASS_OUT, PHASE_FREE);
|
|
|
|
|
|
|
|
indent--;
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("}\n");
|
|
|
|
print_server("RpcEndFinally\n");
|
|
|
|
|
|
|
|
/* calculate buffer length */
|
|
|
|
fprintf(server, "\n");
|
|
|
|
print_server("_pRpcMessage->BufferLength =\n");
|
|
|
|
indent++;
|
2005-12-12 12:12:06 +01:00
|
|
|
print_server("(unsigned int)(_StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer);\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
indent--;
|
|
|
|
indent--;
|
|
|
|
fprintf(server, "}\n");
|
|
|
|
fprintf(server, "\n");
|
|
|
|
|
2005-12-08 12:48:44 +01:00
|
|
|
/* update proc_offset */
|
|
|
|
if (func->args)
|
|
|
|
{
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
2006-06-18 19:45:50 +02:00
|
|
|
*proc_offset += get_size_procformatstring_var(var);
|
2005-12-08 12:48:44 +01:00
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:05:29 +01:00
|
|
|
if (!is_void(def->type, NULL))
|
2006-06-18 19:45:50 +02:00
|
|
|
*proc_offset += get_size_procformatstring_var(def);
|
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-12-08 12:48:44 +01:00
|
|
|
|
2005-12-08 12:45:45 +01:00
|
|
|
func = PREV_LINK(func);
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_dispatchtable(type_t *iface)
|
|
|
|
{
|
|
|
|
unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
|
|
|
|
unsigned long method_count = 0;
|
2005-12-08 12:45:45 +01:00
|
|
|
func_t *func = iface->funcs;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name);
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
2005-12-08 12:45:45 +01:00
|
|
|
while (NEXT_LINK(func)) func = NEXT_LINK(func);
|
|
|
|
while (func)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2005-12-08 12:45:45 +01:00
|
|
|
var_t *def = func->def;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
print_server("%s_", iface->name);
|
|
|
|
write_name(server, def);
|
|
|
|
fprintf(server, ",\n");
|
|
|
|
|
|
|
|
method_count++;
|
2005-12-08 12:45:45 +01:00
|
|
|
func = PREV_LINK(func);
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
|
|
|
print_server("0\n");
|
|
|
|
indent--;
|
|
|
|
print_server("};\n");
|
|
|
|
print_server("RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable =\n", iface->name, LOWORD(ver), HIWORD(ver));
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
|
|
|
print_server("%u,\n", method_count);
|
|
|
|
print_server("%s_table\n", iface->name);
|
|
|
|
indent--;
|
|
|
|
print_server("};\n");
|
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_stubdescdecl(type_t *iface)
|
|
|
|
{
|
2006-04-16 10:39:37 +02:00
|
|
|
print_server("static const MIDL_STUB_DESC %s_StubDesc;\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(server, "\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
|
|
|
{
|
|
|
|
print_server("static const MIDL_STUB_DESC %s_StubDesc =\n", iface->name);
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
2005-12-12 11:51:11 +01:00
|
|
|
print_server("(void *)& %s___RpcServerInterface,\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("MIDL_user_allocate,\n");
|
|
|
|
print_server("MIDL_user_free,\n");
|
2006-03-31 13:46:28 +02:00
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("0,\n");
|
2006-03-31 13:46:28 +02:00
|
|
|
indent--;
|
|
|
|
print_server("},\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0,\n");
|
2006-01-27 12:53:32 +01:00
|
|
|
if (expr_eval_routines)
|
|
|
|
print_server("ExprEvalRoutines,\n");
|
|
|
|
else
|
|
|
|
print_server("0,\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_server("0,\n");
|
|
|
|
print_server("__MIDL_TypeFormatString.Format,\n");
|
|
|
|
print_server("1, /* -error bounds_check flag */\n");
|
|
|
|
print_server("0x10001, /* Ndr library version */\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0x50100a4, /* MIDL Version 5.1.164 */\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0, /* notify & notify_flag routine table */\n");
|
|
|
|
print_server("1, /* Flags */\n");
|
|
|
|
print_server("0, /* Reserved3 */\n");
|
|
|
|
print_server("0, /* Reserved4 */\n");
|
|
|
|
print_server("0 /* Reserved5 */\n");
|
|
|
|
indent--;
|
|
|
|
print_server("};\n");
|
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_serverinterfacedecl(type_t *iface)
|
|
|
|
{
|
|
|
|
unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
|
|
|
|
UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
|
|
|
|
|
|
|
print_server("extern RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable;\n", iface->name, LOWORD(ver), HIWORD(ver));
|
|
|
|
fprintf(server, "\n");
|
|
|
|
print_server("static const RPC_SERVER_INTERFACE %s___RpcServerInterface =\n", iface->name );
|
|
|
|
print_server("{\n");
|
|
|
|
indent++;
|
|
|
|
print_server("sizeof(RPC_SERVER_INTERFACE),\n");
|
|
|
|
print_server("{{0x%08lx,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
|
|
|
|
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],
|
|
|
|
uuid->Data4[7], LOWORD(ver), HIWORD(ver));
|
|
|
|
print_server("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
|
|
|
|
print_server("&%s_v%d_%d_DispatchTable,\n", iface->name, LOWORD(ver), HIWORD(ver));
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
print_server("0,\n");
|
|
|
|
indent--;
|
|
|
|
print_server("};\n");
|
2006-04-22 21:52:51 +02:00
|
|
|
if (old_names)
|
|
|
|
print_server("RPC_IF_HANDLE %s_ServerIfHandle = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n",
|
|
|
|
iface->name, iface->name);
|
|
|
|
else
|
|
|
|
print_server("RPC_IF_HANDLE %s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n",
|
|
|
|
iface->name, LOWORD(ver), HIWORD(ver), iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void init_server(void)
|
|
|
|
{
|
|
|
|
if (server)
|
|
|
|
return;
|
|
|
|
if (!(server = fopen(server_name, "w")))
|
|
|
|
error("Could not open %s for output\n", server_name);
|
|
|
|
|
2006-08-11 01:51:28 +02:00
|
|
|
print_server("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
|
2005-04-15 16:09:45 +02:00
|
|
|
print_server("#include <string.h>\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(server, "\n");
|
2005-04-15 16:09:45 +02:00
|
|
|
print_server("#include \"%s\"\n", header_name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(server, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void write_server(ifref_t *ifaces)
|
|
|
|
{
|
2006-06-01 16:40:10 +02:00
|
|
|
unsigned int proc_offset = 0;
|
|
|
|
unsigned int type_offset = 2;
|
2005-12-12 12:11:44 +01:00
|
|
|
ifref_t *iface = ifaces;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
if (!do_server)
|
|
|
|
return;
|
2007-01-19 12:46:19 +01:00
|
|
|
if (do_everything && !ifaces)
|
2005-02-23 21:31:07 +01:00
|
|
|
return;
|
2005-12-12 12:11:44 +01:00
|
|
|
END_OF_LIST(iface);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
init_server();
|
|
|
|
if (!server)
|
|
|
|
return;
|
|
|
|
|
2006-08-18 03:08:38 +02:00
|
|
|
write_formatstringsdecl(server, indent, ifaces, 0);
|
2006-06-01 16:40:10 +02:00
|
|
|
|
2006-03-31 13:44:04 +02:00
|
|
|
for (; iface; iface = PREV_LINK(iface))
|
2005-12-12 12:11:44 +01:00
|
|
|
{
|
2006-03-31 13:44:04 +02:00
|
|
|
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
|
|
|
|
continue;
|
|
|
|
|
2005-12-12 12:11:44 +01:00
|
|
|
fprintf(server, "/*****************************************************************************\n");
|
|
|
|
fprintf(server, " * %s interface\n", iface->iface->name);
|
|
|
|
fprintf(server, " */\n");
|
|
|
|
fprintf(server, "\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-26 13:08:51 +01:00
|
|
|
if (iface->iface->funcs)
|
|
|
|
{
|
2006-01-27 12:53:32 +01:00
|
|
|
int expr_eval_routines;
|
|
|
|
|
2005-12-26 13:08:51 +01:00
|
|
|
write_serverinterfacedecl(iface->iface);
|
|
|
|
write_stubdescdecl(iface->iface);
|
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
write_function_stubs(iface->iface, &proc_offset, &type_offset);
|
2005-12-26 13:08:51 +01:00
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
print_server("#if !defined(__RPC_WIN32__)\n");
|
|
|
|
print_server("#error Invalid build platform for this stub.\n");
|
|
|
|
print_server("#endif\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
fprintf(server, "\n");
|
2005-12-12 12:11:44 +01:00
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
expr_eval_routines = write_expr_eval_routines(server, iface->iface->name);
|
|
|
|
if (expr_eval_routines)
|
|
|
|
write_expr_eval_routine_list(server, iface->iface->name);
|
|
|
|
|
|
|
|
write_stubdescriptor(iface->iface, expr_eval_routines);
|
|
|
|
write_dispatchtable(iface->iface);
|
|
|
|
}
|
2005-12-12 12:11:44 +01:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
fprintf(server, "\n");
|
|
|
|
|
2006-08-18 03:08:38 +02:00
|
|
|
write_procformatstring(server, ifaces, 0);
|
|
|
|
write_typeformatstring(server, ifaces, 0);
|
2006-06-01 16:40:10 +02:00
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
fclose(server);
|
|
|
|
}
|