2 #include <event2/event.h>
9 #include <trp_internal.h>
10 #include <tr_config.h>
15 /* hold a trps instance and a config manager */
16 struct tr_trps_event_cookie {
22 static int tr_trps_req_handler (TRPS_INSTANCE *trps,
29 return -1; /* not handling anything right now */
33 static int tr_trps_gss_handler(gss_name_t client_name, TR_NAME *gss_name,
37 struct tr_trps_event_cookie *cookie=(struct tr_trps_event_cookie *)cookie_in;
38 TRPS_INSTANCE *trps = cookie->trps;
39 TR_CFG_MGR *cfg_mgr = cookie->cfg_mgr;
41 tr_debug("tr_trps_gss_handler()");
43 if ((!client_name) || (!gss_name) || (!trps) || (!cfg_mgr)) {
44 tr_debug("tr_trps_gss_handler: Bad parameters.");
48 /* look up the RP client matching the GSS name */
49 if ((NULL == (rp = tr_rp_client_lookup(cfg_mgr->active->rp_clients, gss_name)))) {
50 tr_debug("tr_trps_gss_handler: Unknown GSS name %s", gss_name->buf);
55 tr_debug("Client's GSS Name: %s", gss_name->buf);
61 /* called when a connection to the TRPS port is received */
62 static void tr_trps_event_cb(int listener, short event, void *arg)
64 TRPS_INSTANCE *trps = (TRPS_INSTANCE *)arg;
67 if (0==(event & EV_READ)) {
68 tr_debug("tr_trps_event_cb: unexpected event on TRPS socket (event=0x%X)", event);
70 conn=trps_accept(trps, listener);
72 /* need to monitor this fd and trigger events when read becomes possible */
78 /* Configure the trps instance and set up its event handler.
79 * Returns 0 on success, nonzero on failure. Fills in
80 * *trps_event (which should be allocated by caller). */
81 int tr_trps_event_init(struct event_base *base,
84 struct tr_socket_event *trps_ev)
86 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
87 struct tr_trps_event_cookie *cookie;
90 if (trps_ev == NULL) {
91 tr_debug("tr_trps_event_init: Null trps_ev.");
96 /* Create the cookie for callbacks. It is part of the trps context, so it will
97 * be cleaned up when trps is freed by talloc_free. */
98 cookie=talloc(tmp_ctx, struct tr_trps_event_cookie);
100 tr_debug("tr_trps_event_init: Unable to allocate cookie.");
105 cookie->cfg_mgr=cfg_mgr;
106 talloc_steal(trps, cookie);
108 /* get a trps listener */
109 trps_ev->sock_fd=trps_get_listener(trps,
112 cfg_mgr->active->internal->hostname,
113 cfg_mgr->active->internal->trps_port,
115 if (trps_ev->sock_fd < 0) {
116 tr_crit("Error opening TRP server socket.");
122 trps_ev->ev=event_new(base,
127 event_add(trps_ev->ev, NULL);
130 talloc_free(tmp_ctx);