void owl_zephyr_initialize() { int ret; struct servent *sp; struct sockaddr_in sin; ZNotice_t req; Code_t code; owl_dispatch *dispatch; /* * Code modified from libzephyr's ZhmStat.c * * Modified to add the fd to our select loop, rather than hanging * until we get an ack. */ if ((ret = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Error opening Zephyr port: %s", error_message(ret)); return; } (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in)); sp = getservbyname(HM_SVCNAME, "udp"); sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); (void) memset((char *)&req, 0, sizeof(req)); req.z_kind = STAT; req.z_port = 0; req.z_class = HM_STAT_CLASS; req.z_class_inst = HM_STAT_CLIENT; req.z_opcode = HM_GIMMESTATS; req.z_sender = ""; req.z_recipient = ""; req.z_default_format = ""; req.z_message_len = 0; if ((code = ZSetDestAddr(&sin)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } dispatch = owl_malloc(sizeof(*dispatch)); dispatch->fd = ZGetFD(); dispatch->cfunc = owl_zephyr_finish_initialization; dispatch->destroy = (void(*)(owl_dispatch*))owl_free; owl_select_add_dispatch(dispatch); }
void owl_zephyr_initialize(void) { Code_t ret; struct servent *sp; struct sockaddr_in sin; ZNotice_t req; GIOChannel *channel; /* * Code modified from libzephyr's ZhmStat.c * * Modified to add the fd to our select loop, rather than hanging * until we get an ack. */ if ((ret = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Error opening Zephyr port: %s", error_message(ret)); return; } (void) memset(&sin, 0, sizeof(struct sockaddr_in)); sp = getservbyname(HM_SVCNAME, "udp"); sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); (void) memset(&req, 0, sizeof(req)); req.z_kind = STAT; req.z_port = 0; req.z_class = zstr(HM_STAT_CLASS); req.z_class_inst = zstr(HM_STAT_CLIENT); req.z_opcode = zstr(HM_GIMMESTATS); req.z_sender = zstr(""); req.z_recipient = zstr(""); req.z_default_format = zstr(""); req.z_message_len = 0; if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(ret)); return; } if ((ret = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(ret)); return; } channel = g_io_channel_unix_new(ZGetFD()); g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP, &owl_zephyr_finish_initialization, NULL); g_io_channel_unref(channel); }
void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) { Code_t code; char *perl; GSource *event_source; owl_select_remove_io_dispatch(d); ZClosePort(); if ((code = ZInitialize()) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } if ((code = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } event_source = owl_zephyr_event_source_new(ZGetFD()); g_source_attach(event_source, NULL); g_source_unref(event_source); owl_global_set_havezephyr(&g); if(g.load_initial_subs) { owl_zephyr_load_initial_subs(); } while(deferred_subs != NULL) { owl_sub_list *subs = deferred_subs->data; owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs); owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs); deferred_subs = g_list_delete_link(deferred_subs, deferred_subs); g_free(subs); } /* zlog in if we need to */ if (owl_global_is_startuplogin(&g)) { owl_function_debugmsg("startup: doing zlog in"); owl_zephyr_zlog_in(); } /* check pseudo-logins if we need to */ if (owl_global_is_pseudologins(&g)) { owl_function_debugmsg("startup: checking pseudo-logins"); owl_function_zephyr_buddy_check(0); } perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()"); g_free(perl); }
int ZPending() { int retval; if (ZGetFD() < 0) { errno = ZERR_NOPORT; return (-1); } if ((retval = Z_ReadEnqueue()) != ZERR_NONE) { errno = retval; return (-1); } return(ZQLength()); }
void owl_zephyr_finish_initialization(owl_dispatch *d) { Code_t code; owl_select_remove_dispatch(d->fd); ZClosePort(); if ((code = ZInitialize()) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } if ((code = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } d = owl_malloc(sizeof(owl_dispatch)); d->fd = ZGetFD(); d->cfunc = &owl_zephyr_process_events; d->destroy = NULL; owl_select_add_dispatch(d); owl_global_set_havezephyr(&g); if(g.load_initial_subs) { owl_zephyr_load_initial_subs(); } while(deferred_subs != NULL) { owl_sub_list *subs = deferred_subs->data; owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs); owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs); deferred_subs = g_list_delete_link(deferred_subs, deferred_subs); owl_free(subs); } /* zlog in if we need to */ if (owl_global_is_startuplogin(&g)) { owl_function_debugmsg("startup: doing zlog in"); owl_zephyr_zlog_in(); } }
Code_t ZRequestLocations(char *user, register ZAsyncLocateData_t *zald, ZNotice_Kind_t kind, /* UNSAFE, UNACKED, or ACKED */ Z_AuthProc auth) { int retval; ZNotice_t notice; if (ZGetFD() < 0) if ((retval = ZOpenPort((u_short *)0)) != ZERR_NONE) return (retval); (void) memset((char *)¬ice, 0, sizeof(notice)); notice.z_kind = kind; notice.z_port = __Zephyr_port; notice.z_class = LOCATE_CLASS; notice.z_class_inst = user; notice.z_opcode = LOCATE_LOCATE; notice.z_sender = 0; notice.z_recipient = ""; notice.z_default_format = ""; notice.z_message_len = 0; if ((retval = ZSendNotice(¬ice, auth)) != ZERR_NONE) return(retval); if ((zald->user = (char *) malloc(strlen(user)+1)) == NULL) { return(ENOMEM); } if ((zald->version = (char *) malloc(strlen(notice.z_version)+1)) == NULL) { free(zald->user); return(ENOMEM); } zald->uid = notice.z_multiuid; strcpy(zald->user,user); strcpy(zald->version,notice.z_version); return(ZERR_NONE); }