Skip to content

Commit

Permalink
#108 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jul 11, 2019
1 parent a89906b commit 78cbcba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/osax/sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define PAYLOAD_STATUS_SUCCESS 0
#define PAYLOAD_STATUS_OUTDATED 1
#define PAYLOAD_STATUS_NO_ATTRIB 2
#define PAYLOAD_STATUS_CON_ERROR 3

int scripting_addition_load(void);
bool scripting_addition_is_installed(void);
Expand Down
35 changes: 24 additions & 11 deletions src/osax/sa.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,30 @@ static void scripting_addition_prepare_binaries(void)
system(cmd);
}

static char *scripting_addition_request_handshake(uint32_t *flags)
static bool scripting_addition_request_handshake(char *version, uint32_t *attrib)
{
char *result = NULL;
bool result = false;

int sockfd;
char message[MAXLEN];

if (socket_connect_un(&sockfd, g_sa_socket_file)) {
snprintf(message, sizeof(message), "handshake");
if (socket_write(sockfd, message)) {
result = true;

int length;
result = socket_read(sockfd, &length);
if (!result) goto out;
char *rsp = socket_read(sockfd, &length);
if (!rsp) goto out;

char *zero = rsp;
while (*zero != '\0') ++zero;

assert(*zero == '\0');
memcpy(version, rsp, zero - rsp + 1);
memcpy(attrib, zero+1, sizeof(uint32_t));

char *attrib = result + 6;
assert(attrib[-1] == '\0');
memcpy(flags, attrib, sizeof(uint32_t));
free(rsp);
}
}

Expand All @@ -202,11 +209,17 @@ static void scripting_addition_prepare_binaries(void)

static int scripting_addition_perform_validation(void)
{
uint32_t attrib;
char *version = scripting_addition_request_handshake(&attrib);
if (version) debug("yabai: osax version = %s, osax attrib = 0x%X\n", version, attrib);
uint32_t attrib = 0;
char version[MAXLEN] = {};

if (!scripting_addition_request_handshake(version, &attrib)) {
notify("connection failed!", "scripting-addition");
return PAYLOAD_STATUS_CON_ERROR;
}

debug("yabai: osax version = %s, osax attrib = 0x%X\n", version, attrib);

if (!version || !string_equals(version, OSAX_VERSION)) {
if (!string_equals(version, OSAX_VERSION)) {
notify("payload is outdated, please reinstall!", "scripting-addition");
return PAYLOAD_STATUS_OUTDATED;
} else if ((attrib & OSAX_ATTRIB_ALL) != OSAX_ATTRIB_ALL) {
Expand Down

0 comments on commit 78cbcba

Please sign in to comment.