Skip to content

Commit

Permalink
new property for user name (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
norihiro committed May 20, 2021
1 parent 8059693 commit 1cc44c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/obs-vnc-source-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ static void vncsrc_update(void *data, obs_data_t *settings)
src->need_reconnect = true;
}

#ifdef LIBVNCSERVER_HAVE_SASL
const char *user_name = obs_data_get_string(settings, "user_name");
if (user_name && !*user_name) {
BFREE_IF_NONNULL(src->config.user_name);
src->need_reconnect = true;
}
else if (user_name && (!src->config.user_name || strcmp(user_name, src->config.user_name))) {
BFREE_IF_NONNULL(src->config.user_name);
src->config.user_name = bstrdup(user_name);
src->need_reconnect = true;
}
#endif // LIBVNCSERVER_HAVE_SASL

UPDATE_NOTIFY(src, int, bpp, need_reconnect, obs_data_get_int(settings, "bpp"));
UPDATE_NOTIFY(src, int, encodings, encoding_updated, obs_data_get_int(settings, "encodings"));
UPDATE_NOTIFY(src, int, compress, encoding_updated, obs_data_get_int(settings, "compress"));
Expand Down Expand Up @@ -109,6 +122,9 @@ static obs_properties_t *vncsrc_get_properties(void *unused)
obs_properties_add_text(props, "host_name", obs_module_text("Host name"), OBS_TEXT_DEFAULT);
obs_properties_add_int(props, "host_port", obs_module_text("Host port"), 1, 65535, 1);
obs_properties_add_text(props, "plain_passwd", obs_module_text("Password"), OBS_TEXT_PASSWORD);
#ifdef LIBVNCSERVER_HAVE_SASL
obs_properties_add_text(props, "user_name", obs_module_text("User name"), OBS_TEXT_DEFAULT);
#endif // LIBVNCSERVER_HAVE_SASL

prop = obs_properties_add_list(props, "bpp", "Color level", OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
obs_property_list_add_int(prop, "24-bit", 32);
Expand Down Expand Up @@ -157,28 +173,28 @@ static void vncsrc_show(void *data)
{
struct vnc_source *src = data;
long f = os_atomic_load_long(&src->display_flags);
os_atomic_store_long(&src->display_flags, f | VNCSRC_FLG_SHOWN);
os_atomic_set_long(&src->display_flags, f | VNCSRC_FLG_SHOWN);
}

static void vncsrc_hide(void *data)
{
struct vnc_source *src = data;
long f = os_atomic_load_long(&src->display_flags);
os_atomic_store_long(&src->display_flags, f &~VNCSRC_FLG_SHOWN);
os_atomic_set_long(&src->display_flags, f &~VNCSRC_FLG_SHOWN);
}

static void vncsrc_activate(void *data)
{
struct vnc_source *src = data;
long f = os_atomic_load_long(&src->display_flags);
os_atomic_store_long(&src->display_flags, f | VNCSRC_FLG_ACTIVE);
os_atomic_set_long(&src->display_flags, f | VNCSRC_FLG_ACTIVE);
}

static void vncsrc_deactivate(void *data)
{
struct vnc_source *src = data;
long f = os_atomic_load_long(&src->display_flags);
os_atomic_store_long(&src->display_flags, f &~VNCSRC_FLG_ACTIVE);
os_atomic_set_long(&src->display_flags, f &~VNCSRC_FLG_ACTIVE);
}

static void vncsrc_mouse_click(void *data, const struct obs_mouse_event *event, int32_t type, bool mouse_up, uint32_t click_count)
Expand Down
16 changes: 16 additions & 0 deletions src/obs-vnc-source-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
#define debug(fmt, ...) (void)0
// #define debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

#ifdef LIBVNCSERVER_HAVE_SASL
static char *vnc_username(rfbClient* client)
{
struct vnc_source *src = rfbClientGetClientData(client, vncsrc_thread_start);

pthread_mutex_lock(&src->config_mutex);
char *ret = strdup(src->config.user_name ? src->config.user_name : "");
pthread_mutex_unlock(&src->config_mutex);

return ret;
}
#endif // LIBVNCSERVER_HAVE_SASL

static char *vnc_passwd(rfbClient* client)
{
struct vnc_source *src = rfbClientGetClientData(client, vncsrc_thread_start);
Expand Down Expand Up @@ -159,6 +172,9 @@ static inline rfbClient *rfbc_start(struct vnc_source *src)
rfbClientSetClientData(client, vncsrc_thread_start, src);
client->MallocFrameBuffer = vnc_malloc_fb;
client->GotFrameBufferUpdate = vnc_update;
#ifdef LIBVNCSERVER_HAVE_SASL
client->GetUser = vnc_username;
#endif // LIBVNCSERVER_HAVE_SASL
client->GetPassword = vnc_passwd;
client->programName = "obs-vnc-src";
client->canHandleNewFBSize = 1;
Expand Down
5 changes: 4 additions & 1 deletion src/obs-vnc-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <pthread.h>
#include <obs.h>
#include <util/circlebuf.h>
#include <rfb/rfbconfig.h>

enum vnc_encodings_e
{
Expand All @@ -21,7 +22,9 @@ struct vncsrc_conig
{
char *host_name;
int host_port;
// TODO: char *user_name;
#ifdef LIBVNCSERVER_HAVE_SASL
char *user_name;
#endif // LIBVNCSERVER_HAVE_SASL
char *plain_passwd;
int bpp; // bits per pixel; 8, 16, [32] only.
int encodings;
Expand Down

0 comments on commit 1cc44c4

Please sign in to comment.