This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tytab
in repository terminology.

View the commit online.

commit 3c9ed008f01dce6e12e8c9e7248db06161aca39f
Author: [email protected] <[email protected]>
AuthorDate: Mon Mar 30 09:58:35 2026 -0600

    refactor: extract shared tytab_ipc module
    
    Move the tytab IPC protocol (hash computation, struct definitions, Eet
    descriptor setup) into tytab_ipc.c/h, shared by both terminology and
    tytab binaries. Eliminates duplicated types, Eet descriptors, and hash
    function across ipc.c, tytab.c, and tycommon.c.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---
 src/bin/ipc.c       | 78 +++++-----------------------------------------
 src/bin/ipc.h       | 21 -------------
 src/bin/meson.build |  6 ++--
 src/bin/tycommon.c  | 28 -----------------
 src/bin/tycommon.h  |  1 -
 src/bin/tytab.c     | 70 +++++------------------------------------
 src/bin/tytab_ipc.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/tytab_ipc.h | 30 ++++++++++++++++++
 8 files changed, 138 insertions(+), 185 deletions(-)

diff --git a/src/bin/ipc.c b/src/bin/ipc.c
index d70001d8..a5d9af30 100644
--- a/src/bin/ipc.c
+++ b/src/bin/ipc.c
@@ -5,6 +5,7 @@
 #include <Ecore_Ipc.h>
 #include <Eet.h>
 #include "ipc.h"
