Commit e80e008a94a7248cf6baad861f3f21ecda38cdc2
1 parent
ea4bb503
Exists in
master
and in
1 other branch
Working on IPC module for windows.
Showing
11 changed files
with
100 additions
and
45 deletions
Show diff stats
client/src/core/windows/request.cc
client/src/core/windows/session.cc
client/src/session/local/events.cc
... | ... | @@ -36,8 +36,9 @@ |
36 | 36 | * |
37 | 37 | */ |
38 | 38 | |
39 | + #include <config.h> | |
40 | + #include <cstdio> | |
39 | 41 | #include <ipc-client-internals.h> |
40 | - #include <stdio.h> | |
41 | 42 | #include <cstring> |
42 | 43 | #include <malloc.h> |
43 | 44 | |
... | ... | @@ -50,17 +51,17 @@ |
50 | 51 | |
51 | 52 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
52 | 53 | |
53 | -#ifndef HAVE_VASPRINTF | |
54 | - int vasprintf(char **strp, const char *fmt, va_list ap) { | |
54 | +#ifdef _WIN32 | |
55 | + int win32_vasprintf(char **strp, const char *fmt, va_list ap) { | |
55 | 56 | char buf[1024]; |
56 | 57 | |
57 | 58 | int nc = vsnprintf(buf, sizeof(buf), fmt, ap); |
58 | 59 | |
59 | 60 | if(nc < 0) { |
60 | 61 | |
61 | - *strp = strdup(_("Error in vasprintf")); | |
62 | + return nc; | |
62 | 63 | |
63 | - } else if (nc < sizeof(buf)) { | |
64 | + } else if (nc < ((int) sizeof(buf))) { | |
64 | 65 | |
65 | 66 | *strp = (char *) malloc(nc+1); |
66 | 67 | strcpy(*strp, buf); |
... | ... | @@ -77,7 +78,7 @@ |
77 | 78 | |
78 | 79 | return nc; |
79 | 80 | } |
80 | -#endif // !HAVE_VASPRINTF | |
81 | +#endif // _WIN32 | |
81 | 82 | |
82 | 83 | namespace TN3270 { |
83 | 84 | |
... | ... | @@ -105,10 +106,17 @@ |
105 | 106 | this->msg = msg; |
106 | 107 | |
107 | 108 | char * buffer = NULL; |
109 | +#ifdef _WIN32 | |
110 | + if(win32_vasprintf(&buffer,fmt,arg) != -1) { | |
111 | + this->description = buffer; | |
112 | + free(buffer); | |
113 | + } | |
114 | +#else | |
108 | 115 | if(vasprintf(&buffer,fmt,arg) != -1) { |
109 | 116 | this->description = buffer; |
110 | 117 | free(buffer); |
111 | 118 | } |
119 | +#endif | |
112 | 120 | |
113 | 121 | #ifdef DEBUG |
114 | 122 | std::cerr << "Popup:" << std::endl | ... | ... |
common/src/include/lib3270/ipc-glib.h
... | ... | @@ -85,6 +85,8 @@ |
85 | 85 | const gchar * ipc3270_get_display_charset(GObject *object); |
86 | 86 | H3270 * ipc3270_get_session(GObject *object); |
87 | 87 | |
88 | + GQuark ipc3270_get_error_domain(GObject *object); | |
89 | + | |
88 | 90 | void ipc3270_set_error(GObject *object, int errcode, GError **error); |
89 | 91 | |
90 | 92 | GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *parameters, GError **error); | ... | ... |
server/src/core/linux/gobject.c
... | ... | @@ -225,3 +225,8 @@ H3270 * ipc3270_get_session(GObject *object) { |
225 | 225 | void ipc3270_set_error(GObject *object, int errcode, GError **error) { |
226 | 226 | g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); |
227 | 227 | } |
228 | + | |
229 | +GQuark ipc3270_get_error_domain(GObject *object) { | |
230 | + return IPC3270(object)->error_domain; | |
231 | +} | |
232 | + | ... | ... |
server/src/core/methods.c
... | ... | @@ -72,7 +72,7 @@ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVaria |
72 | 72 | |
73 | 73 | // Suceeded |
74 | 74 | debug("%s Suceeds",method_name); |
75 | - return g_variant_new("(i)", (gint) 0); | |
75 | + return g_variant_new_int32(0); | |
76 | 76 | |
77 | 77 | } |
78 | 78 | else if(!g_ascii_strcasecmp(method_name,"setStringAt")) |
... | ... | @@ -90,7 +90,7 @@ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVaria |
90 | 90 | } |
91 | 91 | |
92 | 92 | // Suceeded |
93 | - return g_variant_new("(i)", (gint) 0); | |
93 | + return g_variant_new_int32(0); | |
94 | 94 | |
95 | 95 | } |
96 | 96 | else if(!g_ascii_strcasecmp(method_name,"getStringAt")) |
... | ... | @@ -117,7 +117,7 @@ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVaria |
117 | 117 | } |
118 | 118 | |
119 | 119 | // Suceeded |
120 | - return g_variant_new("(i)", (gint) 0); | |
120 | + return g_variant_new_int32(0); | |
121 | 121 | |
122 | 122 | } |
123 | 123 | else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress")) |
... | ... | @@ -134,8 +134,10 @@ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVaria |
134 | 134 | else if(!g_ascii_strcasecmp(method_name,"waitforready")) |
135 | 135 | { |
136 | 136 | guint timeout = 1; |
137 | - g_variant_get(parameters, "(u)", &timeout); | |
138 | - return g_variant_new("(i)", (gint) lib3270_wait_for_ready(hSession,timeout)); | |
137 | + if(parameters) { | |
138 | + g_variant_get(parameters, "(u)", &timeout); | |
139 | + } | |
140 | + return g_variant_new_int32((gint) lib3270_wait_for_ready(hSession,timeout)); | |
139 | 141 | } |
140 | 142 | |
141 | 143 | // Check action table. |
... | ... | @@ -153,7 +155,7 @@ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVaria |
153 | 155 | } |
154 | 156 | |
155 | 157 | // Suceeded |
156 | - return g_variant_new("(i)", (gint) 0); | |
158 | + return g_variant_new_int32(0); | |
157 | 159 | |
158 | 160 | } |
159 | 161 | } |
... | ... | @@ -177,7 +179,7 @@ GVariant * ipc3270_method_call(GObject *object, const gchar *method_name, GVaria |
177 | 179 | } |
178 | 180 | |
179 | 181 | // Suceeded |
180 | - return g_variant_new("(i)", (gint) 0); | |
182 | + return g_variant_new_int32(0); | |
181 | 183 | |
182 | 184 | } |
183 | 185 | ... | ... |
server/src/core/setproperties.c
... | ... | @@ -44,6 +44,11 @@ gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVari |
44 | 44 | size_t ix; |
45 | 45 | H3270 * hSession = ipc3270_get_session(object); |
46 | 46 | |
47 | + if(!value) { | |
48 | + g_set_error(&error,ipc3270_get_error_domain(object),EINVAL,"Set property method requires an argument"); | |
49 | + return FALSE; | |
50 | + } | |
51 | + | |
47 | 52 | lib3270_trace_event(hSession,"SetProperty(%s) called on session %c\n",property_name,lib3270_get_session_id(hSession)); |
48 | 53 | |
49 | 54 | // Boolean properties | ... | ... |
server/src/core/windows/gobject.c
... | ... | @@ -90,3 +90,7 @@ void ipc3270_set_error(GObject *object, int errcode, GError **error) { |
90 | 90 | g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); |
91 | 91 | } |
92 | 92 | |
93 | +GQuark ipc3270_get_error_domain(GObject *object) { | |
94 | + return IPC3270(object)->error_domain; | |
95 | +} | |
96 | + | ... | ... |
server/src/core/windows/inout.c
... | ... | @@ -85,65 +85,70 @@ static unsigned char * setup_header(unsigned char *txtptr, const gchar *name, in |
85 | 85 | |
86 | 86 | unsigned char * pack_value(unsigned char *txtptr, GVariant *value) { |
87 | 87 | |
88 | - unsigned char type = (unsigned char) g_variant_get_type_string(value)[0]; | |
88 | + const GVariantType *type = g_variant_get_type(value); | |
89 | 89 | |
90 | - debug("%s type=%c",__FUNCTION__,type); | |
90 | + if(g_variant_type_equal(type,G_VARIANT_TYPE_STRING)) { | |
91 | 91 | |
92 | - *(txtptr++) = type; | |
93 | - | |
94 | - switch(type) { | |
95 | - // https://developer.gnome.org/glib/stable/gvariant-format-strings.html | |
96 | - case 's': | |
92 | + *(txtptr++) = 's'; | |
97 | 93 | strcpy((char *) txtptr,g_variant_get_string(value,NULL)); |
98 | 94 | txtptr += (strlen((char *) txtptr)+1); |
99 | - break; | |
100 | 95 | |
101 | - case 'b': // gboolean | |
96 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_BOOLEAN)) { | |
97 | + | |
98 | + *(txtptr++) = 'b'; | |
102 | 99 | *(txtptr++) = g_variant_get_boolean(value) ? 1 : 0; |
103 | - break; | |
104 | 100 | |
105 | - case 'y': // guchar | |
101 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_BYTE)) { | |
102 | + | |
103 | + *(txtptr++) = 'y'; | |
106 | 104 | *(txtptr++) = g_variant_get_byte(value); |
107 | - break; | |
108 | 105 | |
109 | - case 'n': // gint16 | |
106 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_INT16)) { | |
107 | + | |
108 | + *(txtptr++) = 'n'; | |
110 | 109 | *((gint16 *) txtptr) = g_variant_get_int16(value); |
111 | 110 | txtptr += sizeof(gint16); |
112 | - break; | |
113 | 111 | |
114 | - case 'q': // guint16 | |
112 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_UINT16)) { | |
113 | + | |
114 | + *(txtptr++) = 'q'; | |
115 | 115 | *((guint16 *) txtptr) = g_variant_get_uint16(value); |
116 | 116 | txtptr += sizeof(guint16); |
117 | - break; | |
118 | 117 | |
119 | - case 'i': // gint32 | |
120 | - case 'h': // gint32 | |
118 | + } else if(g_variant_type_is_subtype_of(type,G_VARIANT_TYPE_INT32)) { | |
119 | + | |
120 | + *(txtptr++) = 'i'; | |
121 | 121 | *((gint32 *) txtptr) = g_variant_get_int32(value); |
122 | 122 | txtptr += sizeof(gint32); |
123 | - break; | |
124 | 123 | |
125 | - case 'u': // guint32 | |
124 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_UINT32)) { | |
125 | + | |
126 | + *(txtptr++) = 'u'; | |
126 | 127 | *((guint32 *) txtptr) = g_variant_get_uint32(value); |
127 | 128 | txtptr += sizeof(guint32); |
128 | - break; | |
129 | 129 | |
130 | - case 'x': // gint64 | |
130 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_INT64)) { | |
131 | + | |
132 | + *(txtptr++) = 'x'; | |
131 | 133 | *((gint64 *) txtptr) = g_variant_get_int64(value); |
132 | 134 | txtptr += sizeof(gint64); |
133 | - break; | |
134 | 135 | |
135 | - case 't': // guint64 | |
136 | + } else if(g_variant_type_equal(type,G_VARIANT_TYPE_UINT64)) { | |
137 | + | |
138 | + *(txtptr++) = 't'; | |
136 | 139 | *((guint64 *) txtptr) = g_variant_get_uint64(value); |
137 | 140 | txtptr += sizeof(guint64); |
138 | - break; | |
139 | 141 | |
140 | - default: | |
142 | + } else { | |
143 | + | |
141 | 144 | errno = EINVAL; |
145 | + g_message("Invalid IPC value type \"%s\"", g_variant_get_type_string(value)); | |
142 | 146 | return NULL; |
143 | 147 | |
144 | 148 | } |
145 | 149 | |
146 | 150 | return txtptr; |
151 | + | |
147 | 152 | } |
148 | 153 | |
149 | 154 | unsigned char * ipc3270_pack_value(const gchar *name, int id, GVariant *value, size_t * szPacket) { | ... | ... |
server/src/core/windows/pipesource.c
... | ... | @@ -108,10 +108,6 @@ static void process_input(IPC3270_PIPE_SOURCE *source, DWORD cbRead) { |
108 | 108 | g_autoptr (GVariant) parameters = ipc3270_unpack(source->buffer, &request_type); |
109 | 109 | g_autoptr (GVariant) response = NULL; |
110 | 110 | |
111 | - if(!parameters) { | |
112 | - g_message("Rejecting invalid request \"%s\"", request_name); | |
113 | - } | |
114 | - | |
115 | 111 | // Process query |
116 | 112 | switch(request_type) { |
117 | 113 | case 1: // getProperty | ... | ... |
server/src/testprogram/testprogram.c
... | ... | @@ -40,6 +40,8 @@ |
40 | 40 | #include <lib3270/ipc-glib.h> |
41 | 41 | #include <string.h> |
42 | 42 | #include <stdlib.h> |
43 | + #include <glib.h> | |
44 | + #include <glib/gstdio.h> | |
43 | 45 | |
44 | 46 | /*---[ Globals ]------------------------------------------------------------------------------------*/ |
45 | 47 | |
... | ... | @@ -158,6 +160,32 @@ |
158 | 160 | |
159 | 161 | gtk_widget_set_name(window,session_name); |
160 | 162 | |
163 | +#ifdef _WIN32 | |
164 | + { | |
165 | + // WIN32 path settings. | |
166 | + static const char * sep = "\\/."; | |
167 | + | |
168 | + TCHAR szPath[MAX_PATH]; | |
169 | + | |
170 | + if(GetModuleFileName(NULL, szPath, MAX_PATH ) ) { | |
171 | + | |
172 | + for(const char *p = sep; *p; p++) { | |
173 | + | |
174 | + char *ptr = strrchr(szPath,*p); | |
175 | + if(ptr) { | |
176 | + *(ptr+1) = 0; | |
177 | + break; | |
178 | + } | |
179 | + | |
180 | + } | |
181 | + | |
182 | + } | |
183 | + | |
184 | + g_chdir(szPath); | |
185 | + | |
186 | + } | |
187 | +#endif // _WIN32 | |
188 | + | |
161 | 189 | // Setup tabs |
162 | 190 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new(v3270_get_session_name(terminal))); |
163 | 191 | ... | ... |