-/*
- * what we end up sending to the ssld process for ziplinks is the following
- * Z[ourfd][level][RECVQ]
- * Z = ziplinks command = buf[0]
- * ourfd = Our end of the socketpair = buf[1..4]
- * level = zip level buf[5]
- * recvqlen = our recvq len = buf[6-7]
- * recvq = any data we read prior to starting ziplinks
- */
-void
-start_zlib_session(void *data)
-{
- struct Client *server = (struct Client *) data;
- uint16_t recvqlen;
- uint8_t level;
- void *xbuf;
-
- rb_fde_t *F[2];
- rb_fde_t *xF1, *xF2;
- char *buf;
- void *recvq_start;
-
- size_t hdr = (sizeof(uint8_t) * 2) + sizeof(uint32_t);
- size_t len;
- int cpylen, left;
-
- server->localClient->event = NULL;
-
- recvqlen = rb_linebuf_len(&server->localClient->buf_recvq);
-
- len = recvqlen + hdr;
-
- if(len > READBUF_SIZE)
- {
- sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "ssld - attempted to pass message of %zd len, max len %d, giving up",
- len, READBUF_SIZE);
- ilog(L_MAIN, "ssld - attempted to pass message of %zd len, max len %d, giving up", len, READBUF_SIZE);
- exit_client(server, server, server, "ssld readbuf exceeded");
- return;
- }
-
- buf = rb_malloc(len);
- level = ConfigFileEntry.compression_level;
-
- uint32_to_buf(&buf[1], rb_get_fd(server->localClient->F));
- buf[5] = (char) level;
-
- recvq_start = &buf[6];
- server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats));
-
- xbuf = recvq_start;
- left = recvqlen;
-
- do
- {
- cpylen = rb_linebuf_get(&server->localClient->buf_recvq, xbuf, left, LINEBUF_PARTIAL, LINEBUF_RAW);
- left -= cpylen;
- xbuf = (void *) (((uintptr_t) xbuf) + cpylen);
- }
- while(cpylen > 0);
-
- /* Pass the socket to ssld. */
- *buf = 'Z';
- if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF1, &xF2, "Initial zlib socketpairs") == -1)
- {
- sendto_realops_snomask(SNO_GENERAL, L_ALL, "Error creating zlib socketpair - %s", strerror(errno));
- ilog(L_MAIN, "Error creating zlib socketpairs - %s", strerror(errno));
- exit_client(server, server, server, "Error creating zlib socketpair");
- rb_free(buf);
- return;
- }
-
- F[0] = server->localClient->F;
- F[1] = xF1;
- server->localClient->F = xF2;
- /* need to redo as what we did before isn't valid now */
- uint32_to_buf(&buf[1], connid_get(server));
-
- server->localClient->z_ctl = which_ssld();
- if(!server->localClient->z_ctl)
- {
- exit_client(server, server, server, "Error finding available ssld");
- rb_free(buf);
- return;
- }
- server->localClient->z_ctl->cli_count++;
- ssl_cmd_write_queue(server->localClient->z_ctl, F, 2, buf, len);
- rb_free(buf);
-}
-
-static void
-collect_zipstats(void *unused)
-{
- rb_dlink_node *ptr;
- struct Client *target_p;
- char buf[sizeof(uint8_t) + sizeof(uint32_t) + HOSTLEN];
- void *odata;
- size_t len;
- uint32_t id;
-
- buf[0] = 'S';
- odata = buf + sizeof(uint8_t) + sizeof(uint32_t);
-
- RB_DLINK_FOREACH(ptr, serv_list.head)
- {
- target_p = ptr->data;
- if(IsCapable(target_p, CAP_ZIP))
- {
- len = sizeof(uint8_t) + sizeof(uint32_t);
-
- id = rb_get_fd(target_p->localClient->F);
- uint32_to_buf(&buf[1], id);
- rb_strlcpy(odata, target_p->name, (sizeof(buf) - len));
- len += strlen(odata) + 1; /* Get the \0 as well */
- ssl_cmd_write_queue(target_p->localClient->z_ctl, NULL, 0, buf, len);
- }
- }
-}
-