+#include "tytab_ipc.h"
 
 /* forward declaration to avoid pulling in win.h (which requires Elementary headers) */
 char *tab_nonce_register(unsigned int term_id, const char *name,
@@ -17,8 +18,6 @@ static Ecore_Ipc_Server *ipc = NULL;
 static Ecore_Event_Handler *hnd_data = NULL;
 static void (*func_new_inst) (Ipc_Instance *inst) = NULL;
 static Eet_Data_Descriptor *new_inst_edd = NULL;
-static Eet_Data_Descriptor *tab_req_edd = NULL;
-static Eet_Data_Descriptor *tab_rep_edd = NULL;
 
 static Eina_Bool
 _ipc_cb_client_data(void *_data EINA_UNUSED,
@@ -50,7 +49,8 @@ _ipc_cb_client_data(void *_data EINA_UNUSED,
      {
         Ipc_Tab_Request *req;
 
-        req = eet_data_descriptor_decode(tab_req_edd, e->data, e->size);
+        req = eet_data_descriptor_decode(tytab_ipc_req_edd_get(),
+                                           e->data, e->size);
         if (req)
           {
              Ipc_Tab_Reply rep = { .nonce_str = "0" };
@@ -60,8 +60,8 @@ _ipc_cb_client_data(void *_data EINA_UNUSED,
                rep.nonce_str = nonce_s;
 
              int rep_size = 0;
-             void *rep_data = eet_data_descriptor_encode(tab_rep_edd,
-                                                         &rep, &rep_size);
+             void *rep_data = eet_data_descriptor_encode(
+                                  tytab_ipc_rep_edd_get(), &rep, &rep_size);
              if (rep_data)
                {
                   ecore_ipc_client_send(e->client,
@@ -77,72 +77,10 @@ _ipc_cb_client_data(void *_data EINA_UNUSED,
    return ECORE_CALLBACK_PASS_ON;
 }
 
-void
-ipc_tab_init(void)
-{
-   Eet_Data_Descriptor_Class eddc;
-
-   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
-                                             "tab_req",
-                                             sizeof(Ipc_Tab_Request));
-   tab_req_edd = eet_data_descriptor_stream_new(&eddc);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(tab_req_edd, Ipc_Tab_Request,
-                                 "term_id", term_id, EET_T_UINT);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(tab_req_edd, Ipc_Tab_Request,
-                                 "name", name, EET_T_STRING);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(tab_req_edd, Ipc_Tab_Request,
-                                 "cmd", cmd, EET_T_STRING);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(tab_req_edd, Ipc_Tab_Request,
-                                 "direction", direction, EET_T_STRING);
-
-   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
-                                             "tab_rep",
-                                             sizeof(Ipc_Tab_Reply));
-   tab_rep_edd = eet_data_descriptor_stream_new(&eddc);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(tab_rep_edd, Ipc_Tab_Reply,
-                                 "nonce_str", nonce_str, EET_T_STRING);
-}
-
-void
-ipc_tab_shutdown(void)
-{
-   if (tab_req_edd)
-     {
-        eet_data_descriptor_free(tab_req_edd);
-        tab_req_edd = NULL;
-     }
-   if (tab_rep_edd)
-     {
-        eet_data_descriptor_free(tab_rep_edd);
-        tab_rep_edd = NULL;
-     }
-}
-
 static char *
 _ipc_hash_get(void)
 {
-   char buf[1024], hash[64];
-   const char *disp, *session, *xdg_session, *xdg_id, *xdg_seat, *xdg_vt;
-   int h;
-
-   disp = getenv("DISPLAY");
-   if (!disp) disp = "-unknown-";
-   session = getenv("DBUS_SESSION_BUS_ADDRESS");
-   if (!session) session = ":unknown:";
-   xdg_session = getenv("XDG_SESSION_COOKIE");
-   if (!xdg_session) xdg_session = "/unknown/";
-   xdg_id = getenv("XDG_SESSION_ID");
-   if (!xdg_id) xdg_id = "=unknown=";
-   xdg_seat = getenv("XDG_SEAT");
-   if (!xdg_seat) xdg_seat = "@unknown@";
-   xdg_vt = getenv("XDG_VTNR");
-   if (!xdg_vt) xdg_vt = "!unknown!";
-   snprintf(buf, sizeof(buf), "%s.%s.%s.%s.%s.%s",
-            disp, session, xdg_session,
-            xdg_id, xdg_seat, xdg_vt);
-   h = eina_hash_superfast(buf, strlen(buf));
-   snprintf(hash, sizeof(hash), "terminology-%08x", (unsigned int)h);
-   return strdup(hash);
+   return tytab_ipc_hash_get();
 }
 
 void
@@ -216,7 +154,7 @@ ipc_init(void)
                                  "cursor_blink", active_links, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(new_inst_edd, Ipc_Instance,
                                  "visual_bell", active_links, EET_T_INT);
-   ipc_tab_init();
+   tytab_ipc_eet_init();
 }
 
 Eina_Bool
@@ -235,7 +173,7 @@ ipc_serve(void)
 void
 ipc_shutdown(void)
 {
-   ipc_tab_shutdown();
+   tytab_ipc_eet_shutdown();
    if (ipc)
      {
         ecore_ipc_server_del(ipc);
diff --git a/src/bin/ipc.h b/src/bin/ipc.h
index e0e2fd55..f9b43305 100644
--- a/src/bin/ipc.h
+++ b/src/bin/ipc.h
@@ -45,25 +45,4 @@ void ipc_instance_new_func_set(void (*func) (Ipc_Instance *inst));
 Eina_Bool ipc_instance_add(Ipc_Instance *inst);
 void ipc_instance_conn_free(void);
 
-#define TY_IPC_MAJOR_TAB  4
-#define TY_IPC_MINOR_TAB  1
-
-typedef struct _Ipc_Tab_Request Ipc_Tab_Request;
-struct _Ipc_Tab_Request
-{
-   unsigned int term_id;
-   char *name;
-   char *cmd;
-   char *direction; /* "l","r","t","b" or "" — Eet needs string, not char */
-};
-
-typedef struct _Ipc_Tab_Reply Ipc_Tab_Reply;
-struct _Ipc_Tab_Reply
-{
-   char *nonce_str; /* decimal string of uint64, "0" = rejected */
-};
-
-void ipc_tab_init(void);
-void ipc_tab_shutdown(void);
-
 #endif
diff --git a/src/bin/meson.build b/src/bin/meson.build
index b91324f5..67f2d743 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -39,7 +39,8 @@ terminology_sources = ['private.h',
                        'extns.c', 'extns.h',
                        'gravatar.c', 'gravatar.h',
                        'tty_keys.h',
-                       'sb.c', 'sb.h']
+                       'sb.c', 'sb.h',
+                       'tytab_ipc.c', 'tytab_ipc.h']
 
 tybg_sources = ['tycommon.c', 'tycommon.h', 'tybg.c']
 tyalpha_sources = ['tycommon.c', 'tycommon.h', 'tyalpha.c']
@@ -48,7 +49,8 @@ tyq_sources = ['tycommon.c', 'tycommon.h', 'tyq.c']
 tycat_sources = ['tycommon.c', 'tycommon.h', 'tycat.c', 'extns.c', 'extns.h']
 tyls_sources = ['extns.c', 'extns.h', 'tyls.c', 'tycommon.c', 'tycommon.h']
 tysend_sources = ['tycommon.c', 'tycommon.h', 'tysend.c']
-tytab_sources = ['tycommon.c', 'tycommon.h', 'tytab.c']
+tytab_sources = ['tycommon.c', 'tycommon.h', 'tytab.c',
+                  'tytab_ipc.c', 'tytab_ipc.h']
 tyfuzz_sources = ['termptyesc.c', 'termptyesc.h',
                   'backlog.c', 'backlog.h',
                   'termptyops.c', 'termptyops.h',
diff --git a/src/bin/tycommon.c b/src/bin/tycommon.c
index d8ea40ac..7503eeaa 100644
--- a/src/bin/tycommon.c
+++ b/src/bin/tycommon.c
@@ -1,5 +1,4 @@
 #include "private.h"
-#include <Eina.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -115,33 +114,6 @@ end:
    return res;
 }
 
-char *
-ipc_hash_get(void)
-{
-   char buf[1024], hash[64];
-   const char *disp, *session, *xdg_session, *xdg_id, *xdg_seat, *xdg_vt;
-   int h;
-
-   disp = getenv("DISPLAY");
-   if (!disp) disp = "-unknown-";
-   session = getenv("DBUS_SESSION_BUS_ADDRESS");
-   if (!session) session = ":unknown:";
-   xdg_session = getenv("XDG_SESSION_COOKIE");
-   if (!xdg_session) xdg_session = "/unknown/";
-   xdg_id = getenv("XDG_SESSION_ID");
-   if (!xdg_id) xdg_id = "=unknown=";
-   xdg_seat = getenv("XDG_SEAT");
-   if (!xdg_seat) xdg_seat = "@unknown@";
-   xdg_vt = getenv("XDG_VTNR");
-   if (!xdg_vt) xdg_vt = "!unknown!";
-   snprintf(buf, sizeof(buf), "%s.%s.%s.%s.%s.%s",
-            disp, session, xdg_session,
-            xdg_id, xdg_seat, xdg_vt);
-   h = eina_hash_superfast(buf, strlen(buf));
-   snprintf(hash, sizeof(hash), "terminology-%08x", (unsigned int)h);
-   return strdup(hash);
-}
-
 ssize_t
 ty_write(int fd, const void *buf, size_t count)
 {
diff --git a/src/bin/tycommon.h b/src/bin/tycommon.h
index 81f38c2e..69b9fcb9 100644
--- a/src/bin/tycommon.h
+++ b/src/bin/tycommon.h
@@ -1,7 +1,6 @@
 #ifndef TERMINOLOGY_TY_COMMON_H_
 #define TERMINOLOGY_TY_COMMON_H_ 1
 
-char *ipc_hash_get(void);
 int expect_running_in_terminology(void);
 ssize_t ty_write(int fd, const void *buf, size_t count);
 
diff --git a/src/bin/tytab.c b/src/bin/tytab.c
index 78877d3a..34fc5e08 100644
--- a/src/bin/tytab.c
+++ b/src/bin/tytab.c
@@ -6,63 +6,7 @@
 #include <Eet.h>
 #include "private.h"
 #include "tycommon.h"
-
-/* Tab IPC protocol types — must match ipc.h/ipc.c definitions */
-#define TY_IPC_MAJOR_TAB  4
-#define TY_IPC_MINOR_TAB  1
-
-typedef struct _Ipc_Tab_Request Ipc_Tab_Request;
-struct _Ipc_Tab_Request
-{
-   unsigned int term_id;
-   char *name;
-   char *cmd;
-   char *direction;
-};
-
-typedef struct _Ipc_Tab_Reply Ipc_Tab_Reply;
-struct _Ipc_Tab_Reply
-{
-   char *nonce_str;
-};
-
-static Eet_Data_Descriptor *_tab_req_edd = NULL;
-static Eet_Data_Descriptor *_tab_rep_edd = NULL;
-
-static void
-_eet_init(void)
-{
-   Eet_Data_Descriptor_Class eddc;
-
-   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
-                                             "tab_req",
-                                             sizeof(Ipc_Tab_Request));
-   _tab_req_edd = eet_data_descriptor_stream_new(&eddc);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
-                                 "term_id", term_id, EET_T_UINT);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
-                                 "name", name, EET_T_STRING);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
-                                 "cmd", cmd, EET_T_STRING);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
-                                 "direction", direction, EET_T_STRING);
-
-   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
-                                             "tab_rep",
-                                             sizeof(Ipc_Tab_Reply));
-   _tab_rep_edd = eet_data_descriptor_stream_new(&eddc);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_rep_edd, Ipc_Tab_Reply,
-                                 "nonce_str", nonce_str, EET_T_STRING);
-}
-
-static void
-_eet_shutdown(void)
-{
-   if (_tab_req_edd) eet_data_descriptor_free(_tab_req_edd);
-   if (_tab_rep_edd) eet_data_descriptor_free(_tab_rep_edd);
-   _tab_req_edd = NULL;
-   _tab_rep_edd = NULL;
-}
+#include "tytab_ipc.h"
 
 static void
 print_usage(const char *argv0)
