4 * Copyright 2005 Eric Kohl
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #define END_OF_LIST(list) \
41 while (NEXT_LINK(list)) \
42 list = NEXT_LINK(list); \
47 static int indent
= 0;
50 static int print_server(const char *format
, ...)
56 for (i
= 0; i
< indent
; i
++)
58 r
= vfprintf(server
, format
, va
);
65 get_base_type(unsigned char type
)
83 static void write_procformatstring(type_t
*iface
)
85 func_t
*func
= iface
->funcs
;
87 unsigned int type_offset
= 2;
88 int in_attr
, out_attr
;
90 print_server("static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
97 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
100 /* emit argument data */
104 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
107 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
108 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
110 /* set 'in' attribute if neither 'in' nor 'out' is set */
111 if (!out_attr
&& !in_attr
)
114 if (var
->ptr_level
== 0)
116 if (is_base_type(var
->type
))
118 print_server("0x4e, /* FC_IN_PARAM_BASETYPE */\n");
119 print_server("0x%02x, /* FC_<type> */\n", get_base_type(var
->type
->type
));
123 error("%s:%d Unknown/unsupported type 0x%x\n",
124 __FUNCTION__
,__LINE__
, var
->type
->type
);
128 else if (var
->ptr_level
== 1)
130 if (is_base_type(var
->type
))
132 if (in_attr
& !out_attr
)
133 print_server("0x4d, /* FC_IN_PARAM */\n");
134 else if (!in_attr
& out_attr
)
135 print_server("0x51, /* FC_OUT_PARAM */\n");
136 else if (in_attr
& out_attr
)
137 print_server("0x50, /* FC_IN_OUT_PARAM */\n");
138 fprintf(server
, "#ifndef _ALPHA_\n");
139 print_server("0x01,\n");
140 fprintf(server
, "#else\n");
141 print_server("0x02,\n");
142 fprintf(server
, "#endif\n");
143 print_server("NdrFcShort(0x%x),\n", type_offset
);
148 error("%s:%d Unknown/unsupported type 0x%x\n",
149 __FUNCTION__
,__LINE__
, var
->type
->type
);
154 var
= PREV_LINK(var
);
158 /* emit return value data */
160 if (is_void(var
->type
, NULL
))
162 print_server("0x5b, /* FC_END */\n");
163 print_server("0x5c, /* FC_PAD */\n");
165 else if (is_base_type(var
->type
))
167 print_server("0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
168 print_server("0x%02x, /* FC_<type> */\n", get_base_type(var
->type
->type
));
172 error("%s:%d Unknown/unsupported type 0x%x\n",
173 __FUNCTION__
,__LINE__
, var
->type
->type
);
177 func
= PREV_LINK(func
);
180 print_server("0x0\n");
184 print_server("};\n");
189 static void write_typeformatstring(type_t
*iface
)
191 func_t
*func
= iface
->funcs
;
195 int ptr_attr
, ref_attr
, unique_attr
;
197 print_server("static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
200 print_server("0,\n");
203 print_server("NdrFcShort(0x0),\n");
205 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
211 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
214 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
215 string_attr
= is_attr(var
->attrs
, ATTR_STRING
);
217 if (var
->ptr_level
> 1)
219 error("Function '%s' argument '%s': Pointer level %d not supported!\n",
220 func
->def
->name
, var
->name
, var
->ptr_level
);
224 if (var
->ptr_level
== 1)
226 ptr_attr
= is_attr(var
->attrs
, ATTR_PTR
);
227 ref_attr
= is_attr(var
->attrs
, ATTR_REF
);
228 unique_attr
= is_attr(var
->attrs
, ATTR_UNIQUE
);
230 if (ptr_attr
+ ref_attr
+ unique_attr
== 0)
233 if (is_base_type(var
->type
))
236 print_server("0x11, 0x0c, /* FC_RP [allocated_on_stack] [simple_pointer] */\n");
240 print_server("0x14, 0x08, /* FC_FP [simple_pointer] */\n");
242 print_server("0x11, 0x08, /* FC_RP [simple_pointer] */\n");
243 else if (unique_attr
)
244 print_server("0x12, 0x08, /* FC_UP [simple_pointer] */\n");
249 if (var
->type
->type
== RPC_FC_CHAR
)
250 print_server("0x%02x, /* FC_C_CSTRING */\n", RPC_FC_C_CSTRING
);
251 else if (var
->type
->type
== RPC_FC_WCHAR
)
252 print_server("0x%02x, /* FC_C_WSTRING */\n", RPC_FC_C_WSTRING
);
255 error("%s: Invalid type!\n", __FUNCTION__
);
260 print_server("0x%02x, /* FC_<type> */\n", get_base_type(var
->type
->type
));
261 print_server("0x5c, /* FC_PAD */\n");
265 var
= PREV_LINK(var
);
271 func
= PREV_LINK(func
);
274 print_server("0x0\n");
278 print_server("};\n");
283 static void print_message_buffer_size(func_t
*func
)
285 unsigned int alignment
= 0;
294 fprintf(server
, "\n");
295 print_server("_StubMsg.BufferLength =");
299 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
300 for (; var
; var
= PREV_LINK(var
))
302 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
307 switch (var
->type
->type
)
320 if (last_size
> 0 && last_size
< 2)
321 alignment
+= (2 - last_size
);
328 if (last_size
> 0 && last_size
< 4)
329 alignment
+= (4 - last_size
);
335 if (last_size
> 0 && last_size
< 4)
336 alignment
+= (4 - last_size
);
340 error("%s:%d Unknown/unsupported type 0x%x\n",
341 __FUNCTION__
,__LINE__
, var
->type
->type
);
346 fprintf(server
, " +");
347 fprintf(server
, " %dU", (size
== 0) ? 0 : size
+ alignment
);
353 /* return value size */
354 if (!is_void(func
->def
->type
, NULL
))
356 switch(func
->def
->type
->type
)
368 if (last_size
> 0 && last_size
< 4)
369 alignment
+= (4 - last_size
);
375 if (last_size
> 0 && last_size
< 4)
376 alignment
+= (4 - last_size
);
380 error("%s:%d Unknown/unsupported type 0x%x\n",
381 __FUNCTION__
,__LINE__
, func
->def
->type
->type
);
386 fprintf(server
, " +");
388 fprintf(server
, " %dU", (size
== 0) ? 0 : size
+ alignment
);
390 fprintf(server
, ";\n");
392 /* get string size */
397 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
398 for (; var
; var
= PREV_LINK(var
))
400 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
401 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
402 string_attr
= is_attr(var
->attrs
, ATTR_STRING
);
404 /* set 'in' attribute if neither 'in' nor 'out' is found */
405 if (!out_attr
&& !in_attr
)
408 if (var
->ptr_level
== 1 &&
410 (var
->type
->type
== RPC_FC_CHAR
|| var
->type
->type
== RPC_FC_WCHAR
))
412 print_server("_StubMsg.BufferLength += 16;\n");
418 fprintf(server
, "\n");
423 static void init_pointers (func_t
*func
)
431 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
434 if (var
->ptr_level
== 1)
437 write_type(server
, var
->type
, NULL
, var
->tname
);
438 fprintf(server
, " __RPC_FAR *)%s = 0;\n", var
->name
);
440 else if (var
->ptr_level
> 1)
442 error("Pointer level %d not supported!\n", var
->ptr_level
);
446 var
= PREV_LINK(var
);
448 fprintf(server
, "\n");
452 static void unmarshall_in_arguments(func_t
*func
, unsigned int *type_offset
)
454 unsigned int alignment
;
456 unsigned int last_size
= 0;
458 int in_attr
, out_attr
;
460 int ptr_attr
, ref_attr
, unique_attr
;
466 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
467 for (; var
; var
= PREV_LINK(var
))
469 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
470 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
471 string_attr
= is_attr(var
->attrs
, ATTR_STRING
);
473 /* set 'in' attribute if neither 'in' nor 'out' is set */
474 if (!out_attr
&& !in_attr
)
479 if (var
->ptr_level
== 1)
481 ptr_attr
= is_attr(var
->attrs
, ATTR_PTR
);
482 ref_attr
= is_attr(var
->attrs
, ATTR_REF
);
483 unique_attr
= is_attr(var
->attrs
, ATTR_UNIQUE
);
484 if (ptr_attr
+ ref_attr
+ unique_attr
== 0)
490 (var
->type
->type
== RPC_FC_CHAR
|| var
->type
->type
== RPC_FC_WCHAR
))
492 print_server("NdrConformantStringUnmarshall(\n");
494 print_server("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
495 print_server("(unsigned char __RPC_FAR * __RPC_FAR *)&%s,\n", var
->name
);
496 print_server("(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%u],\n", *type_offset
+ 2);
497 print_server("(unsigned char)0);\n");
499 fprintf(server
, "\n");
504 switch (var
->type
->type
)
517 if (last_size
!= 0 && last_size
< 2)
518 alignment
= (2 - last_size
);
525 if (last_size
!= 0 && last_size
< 4)
526 alignment
= (4 - last_size
);
532 if (last_size
!= 0 && last_size
< 4)
533 alignment
= (4 - last_size
);
541 error("%s:%d Unknown/unsupported type 0x%x\n",
542 __FUNCTION__
,__LINE__
, var
->type
->type
);
549 print_server("_StubMsg.Buffer += %u;\n", alignment
);
552 write_name(server
, var
);
553 fprintf(server
, " = (");
554 write_type(server
, var
->type
, NULL
, var
->tname
);
555 fprintf(server
, " __RPC_FAR*)_StubMsg.Buffer;\n");
556 print_server("_StubMsg.Buffer += sizeof(");
557 write_type(server
, var
->type
, NULL
, var
->tname
);
558 fprintf(server
, ");\n");
559 fprintf(server
, "\n");
565 else if (unique_attr
)
567 print_server("NdrPointerUnmarshall(\n");
569 print_server("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
570 print_server("(unsigned char __RPC_FAR * __RPC_FAR *)&%s,\n", var
->name
);
571 print_server("(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%u],\n", *type_offset
);
572 print_server("(unsigned char)0);\n");
574 fprintf(server
, "\n");
581 switch (var
->type
->type
)
594 if (last_size
!= 0 && last_size
< 2)
595 alignment
= (2 - last_size
);
602 if (last_size
!= 0 && last_size
< 4)
603 alignment
= (4 - last_size
);
609 if (last_size
!= 0 && last_size
< 4)
610 alignment
= (4 - last_size
);
618 error("%s:%d Unknown/unsupported type 0x%x\n",
619 __FUNCTION__
,__LINE__
, var
->type
->type
);
626 print_server("_StubMsg.Buffer += %u;\n", alignment
);
629 write_name(server
, var
);
630 fprintf(server
, " = *((");
631 write_type(server
, var
->type
, NULL
, var
->tname
);
632 fprintf(server
, " __RPC_FAR*)_StubMsg.Buffer);\n");
633 print_server("_StubMsg.Buffer += sizeof(");
634 write_type(server
, var
->type
, NULL
, var
->tname
);
635 fprintf(server
, ");\n");
636 fprintf(server
, "\n");
643 /* calculate the next type offset */
644 if (var
->ptr_level
== 1)
652 static void marshall_out_arguments(func_t
*func
)
654 unsigned int alignment
= 0;
655 unsigned int size
= 0;
656 unsigned int last_size
= 0;
663 /* marshall the out arguments */
667 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
668 for (; var
; var
= PREV_LINK(var
))
670 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
675 switch (var
->type
->type
)
688 if (last_size
!= 0 && last_size
< 2)
689 alignment
= (2 - last_size
);
696 if (last_size
!= 0 && last_size
< 4)
697 alignment
= (4 - last_size
);
703 if (last_size
!= 0 && last_size
< 4)
704 alignment
= (4 - last_size
);
712 error("%s:%d Unknown/unsupported type 0x%x\n",
713 __FUNCTION__
,__LINE__
, var
->type
->type
);
720 print_server("_StubMsg.Buffer += %u;\n", alignment
);
722 if (var
->ptr_level
== 1)
724 fprintf(server
, "\n");
726 write_type(server
, var
->type
, NULL
, var
->tname
);
727 fprintf(server
, " __RPC_FAR *)_StubMsg.Buffer) = *");
728 write_name(server
, var
);
729 fprintf(server
, ";\n");
731 print_server("_StubMsg.Buffer += sizeof(");
732 write_type(server
, var
->type
, NULL
, var
->tname
);
733 fprintf(server
, ");");
737 error("Pointer level %d is not supported!\n", var
->ptr_level
);
746 /* marshall the return value */
747 if (!is_void(def
->type
, NULL
))
750 switch (def
->type
->type
)
762 if (last_size
!= 0 && last_size
< 4)
763 alignment
= (4 - last_size
);
769 if (last_size
!= 0 && last_size
< 4)
770 alignment
= (4 - last_size
);
774 error("%s:%d Unknown/unsupported type 0x%x\n",
775 __FUNCTION__
,__LINE__
, var
->type
->type
);
779 fprintf(server
, "\n");
781 print_server("_StubMsg.Buffer += %u;\n", alignment
);
783 write_type(server
, def
->type
, def
, def
->tname
);
784 fprintf(server
, " __RPC_FAR *)_StubMsg.Buffer) = _RetVal;\n");
785 print_server("_StubMsg.Buffer += sizeof(");
786 write_type(server
, def
->type
, def
, def
->tname
);
787 fprintf(server
, ");\n");
792 static int use_return_buffer(func_t
*func
)
796 if (!is_void(func
->def
->type
, NULL
))
803 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
806 if (is_attr(var
->attrs
, ATTR_OUT
))
809 var
= PREV_LINK(var
);
816 static void write_function_stubs(type_t
*iface
)
818 int explicit_handle
= is_attr(iface
->attrs
, ATTR_EXPLICIT_HANDLE
);
819 func_t
*func
= iface
->funcs
;
821 var_t
* explicit_handle_var
;
822 unsigned int proc_offset
= 0;
823 unsigned int type_offset
= 2;
828 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
831 var_t
*def
= func
->def
;
833 /* check for a defined binding handle */
834 explicit_handle_var
= get_explicit_handle_var(func
);
837 if (!explicit_handle_var
)
839 error("%s() does not define an explicit binding handle!\n", def
->name
);
845 if (explicit_handle_var
)
847 error("%s() must not define a binding handle!\n", def
->name
);
852 fprintf(server
, "void __RPC_STUB\n");
853 fprintf(server
, "%s_", iface
->name
);
854 write_name(server
, def
);
855 fprintf(server
, "(\n");
857 print_server("PRPC_MESSAGE _pRpcMessage)\n");
860 /* write the functions body */
861 fprintf(server
, "{\n");
864 /* declare return value '_RetVal' */
865 if (!is_void(def
->type
, NULL
))
868 write_type(server
, def
->type
, def
, def
->tname
);
869 fprintf(server
, " _RetVal;\n");
872 /* declare arguments */
877 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
880 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
881 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
882 if (!out_attr
&& !in_attr
)
887 write_type(server
, var
->type
, NULL
, var
->tname
);
888 fprintf(server
, " _W%u;\n", i
);
893 write_type(server
, var
->type
, var
, var
->tname
);
894 fprintf(server
, " ");
895 write_name(server
, var
);
896 fprintf(server
, ";\n");
898 var
= PREV_LINK(var
);
902 print_server("MIDL_STUB_MESSAGE _StubMsg;\n");
903 print_server("RPC_STATUS _Status;\n");
904 fprintf(server
, "\n");
907 print_server("((void)(_Status));\n");
908 print_server("NdrServerInitializeNew(\n");
910 print_server("_pRpcMessage,\n");
911 print_server("&_StubMsg,\n");
912 print_server("&%s_StubDesc);\n", iface
->name
);
914 fprintf(server
, "\n");
918 print_server("%s = _pRpcMessage->Handle;\n", explicit_handle_var
->name
);
919 fprintf(server
, "\n");
924 print_server("RpcTryFinally\n");
927 print_server("RpcTryExcept\n");
933 print_server("if ((_pRpcMessage->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
935 print_server("NdrConvert(\n");
937 print_server("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
938 print_server("(PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", proc_offset
);
940 fprintf(server
, "\n");
942 unmarshall_in_arguments(func
, &type_offset
);
945 print_server("if (_StubMsg.Buffer > _StubMsg.BufferEnd)\n");
948 print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
953 print_server("RpcExcept(RPC_BAD_STUB_DATA_EXCEPTION_FILTER)\n");
956 print_server("RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
959 print_server("RpcEndExcept\n");
960 fprintf(server
, "\n");
962 /* assign out arguments */
967 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
970 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
971 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
972 if (!out_attr
&& !in_attr
)
977 write_name(server
, var
);
978 fprintf(server
, " = &_W%u;\n", i
);
982 var
= PREV_LINK(var
);
986 fprintf(server
, "\n");
989 /* Call the real server function */
990 if (!is_void(def
->type
, NULL
))
991 print_server("_RetVal = ");
994 write_name(server
, def
);
1000 fprintf(server
, "(\n");
1003 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1009 fprintf(server
, ",\n");
1011 write_name(server
, var
);
1012 var
= PREV_LINK(var
);
1014 fprintf(server
, ");\n");
1019 fprintf(server
, "();\n");
1022 /* allocate and fill the return message buffer */
1023 if (use_return_buffer(func
))
1025 print_message_buffer_size(func
);
1026 print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
1027 fprintf(server
, "\n");
1028 print_server("_Status = I_RpcGetBuffer(_pRpcMessage);\n");
1029 print_server("if (_Status)\n");
1031 print_server("RpcRaiseException(_Status);\n");
1033 fprintf(server
, "\n");
1034 print_server("_StubMsg.Buffer = (unsigned char __RPC_FAR *)_pRpcMessage->Buffer;\n");
1036 /* marshall the out arguments */
1037 marshall_out_arguments(func
);
1041 print_server("}\n");
1042 print_server("RpcFinally\n");
1043 print_server("{\n");
1044 print_server("}\n");
1045 print_server("RpcEndFinally\n");
1047 /* calculate buffer length */
1048 fprintf(server
, "\n");
1049 print_server("_pRpcMessage->BufferLength =\n");
1051 print_server("(unsigned int)((long)_StubMsg.Buffer - (long)_pRpcMessage->Buffer);\n");
1054 fprintf(server
, "}\n");
1055 fprintf(server
, "\n");
1057 /* update proc_offset */
1061 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1064 proc_offset
+= 2; /* FIXME */
1065 var
= PREV_LINK(var
);
1068 proc_offset
+= 2; /* FIXME */
1070 func
= PREV_LINK(func
);
1075 static void write_dispatchtable(type_t
*iface
)
1077 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
1078 unsigned long method_count
= 0;
1079 func_t
*cur
= iface
->funcs
;
1081 print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface
->name
);
1082 print_server("{\n");
1084 while (NEXT_LINK(cur
)) cur
= NEXT_LINK(cur
);
1087 var_t
*def
= cur
->def
;
1089 print_server("%s_", iface
->name
);
1090 write_name(server
, def
);
1091 fprintf(server
, ",\n");
1094 cur
= PREV_LINK(cur
);
1096 print_server("0\n");
1098 print_server("};\n");
1099 print_server("RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable =\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
1100 print_server("{\n");
1102 print_server("%u,\n", method_count
);
1103 print_server("%s_table\n", iface
->name
);
1105 print_server("};\n");
1106 fprintf(server
, "\n");
1110 static void write_stubdescdecl(type_t
*iface
)
1112 print_server("extern const MIDL_STUB_DESC %s_StubDesc;\n", iface
->name
);
1113 fprintf(server
, "\n");
1117 static void write_stubdescriptor(type_t
*iface
)
1119 print_server("static const MIDL_STUB_DESC %s_StubDesc =\n", iface
->name
);
1120 print_server("{\n");
1122 print_server("(void __RPC_FAR *)& %s___RpcServerInterface,\n", iface
->name
);
1123 print_server("MIDL_user_allocate,\n");
1124 print_server("MIDL_user_free,\n");
1125 print_server("{NULL},\n");
1126 print_server("0,\n");
1127 print_server("0,\n");
1128 print_server("0,\n");
1129 print_server("0,\n");
1130 print_server("__MIDL_TypeFormatString.Format,\n");
1131 print_server("1, /* -error bounds_check flag */\n");
1132 print_server("0x10001, /* Ndr library version */\n");
1133 print_server("0,\n");
1134 print_server("0x50100a4, /* MIDL Version 5.1.164 */\n");
1135 print_server("0,\n");
1136 print_server("0,\n");
1137 print_server("0, /* notify & notify_flag routine table */\n");
1138 print_server("1, /* Flags */\n");
1139 print_server("0, /* Reserved3 */\n");
1140 print_server("0, /* Reserved4 */\n");
1141 print_server("0 /* Reserved5 */\n");
1143 print_server("};\n");
1144 fprintf(server
, "\n");
1148 static void write_serverinterfacedecl(type_t
*iface
)
1150 unsigned long ver
= get_attrv(iface
->attrs
, ATTR_VERSION
);
1151 UUID
*uuid
= get_attrp(iface
->attrs
, ATTR_UUID
);
1153 print_server("extern RPC_DISPATCH_TABLE %s_v%d_%d_DispatchTable;\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
1154 fprintf(server
, "\n");
1155 print_server("static const RPC_SERVER_INTERFACE %s___RpcServerInterface =\n", iface
->name
);
1156 print_server("{\n");
1158 print_server("sizeof(RPC_SERVER_INTERFACE),\n");
1159 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",
1160 uuid
->Data1
, uuid
->Data2
, uuid
->Data3
, uuid
->Data4
[0], uuid
->Data4
[1],
1161 uuid
->Data4
[2], uuid
->Data4
[3], uuid
->Data4
[4], uuid
->Data4
[5], uuid
->Data4
[6],
1162 uuid
->Data4
[7], LOWORD(ver
), HIWORD(ver
));
1163 print_server("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
1164 print_server("&%s_v%d_%d_DispatchTable,\n", iface
->name
, LOWORD(ver
), HIWORD(ver
));
1165 print_server("0,\n");
1166 print_server("0,\n");
1167 print_server("0,\n");
1168 print_server("0,\n");
1169 print_server("0,\n");
1171 print_server("};\n");
1173 print_server("RPC_IF_HANDLE %s_ServerIfHandle = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n",
1174 iface
->name
, iface
->name
);
1176 print_server("RPC_IF_HANDLE %s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n",
1177 iface
->name
, LOWORD(ver
), HIWORD(ver
), iface
->name
);
1178 fprintf(server
, "\n");
1181 static void write_formatdesc( const char *str
)
1183 print_server("typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
1184 print_server("{\n");
1186 print_server("short Pad;\n");
1187 print_server("unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
1189 print_server("} MIDL_%s_FORMAT_STRING;\n", str
);
1193 static int get_type_format_string_size(type_t
*iface
)
1199 /* determine the proc format string size */
1200 func
= iface
->funcs
;
1201 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
1204 /* argument list size */
1208 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1211 if (var
->ptr_level
== 1)
1213 if (is_base_type(var
->type
))
1217 var
= PREV_LINK(var
);
1221 func
= PREV_LINK(func
);
1228 static int get_proc_format_string_size(type_t
*iface
)
1234 /* determine the proc format string size */
1235 func
= iface
->funcs
;
1236 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
1239 /* argument list size */
1243 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1246 switch (var
->ptr_level
)
1249 if (is_base_type(var
->type
))
1254 if (is_base_type(var
->type
))
1259 var
= PREV_LINK(var
);
1263 /* return value size */
1265 func
= PREV_LINK(func
);
1272 static void write_formatstringsdecl(type_t
*iface
)
1274 print_server("#define TYPE_FORMAT_STRING_SIZE %d\n",
1275 get_type_format_string_size(iface
));
1277 print_server("#define PROC_FORMAT_STRING_SIZE %d\n",
1278 get_proc_format_string_size(iface
));
1280 fprintf(server
, "\n");
1281 write_formatdesc("TYPE");
1282 write_formatdesc("PROC");
1283 fprintf(server
, "\n");
1284 print_server("extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
1285 print_server("extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
1290 static void init_server(void)
1294 if (!(server
= fopen(server_name
, "w")))
1295 error("Could not open %s for output\n", server_name
);
1297 print_server("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", WIDL_FULLVERSION
, input_name
);
1298 print_server("#include<string.h>\n");
1299 fprintf(server
, "\n");
1300 print_server("#include\"%s\"\n", header_name
);
1301 fprintf(server
, "\n");
1305 void write_server(ifref_t
*ifaces
)
1307 ifref_t
*iface
= ifaces
;
1321 fprintf(server
, "/*****************************************************************************\n");
1322 fprintf(server
, " * %s interface\n", iface
->iface
->name
);
1323 fprintf(server
, " */\n");
1324 fprintf(server
, "\n");
1326 write_formatstringsdecl(iface
->iface
);
1327 write_serverinterfacedecl(iface
->iface
);
1328 write_stubdescdecl(iface
->iface
);
1330 write_function_stubs(iface
->iface
);
1332 write_stubdescriptor(iface
->iface
);
1333 write_dispatchtable(iface
->iface
);
1335 print_server("#if !defined(__RPC_WIN32__)\n");
1336 print_server("#error Invalid build platform for this stub.\n");
1337 print_server("#endif\n");
1338 fprintf(server
, "\n");
1340 write_procformatstring(iface
->iface
);
1341 write_typeformatstring(iface
->iface
);
1343 fprintf(server
, "\n");
1345 iface
= PREV_LINK(iface
);