qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] PATCH: 2/7: Push VncState struct into vnc.h


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] PATCH: 2/7: Push VncState struct into vnc.h
Date: Thu, 12 Feb 2009 15:02:05 +0000
User-agent: Mutt/1.4.1i

This patch moves the declaration for the VncState struct out of the
vnc.c file and into vnc.h. This is to prepare for next patches which
have the auth mechanisms implementated in separate vnc-auth-vencrypt.c
and vnc-auth-sasl.c files

In doing this, I discovered that there is a pile of duplicated keymap
code statically compiled into all the console frontends. A couple of
trivial changes allowed this to be sanitized, so instead of doing
a #include "keymaps.c", duplicating all code, we can have a shared
keymaps.h file, and only compile code once.

   Signed-off-by: Daniel P. Berrange <address@hidden>


 Makefile      |    9 ++-
 b/keymaps.h   |   60 ++++++++++++++++++++++++
 curses.c      |    3 -
 curses_keys.h |    9 +--
 keymaps.c     |   45 +++++++-----------
 sdl.c         |    3 -
 sdl_keysym.h  |    7 +-
 vnc.c         |  101 ++---------------------------------------
 vnc.h         |  140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 vnc_keysym.h  |    5 --
 10 files changed, 235 insertions(+), 147 deletions(-)


Daniel


diff -r 1e8d80609fe1 Makefile
--- a/Makefile  Wed Feb 11 17:31:30 2009 +0000
+++ b/Makefile  Wed Feb 11 17:31:34 2009 +0000
@@ -137,6 +137,7 @@ endif
 AUDIO_OBJS+= wavcapture.o
 OBJS+=$(addprefix audio/, $(AUDIO_OBJS))
 
+OBJS+=keymaps.o
 ifdef CONFIG_SDL
 OBJS+=sdl.o x_keymap.o
 endif
@@ -161,15 +162,17 @@ LIBS+=$(VDE_LIBS)
 
 cocoa.o: cocoa.m
 
-sdl.o: sdl.c keymaps.c sdl_keysym.h
+keymaps.o: keymaps.c keymaps.h
+
+sdl.o: sdl.c keymaps.h sdl_keysym.h
 
 sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS)
 
-vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h
+vnc.o: vnc.c keymaps.h sdl_keysym.h vnchextile.h d3des.c d3des.h
 
 vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
 
-curses.o: curses.c keymaps.c curses_keys.h
+curses.o: curses.c keymaps.h curses_keys.h
 
 bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
 
