9 #include <trp_internal.h>
11 static int trpc_destructor(void *object)
13 TRPC_INSTANCE *trpc=talloc_get_type_abort(object, TRPC_INSTANCE);
14 if (trpc->gssname!=NULL)
15 tr_free_name(trpc->gssname);
19 /* also allocates the incoming mq */
20 TRPC_INSTANCE *trpc_new (TALLOC_CTX *mem_ctx)
22 TRPC_INSTANCE *trpc=talloc(mem_ctx, TRPC_INSTANCE);
29 trpc->mq=tr_mq_new(trpc);
34 talloc_set_destructor((void *)trpc, trpc_destructor);
40 void trpc_free (TRPC_INSTANCE *trpc)
46 TRPC_INSTANCE *trpc_get_next(TRPC_INSTANCE *trpc)
51 void trpc_set_next(TRPC_INSTANCE *trpc, TRPC_INSTANCE *next)
56 /* Ok to call more than once; guarantees trpc no longer in the list. Does not free removed element.
57 * Returns handle to new list, you must replace your old handle on the list with this. */
58 TRPC_INSTANCE *trpc_remove(TRPC_INSTANCE *trpc, TRPC_INSTANCE *remove)
60 TRPC_INSTANCE *cur=trpc;
61 TRPC_INSTANCE *last=NULL;
66 /* first element is a special case */
68 trpc=trpc_get_next(cur); /* advance list head */
70 /* it was not the first element */
72 cur=trpc_get_next(cur);
75 trpc_set_next(last, trpc_get_next(cur));
79 cur=trpc_get_next(cur);
85 static TRPC_INSTANCE *trpc_get_tail(TRPC_INSTANCE *trpc)
87 while((trpc!=NULL)&&(trpc_get_next(trpc)!=NULL))
88 trpc=trpc_get_next(trpc);
92 void trpc_append(TRPC_INSTANCE *trpc, TRPC_INSTANCE *new)
94 trpc_set_next(trpc_get_tail(trpc), new);
97 char *trpc_get_server(TRPC_INSTANCE *trpc)
102 void trpc_set_server(TRPC_INSTANCE *trpc, char *server)
107 TR_NAME *trpc_get_gssname(TRPC_INSTANCE *trpc)
109 return trpc->gssname;
112 /* takes responsibility for freeing gssname */
113 void trpc_set_gssname(TRPC_INSTANCE *trpc, TR_NAME *gssname)
115 trpc->gssname=gssname;
118 unsigned int trpc_get_port(TRPC_INSTANCE *trpc)
123 void trpc_set_port(TRPC_INSTANCE *trpc, unsigned int port)
128 TRP_CONNECTION *trpc_get_conn(TRPC_INSTANCE *trpc)
133 void trpc_set_conn(TRPC_INSTANCE *trpc, TRP_CONNECTION *conn)
138 DH *trpc_get_dh(TRPC_INSTANCE *trpc)
143 void trpc_set_dh(TRPC_INSTANCE *trpc, DH *dh)
148 TRP_CONNECTION_STATUS trpc_get_status(TRPC_INSTANCE *trpc)
150 return trp_connection_get_status(trpc_get_conn(trpc));
153 TR_MQ *trpc_get_mq(TRPC_INSTANCE *trpc)
158 void trpc_set_mq(TRPC_INSTANCE *trpc, TR_MQ *mq)
163 /* submit msg to trpc for transmission */
164 void trpc_mq_append(TRPC_INSTANCE *trpc, TR_MQ_MSG *msg)
166 tr_mq_append(trpc->mq, msg);
169 TR_MQ_MSG *trpc_mq_pop(TRPC_INSTANCE *trpc)
171 return tr_mq_pop(trpc->mq);
174 TRP_RC trpc_connect(TRPC_INSTANCE *trpc)
176 return trp_connection_initiate(trpc_get_conn(trpc), trpc_get_server(trpc), trpc_get_port(trpc));
179 /* simple function, based on tidc_send_req */
180 TRP_RC trpc_send_msg (TRPC_INSTANCE *trpc,
181 const char *msg_content)
184 TRP_RC rc=TRP_SUCCESS;
186 /* Send the request over the connection */
187 if (err = gsscon_write_encrypted_token(trp_connection_get_fd(trpc_get_conn(trpc)),
188 *trp_connection_get_gssctx(trpc_get_conn(trpc)),
190 strlen(msg_content))) {
191 tr_err( "trpc_send_msg: Error sending message over connection.\n");