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);
28 trpc->mq=tr_mq_new(trpc);
33 talloc_set_destructor((void *)trpc, trpc_destructor);
39 void trpc_free (TRPC_INSTANCE *trpc)
45 TRPC_INSTANCE *trpc_get_next(TRPC_INSTANCE *trpc)
50 void trpc_set_next(TRPC_INSTANCE *trpc, TRPC_INSTANCE *next)
55 /* Ok to call more than once; guarantees trpc no longer in the list. Does not free removed element.
56 * Returns handle to new list, you must replace your old handle on the list with this. */
57 TRPC_INSTANCE *trpc_remove(TRPC_INSTANCE *trpc, TRPC_INSTANCE *remove)
59 TRPC_INSTANCE *cur=trpc;
60 TRPC_INSTANCE *last=NULL;
65 /* first element is a special case */
67 trpc=trpc_get_next(cur); /* advance list head */
69 /* it was not the first element */
71 cur=trpc_get_next(cur);
74 trpc_set_next(last, trpc_get_next(cur));
78 cur=trpc_get_next(cur);
84 static TRPC_INSTANCE *trpc_get_tail(TRPC_INSTANCE *trpc)
86 while((trpc!=NULL)&&(trpc_get_next(trpc)!=NULL))
87 trpc=trpc_get_next(trpc);
91 void trpc_append(TRPC_INSTANCE *trpc, TRPC_INSTANCE *new)
93 trpc_set_next(trpc_get_tail(trpc), new);
96 char *trpc_get_server(TRPC_INSTANCE *trpc)
101 void trpc_set_server(TRPC_INSTANCE *trpc, char *server)
106 TR_NAME *trpc_get_gssname(TRPC_INSTANCE *trpc)
108 return trpc->gssname;
111 /* takes responsibility for freeing gssname */
112 void trpc_set_gssname(TRPC_INSTANCE *trpc, TR_NAME *gssname)
114 trpc->gssname=gssname;
117 unsigned int trpc_get_port(TRPC_INSTANCE *trpc)
122 void trpc_set_port(TRPC_INSTANCE *trpc, unsigned int port)
127 TRP_CONNECTION *trpc_get_conn(TRPC_INSTANCE *trpc)
132 void trpc_set_conn(TRPC_INSTANCE *trpc, TRP_CONNECTION *conn)
137 TRP_CONNECTION_STATUS trpc_get_status(TRPC_INSTANCE *trpc)
139 return trp_connection_get_status(trpc_get_conn(trpc));
142 TR_MQ *trpc_get_mq(TRPC_INSTANCE *trpc)
147 void trpc_set_mq(TRPC_INSTANCE *trpc, TR_MQ *mq)
152 /* submit msg to trpc for transmission */
153 void trpc_mq_add(TRPC_INSTANCE *trpc, TR_MQ_MSG *msg)
155 tr_mq_add(trpc->mq, msg);
158 TR_MQ_MSG *trpc_mq_pop(TRPC_INSTANCE *trpc)
160 return tr_mq_pop(trpc->mq);
163 void trpc_mq_clear(TRPC_INSTANCE *trpc)
165 tr_mq_clear(trpc->mq);
168 TRP_RC trpc_connect(TRPC_INSTANCE *trpc)
170 return trp_connection_initiate(trpc_get_conn(trpc), trpc_get_server(trpc), trpc_get_port(trpc));
173 /* simple function, based on tidc_send_req */
174 TRP_RC trpc_send_msg (TRPC_INSTANCE *trpc,
175 const char *msg_content)
178 TRP_RC rc=TRP_SUCCESS;
180 /* Send the request over the connection */
181 if (err = gsscon_write_encrypted_token(trp_connection_get_fd(trpc_get_conn(trpc)),
182 *trp_connection_get_gssctx(trpc_get_conn(trpc)),
184 strlen(msg_content))) {
185 tr_err( "trpc_send_msg: Error sending message over connection.\n");