diff -r 1e8d80609fe1 curses.c
--- a/curses.c  Wed Feb 11 17:31:30 2009 +0000
+++ b/curses.c  Wed Feb 11 17:31:34 2009 +0000
@@ -158,7 +158,6 @@ static void curses_cursor_position(Displ
 /* generic keyboard conversion */
 
 #include "curses_keys.h"
-#include "keymaps.c"
 
 static kbd_layout_t *kbd_layout = 0;
 static int keycode2keysym[CURSES_KEYS];
@@ -311,7 +310,7 @@ static void curses_keyboard_setup(void)
         keyboard_layout = "en-us";
 #endif
     if(keyboard_layout) {
-        kbd_layout = init_keyboard_layout(keyboard_layout);
+        kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
         if (!kbd_layout)
             exit(1);
     }
diff -r 1e8d80609fe1 curses_keys.h
--- a/curses_keys.h     Wed Feb 11 17:31:30 2009 +0000
+++ b/curses_keys.h     Wed Feb 11 17:31:34 2009 +0000
@@ -21,6 +21,10 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
+#include "keymaps.h"
+
+
 #define KEY_RELEASE         0x80
 #define KEY_MASK            0x7f
 #define SHIFT_CODE          0x2a
@@ -239,11 +243,6 @@ static const int curses2keysym[CURSES_KE
 
 };
 
-typedef struct {
-       const char* name;
-       int keysym;
-} name2keysym_t;
-
 static const name2keysym_t name2keysym[] = {
     /* Plain ASCII */
     { "space", 0x020 },
diff -r 1e8d80609fe1 keymaps.c
--- a/keymaps.c Wed Feb 11 17:31:30 2009 +0000
+++ b/keymaps.c Wed Feb 11 17:31:34 2009 +0000
@@ -22,34 +22,20 @@
  * THE SOFTWARE.
  */
 
-static int get_keysym(const char *name)
+#include "keymaps.h"
+#include "sysemu.h"
+
+static int get_keysym(const name2keysym_t *table,
+                     const char *name)
 {
     const name2keysym_t *p;
-    for(p = name2keysym; p->name != NULL; p++) {
+    for(p = table; p->name != NULL; p++) {
         if (!strcmp(p->name, name))
             return p->keysym;
     }
     return 0;
 }
 
-struct key_range {
-    int start;
-    int end;
-    struct key_range *next;
-};
-
-#define MAX_NORMAL_KEYCODE 512
-#define MAX_EXTRA_COUNT 256
-typedef struct {
-    uint16_t keysym2keycode[MAX_NORMAL_KEYCODE];
-    struct {
-       int keysym;
-       uint16_t keycode;
-    } keysym2keycode_extra[MAX_EXTRA_COUNT];
-    int extra_count;
-    struct key_range *keypad_range;
-    struct key_range *numlock_range;
-} kbd_layout_t;
 
 static void add_to_key_range(struct key_range **krp, int code) {
     struct key_range *kr;
@@ -73,7 +59,8 @@ static void add_to_key_range(struct key_
     }
 }
 
-static kbd_layout_t *parse_keyboard_layout(const char *language,
+static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
+                                          const char *language,
                                           kbd_layout_t * k)
 {
     FILE *f;
@@ -102,7 +89,7 @@ static kbd_layout_t *parse_keyboard_layo
        if (!strncmp(line, "map ", 4))
            continue;
        if (!strncmp(line, "include ", 8)) {
-           parse_keyboard_layout(line + 8, k);
+           parse_keyboard_layout(table, line + 8, k);
         } else {
            char *end_of_keysym = line;
            while (*end_of_keysym != 0 && *end_of_keysym != ' ')
@@ -110,7 +97,7 @@ static kbd_layout_t *parse_keyboard_layo
            if (*end_of_keysym) {
                int keysym;
                *end_of_keysym = 0;
-               keysym = get_keysym(line);
+               keysym = get_keysym(table, line);
                if (keysym == 0) {
                     //             fprintf(stderr, "Warning: unknown keysym 
%s\n", line);
                } else {
@@ -154,12 +141,14 @@ static kbd_layout_t *parse_keyboard_layo
     return k;
 }
 
-static void *init_keyboard_layout(const char *language)
+
+void *init_keyboard_layout(const name2keysym_t *table, const char *language)
 {
-    return parse_keyboard_layout(language, 0);
+    return parse_keyboard_layout(table, language, 0);
 }
 
-static int keysym2scancode(void *kbd_layout, int keysym)
+
+int keysym2scancode(void *kbd_layout, int keysym)
 {
     kbd_layout_t *k = kbd_layout;
     if (keysym < MAX_NORMAL_KEYCODE) {
@@ -180,7 +169,7 @@ static int keysym2scancode(void *kbd_lay
     return 0;
 }
 
-static inline int keycode_is_keypad(void *kbd_layout, int keycode)
+int keycode_is_keypad(void *kbd_layout, int keycode)
 {
     kbd_layout_t *k = kbd_layout;
     struct key_range *kr;
@@ -191,7 +180,7 @@ static inline int keycode_is_keypad(void
     return 0;
 }
 
-static inline int keysym_is_numlock(void *kbd_layout, int keysym)
+int keysym_is_numlock(void *kbd_layout, int keysym)
 {
     kbd_layout_t *k = kbd_layout;
     struct key_range *kr;
diff -r 1e8d80609fe1 keymaps.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/keymaps.h Wed Feb 11 17:31:34 2009 +0000
@@ -0,0 +1,60 @@
+/*
+ * QEMU keysym to keycode conversion using rdesktop keymaps
+ *
+ * Copyright (c) 2004 Johannes Schindelin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef __QEMU_KEYMAPS_H__
+#define __QEMU_KEYMAPS_H__
+
+#include "qemu-common.h"
+
+typedef struct {
+       const char* name;
+       int keysym;
+} name2keysym_t;
+
+struct key_range {
+    int start;
+    int end;
+    struct key_range *next;
+};
+
+#define MAX_NORMAL_KEYCODE 512
+#define MAX_EXTRA_COUNT 256
+typedef struct {
+    uint16_t keysym2keycode[MAX_NORMAL_KEYCODE];
+    struct {
+       int keysym;
+       uint16_t keycode;
+    } keysym2keycode_extra[MAX_EXTRA_COUNT];
+    int extra_count;
+    struct key_range *keypad_range;
+    struct key_range *numlock_range;
+} kbd_layout_t;
+
+
+void *init_keyboard_layout(const name2keysym_t *table, const char *language);
+int keysym2scancode(void *kbd_layout, int keysym);
+int keycode_is_keypad(void *kbd_layout, int keycode);
+int keysym_is_numlock(void *kbd_layout, int keysym);
+
+#endif /* __QEMU_KEYMAPS_H__ */
diff -r 1e8d80609fe1 sdl.c
--- a/sdl.c     Wed Feb 11 17:31:30 2009 +0000
+++ b/sdl.c     Wed Feb 11 17:31:34 2009 +0000
@@ -107,7 +107,6 @@ static void sdl_resize(DisplayState *ds)
 /* generic keyboard conversion */
 
 #include "sdl_keysym.h"
-#include "keymaps.c"
 
 static kbd_layout_t *kbd_layout = NULL;
 
@@ -623,7 +622,7 @@ void sdl_display_init(DisplayState *ds, 
         keyboard_layout = "en-us";
 #endif
     if(keyboard_layout) {
-        kbd_layout = init_keyboard_layout(keyboard_layout);
+        kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
         if (!kbd_layout)
             exit(1);
     }
diff -r 1e8d80609fe1 sdl_keysym.h
--- a/sdl_keysym.h      Wed Feb 11 17:31:30 2009 +0000
+++ b/sdl_keysym.h      Wed Feb 11 17:31:34 2009 +0000
@@ -1,7 +1,6 @@
-typedef struct {
-       const char* name;
-       int keysym;
-} name2keysym_t;
+
+#include "keymaps.h"
+
 static const name2keysym_t name2keysym[]={
 /* ascii */
     { "space",                0x020},
diff -r 1e8d80609fe1 vnc.c
--- a/vnc.c     Wed Feb 11 17:31:30 2009 +0000
+++ b/vnc.c     Wed Feb 11 17:31:34 2009 +0000
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2006 Anthony Liguori <address@hidden>
  * Copyright (C) 2006 Fabrice Bellard
+ * Copyright (C) 2009 Red Hat, Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal
@@ -23,26 +24,17 @@
  * THE SOFTWARE.
  */
 
-#include "qemu-common.h"
-#include "console.h"
+#include "vnc.h"
+
 #include "sysemu.h"
 #include "qemu_socket.h"
 #include "qemu-timer.h"
-#include "audio/audio.h"
-#include <zlib.h>
 
 #define VNC_REFRESH_INTERVAL (1000 / 30)
 
-#include "vnc.h"
 #include "vnc_keysym.h"
-#include "keymaps.c"
 #include "d3des.h"
 
-#ifdef CONFIG_VNC_TLS
-#include <gnutls/gnutls.h>
-#include <gnutls/x509.h>
-#endif /* CONFIG_VNC_TLS */
-
 // #define _VNC_DEBUG 1
 
 #ifdef _VNC_DEBUG
@@ -65,91 +57,8 @@ static void vnc_debug_gnutls_log(int lev
     } \
 }
 
-typedef struct Buffer
-{
-    size_t capacity;
-    size_t offset;
-    uint8_t *buffer;
-} Buffer;
 
-typedef struct VncState VncState;
 
-typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
-
-typedef void VncWritePixels(VncState *vs, void *data, int size);
-
-typedef void VncSendHextileTile(VncState *vs,
-                                int x, int y, int w, int h,
-                                void *last_bg,
-                                void *last_fg,
-                                int *has_bg, int *has_fg);
-
-#define VNC_MAX_WIDTH 2048
-#define VNC_MAX_HEIGHT 2048
-#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32))
-
-#define VNC_AUTH_CHALLENGE_SIZE 16
-
-struct VncState
-{
-    QEMUTimer *timer;
-    int lsock;
-    int csock;
-    DisplayState *ds;
-    int need_update;
-    uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
-    char *old_data;
-    uint32_t features;
-    int absolute;
-    int last_x;
-    int last_y;
-
-    uint32_t vnc_encoding;
-    uint8_t tight_quality;
-    uint8_t tight_compression;
-
-    int major;
-    int minor;
-
-    char *display;
-    char *password;
-    int auth;
-#ifdef CONFIG_VNC_TLS
-    int subauth;
-    int x509verify;
-
-    char *x509cacert;
-    char *x509cacrl;
-    char *x509cert;
-    char *x509key;
-#endif
-    char challenge[VNC_AUTH_CHALLENGE_SIZE];
-
-#ifdef CONFIG_VNC_TLS
-    int wiremode;
-    gnutls_session_t tls_session;
-#endif
-
-    Buffer output;
-    Buffer input;
-    kbd_layout_t *kbd_layout;
-    /* current output mode information */
-    VncWritePixels *write_pixels;
-    VncSendHextileTile *send_hextile_tile;
-    DisplaySurface clientds, serverds;
-
-    CaptureVoiceOut *audio_cap;
-    struct audsettings as;
-
-    VncReadEvent *read_handler;
-    size_t read_handler_expect;
-    /* input */
-    uint8_t modifiers_state[256];
-
-    Buffer zlib;
-    Buffer zlib_tmp;
-    z_stream zlib_stream[4];
-};
 
 static VncState *vnc_state; /* needed for info vnc */
 static DisplayChangeListener *dcl;
@@ -2352,9 +2261,9 @@ void vnc_display_init(DisplayState *ds)
     vs->ds = ds;
 
     if (keyboard_layout)
-        vs->kbd_layout = init_keyboard_layout(keyboard_layout);
+        vs->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
     else
-        vs->kbd_layout = init_keyboard_layout("en-us");
+        vs->kbd_layout = init_keyboard_layout(name2keysym, "en-us");
 
     if (!vs->kbd_layout)
        exit(1);
diff -r 1e8d80609fe1 vnc.h
--- a/vnc.h     Wed Feb 11 17:31:30 2009 +0000
+++ b/vnc.h     Wed Feb 11 17:31:34 2009 +0000
@@ -1,5 +1,139 @@
-#ifndef __VNCTIGHT_H
-#define __VNCTIGHT_H
+/*
+ * QEMU VNC display driver
+ *
+ * Copyright (C) 2006 Anthony Liguori <address@hidden>
+ * Copyright (C) 2006 Fabrice Bellard
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef __VNC_H
+#define __VNC_H
+
+
+#include "qemu-common.h"
+#include "console.h"
+#include "audio/audio.h"
+#include <zlib.h>
+
+#ifdef CONFIG_VNC_TLS
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#endif /* CONFIG_VNC_TLS */
+
+#include "keymaps.h"
+
+
+/*****************************************************************************
+ *
+ * Core data structures
+ *
+ *****************************************************************************/
+
+
+#define VNC_MAX_WIDTH 2048
+#define VNC_MAX_HEIGHT 2048
+#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32))
+
+#define VNC_AUTH_CHALLENGE_SIZE 16
+
+typedef struct VncState VncState;
+
+typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
+
+typedef void VncWritePixels(VncState *vs, void *data, int size);
+
+typedef void VncSendHextileTile(VncState *vs,
+                                int x, int y, int w, int h,
+                                void *last_bg,
+                                void *last_fg,
+                                int *has_bg, int *has_fg);
+
+
+typedef struct Buffer
+{
+    size_t capacity;
+    size_t offset;
+    uint8_t *buffer;
+} Buffer;
+
+struct VncState
+{
+    QEMUTimer *timer;
+    int lsock;
+    int csock;
+    DisplayState *ds;
+    int need_update;
+    uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
+    char *old_data;
+    uint32_t features;
+    int absolute;
+    int last_x;
+    int last_y;
+
+    uint32_t vnc_encoding;
+    uint8_t tight_quality;
+    uint8_t tight_compression;
+
+    int major;
+    int minor;
+
+    char *display;
+    char *password;
+    int auth;
+#ifdef CONFIG_VNC_TLS
+    int subauth;
+    int x509verify;
+
+    char *x509cacert;
+    char *x509cacrl;
+    char *x509cert;
+    char *x509key;
+#endif
+    char challenge[VNC_AUTH_CHALLENGE_SIZE];
+
+#ifdef CONFIG_VNC_TLS
+    int wiremode;
+    gnutls_session_t tls_session;
+#endif
+
+    Buffer output;
+    Buffer input;
+    kbd_layout_t *kbd_layout;
+    /* current output mode information */
+    VncWritePixels *write_pixels;
+    VncSendHextileTile *send_hextile_tile;
+    DisplaySurface clientds, serverds;
+
+    CaptureVoiceOut *audio_cap;
+    struct audsettings as;
+
+    VncReadEvent *read_handler;
+    size_t read_handler_expect;
+    /* input */
+    uint8_t modifiers_state[256];
+
+    Buffer zlib;
+    Buffer zlib_tmp;
+    z_stream zlib_stream[4];
+};
 
 /*****************************************************************************
  *
@@ -109,4 +243,4 @@ enum {
 #define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
 #define VNC_FEATURE_ZLIB_MASK                (1 << VNC_FEATURE_ZLIB)
 
-#endif /* __VNCTIGHT_H */
+#endif /* __VNC_H */
diff -r 1e8d80609fe1 vnc_keysym.h
--- a/vnc_keysym.h      Wed Feb 11 17:31:30 2009 +0000
+++ b/vnc_keysym.h      Wed Feb 11 17:31:34 2009 +0000
@@ -1,7 +1,4 @@
-typedef struct {
-       const char* name;
-       int keysym;
-} name2keysym_t;
+
 static const name2keysym_t name2keysym[]={
 /* ascii */
     { "space",                0x020},

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




reply via email to

[Prev in Thread] Current Thread [Next in Thread]