@@ -143,7 +87,7 @@ _cb_server_data(void *_data EINA_UNUSED,
      {
         Ipc_Tab_Reply *rep;
 
-        rep = eet_data_descriptor_decode(_tab_rep_edd, e->data, e->size);
+        rep = eet_data_descriptor_decode(tytab_ipc_rep_edd_get(), e->data, e->size);
         if (rep)
           {
              if (rep->nonce_str && strcmp(rep->nonce_str, "0") != 0)
@@ -187,7 +131,7 @@ _request_nonce(unsigned int term_id, const char *name,
    void *data;
    int size;
 
-   hash = ipc_hash_get();
+   hash = tytab_ipc_hash_get();
    if (!hash) return NULL;
 
    srv = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, hash, 0, NULL);
@@ -209,7 +153,7 @@ _request_nonce(unsigned int term_id, const char *name,
      req.direction = "";
    req.cmd = (char *)cmd_str;
 
-   data = "" &req, &size);
+   data = "" &req, &size);
    if (!data)
      {
         ecore_ipc_server_del(srv);
@@ -330,14 +274,14 @@ main(int argc, char **argv)
         ecore_init();
         ecore_ipc_init();
         eet_init();
-        _eet_init();
+        tytab_ipc_eet_init();
 
         nonce = _request_nonce(term_id, name ? name : "",
                                dir, cmdbuf[0] ? cmdbuf : "");
         if (!nonce)
           {
              fprintf(stderr, "tytab: request rejected by terminology\n");
-             _eet_shutdown();
+             tytab_ipc_eet_shutdown();
              eet_shutdown();
              ecore_ipc_shutdown();
              ecore_shutdown();
@@ -350,7 +294,7 @@ main(int argc, char **argv)
           perror("write");
 
         free(nonce);
-        _eet_shutdown();
+        tytab_ipc_eet_shutdown();
         eet_shutdown();
         ecore_ipc_shutdown();
         ecore_shutdown();
diff --git a/src/bin/tytab_ipc.c b/src/bin/tytab_ipc.c
new file mode 100644
index 00000000..5f69954a
--- /dev/null
+++ b/src/bin/tytab_ipc.c
@@ -0,0 +1,89 @@
+#include <Eina.h>
+#include <Eet.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "tytab_ipc.h"
+
+static Eet_Data_Descriptor *_tab_req_edd = NULL;
+static Eet_Data_Descriptor *_tab_rep_edd = NULL;
+
+char *
+tytab_ipc_hash_get(void)
+{
+   char buf[1024], hash[64];
+   const char *disp, *session, *xdg_session, *xdg_id, *xdg_seat, *xdg_vt;
+   int h;
+
+   disp = getenv("DISPLAY");
+   if (!disp) disp = "-unknown-";
+   session = getenv("DBUS_SESSION_BUS_ADDRESS");
+   if (!session) session = ":unknown:";
+   xdg_session = getenv("XDG_SESSION_COOKIE");
+   if (!xdg_session) xdg_session = "/unknown/";
+   xdg_id = getenv("XDG_SESSION_ID");
+   if (!xdg_id) xdg_id = "=unknown=";
+   xdg_seat = getenv("XDG_SEAT");
+   if (!xdg_seat) xdg_seat = "@unknown@";
+   xdg_vt = getenv("XDG_VTNR");
+   if (!xdg_vt) xdg_vt = "!unknown!";
+   snprintf(buf, sizeof(buf), "%s.%s.%s.%s.%s.%s",
+            disp, session, xdg_session,
+            xdg_id, xdg_seat, xdg_vt);
+   h = eina_hash_superfast(buf, strlen(buf));
+   snprintf(hash, sizeof(hash), "terminology-%08x", (unsigned int)h);
+   return strdup(hash);
+}
+
+void
+tytab_ipc_eet_init(void)
+{
+   Eet_Data_Descriptor_Class eddc;
+
+   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
+                                             "tab_req",
+                                             sizeof(Ipc_Tab_Request));
+   _tab_req_edd = eet_data_descriptor_stream_new(&eddc);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
+                                 "term_id", term_id, EET_T_UINT);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
+                                 "name", name, EET_T_STRING);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
+                                 "cmd", cmd, EET_T_STRING);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_req_edd, Ipc_Tab_Request,
+                                 "direction", direction, EET_T_STRING);
+
+   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc),
+                                             "tab_rep",
+                                             sizeof(Ipc_Tab_Reply));
+   _tab_rep_edd = eet_data_descriptor_stream_new(&eddc);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_tab_rep_edd, Ipc_Tab_Reply,
+                                 "nonce_str", nonce_str, EET_T_STRING);
+}
+
+void
+tytab_ipc_eet_shutdown(void)
+{
+   if (_tab_req_edd)
+     {
+        eet_data_descriptor_free(_tab_req_edd);
+        _tab_req_edd = NULL;
+     }
+   if (_tab_rep_edd)
+     {
+        eet_data_descriptor_free(_tab_rep_edd);
+        _tab_rep_edd = NULL;
+     }
+}
+
+Eet_Data_Descriptor *
+tytab_ipc_req_edd_get(void)
+{
+   return _tab_req_edd;
+}
+
+Eet_Data_Descriptor *
+tytab_ipc_rep_edd_get(void)
+{
+   return _tab_rep_edd;
+}
diff --git a/src/bin/tytab_ipc.h b/src/bin/tytab_ipc.h
new file mode 100644
index 00000000..754d905e
--- /dev/null
+++ b/src/bin/tytab_ipc.h
@@ -0,0 +1,30 @@
+#ifndef TERMINOLOGY_TYTAB_IPC_H_
+#define TERMINOLOGY_TYTAB_IPC_H_ 1
+
+#include <Eet.h>
+
+#define TY_IPC_MAJOR_TAB  4
+#define TY_IPC_MINOR_TAB  1
+
+typedef struct _Ipc_Tab_Request Ipc_Tab_Request;
+struct _Ipc_Tab_Request
+{
+   unsigned int term_id;
+   char *name;
+   char *cmd;
+   char *direction; /* "l","r","t","b" or "" — Eet needs string, not char */
+};
+
+typedef struct _Ipc_Tab_Reply Ipc_Tab_Reply;
+struct _Ipc_Tab_Reply
+{
+   char *nonce_str; /* decimal string of uint64, "0" = rejected */
+};
+
+char *tytab_ipc_hash_get(void);
+void  tytab_ipc_eet_init(void);
+void  tytab_ipc_eet_shutdown(void);
+Eet_Data_Descriptor *tytab_ipc_req_edd_get(void);
+Eet_Data_Descriptor *tytab_ipc_rep_edd_get(void);
+
+#endif

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to