[BACK]Return to client-fn.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/client-fn.c, Revision 1.1

1.1     ! nicm        1: /* $OpenBSD$ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
        !             5:  *
        !             6:  * Permission to use, copy, modify, and distribute this software for any
        !             7:  * purpose with or without fee is hereby granted, provided that the above
        !             8:  * copyright notice and this permission notice appear in all copies.
        !             9:  *
        !            10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
        !            15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
        !            16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            17:  */
        !            18:
        !            19: #include <sys/types.h>
        !            20:
        !            21: #include <stdlib.h>
        !            22: #include <string.h>
        !            23:
        !            24: #include "tmux.h"
        !            25:
        !            26: void
        !            27: client_fill_session(struct msg_command_data *data)
        !            28: {
        !            29:        char            *env, *ptr1, *ptr2, buf[256];
        !            30:        size_t           len;
        !            31:        const char      *errstr;
        !            32:        long long        ll;
        !            33:
        !            34:        data->pid = -1;
        !            35:        if ((env = getenv("TMUX")) == NULL)
        !            36:                return;
        !            37:
        !            38:        if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
        !            39:                return;
        !            40:        for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
        !            41:                ;
        !            42:        if (*ptr1 != ',')
        !            43:                return;
        !            44:        ptr1++;
        !            45:        ptr2++;
        !            46:
        !            47:        len = ptr2 - ptr1 - 1;
        !            48:        if (len > (sizeof buf) - 1)
        !            49:                return;
        !            50:        memcpy(buf, ptr1, len);
        !            51:        buf[len] = '\0';
        !            52:
        !            53:        ll = strtonum(buf, 0, LONG_MAX, &errstr);
        !            54:        if (errstr != NULL)
        !            55:                return;
        !            56:        data->pid = ll;
        !            57:
        !            58:        ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
        !            59:        if (errstr != NULL)
        !            60:                return;
        !            61:        data->idx = ll;
        !            62: }
        !            63:
        !            64: void
        !            65: client_write_server(
        !            66:     struct client_ctx *cctx, enum hdrtype type, void *buf, size_t len)
        !            67: {
        !            68:        struct hdr      hdr;
        !            69:
        !            70:        hdr.type = type;
        !            71:        hdr.size = len;
        !            72:        buffer_write(cctx->srv_out, &hdr, sizeof hdr);
        !            73:
        !            74:        if (buf != NULL && len > 0)
        !            75:                buffer_write(cctx->srv_out, buf, len);
        !            76: }
        !            77:
        !            78: void
        !            79: client_write_server2(struct client_ctx *cctx,
        !            80:     enum hdrtype type, void *buf1, size_t len1, void *buf2, size_t len2)
        !            81: {
        !            82:        struct hdr      hdr;
        !            83:
        !            84:        hdr.type = type;
        !            85:        hdr.size = len1 + len2;
        !            86:        buffer_write(cctx->srv_out, &hdr, sizeof hdr);
        !            87:
        !            88:        if (buf1 != NULL && len1 > 0)
        !            89:                buffer_write(cctx->srv_out, buf1, len1);
        !            90:        if (buf2 != NULL && len2 > 0)
        !            91:                buffer_write(cctx->srv_out, buf2, len2);
        !            92: }