2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: tt_db_rpc_message_routines.C /main/3 1995/10/23 10:05:09 rswiston $
28 /* @(#)tt_db_rpc_message_routines.C 1.10 94/11/17
29 * tt_db_rpc_message_routines.cc - Defines routines for converting TT
30 * message classes to RPC arguments.
32 * Copyright (c) 1992 by Sun Microsystems, Inc.
35 #include "mp/mp_message.h"
36 #include "util/tt_string.h"
37 #include "util/tt_xdr_utils.h"
38 #include "db/tt_db_rpc_message_routines.h"
40 // If this file is being compiled with -g, then DEFINE_NEW_AND_DELETE
41 // must be defined in order to prevent a dependency on the libC library.
42 // The dependency is due to the fact that cfront generates an extern
43 // reference to vec_new and vec_delete if it sees any access to arrays
44 // of calsses or structures. In the case of this file, tt_message_list
45 // contains a pointer to a structure that causes the references to be
47 #ifdef DEFINE_NEW_AND_DELETE
49 void *__vec_new (void *, int , int , void *)
50 { return (void *)NULL; }
52 void __vec_delete (void *, int , int , void *, int , int )
58 _tt_get_rpc_message (const _tt_message &rpc_message,
59 _Tt_message_ptr &message)
61 message = (_Tt_message *)NULL;
63 if (rpc_message.body.body_len) {
67 rpc_message.body.body_val,
68 (u_int)rpc_message.body.body_len,
71 message = new _Tt_message;
72 (void)message->xdr(&xdrs);
77 _tt_get_rpc_messages (const _tt_message_list &rpc_messages,
78 _Tt_message_list_ptr &messages)
80 messages = (_Tt_message_list *)NULL;
82 if (rpc_messages.messages_len) {
83 messages = new _Tt_message_list;
85 for (int i=0; i < rpc_messages.messages_len; i++) {
86 _Tt_message_ptr message_ptr;
88 _tt_get_rpc_message(rpc_messages.messages_val [i],
90 (void)messages->append(message_ptr);
96 _tt_set_rpc_message (const _Tt_message_ptr &message,
97 _tt_message &rpc_message)
99 if (message.is_null()) {
100 rpc_message.body.body_val = (char *)NULL;
101 rpc_message.body.body_len = 0;
104 _Tt_xdr_size_stream xdrsz;
107 if (!message->xdr((XDR *)xdrsz)) {
108 return TT_DB_ERR_ILLEGAL_MESSAGE;
110 length = (u_int)xdrsz.getsize();
113 _Tt_string temp_string((int)length);
114 xdrmem_create(&xdrs, (char *)temp_string, length, XDR_ENCODE);
115 if (!message->xdr(&xdrs)) {
116 return TT_DB_ERR_ILLEGAL_MESSAGE;
119 rpc_message.body.body_val = (char *)malloc(length+1);
120 (void)memcpy(rpc_message.body.body_val, (char *)temp_string, length);
121 rpc_message.body.body_val[length] = '\0';
122 rpc_message.body.body_len = length;