Skip to content

Add disabled servers #81

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test_mxqd_control.o
mxq_log.o
mx_mysql.o
mxqd_control.o
keywordset.o
test_keywordset.o
mxqset.o


mxqsub
Expand All @@ -30,10 +33,12 @@ mxqdump
mxqkill
mxqd
mxqps
mxqset
test_mx_util
test_mx_log
test_mx_mysq
test_mxqd_control
test_keywordset

/web/pages/mxq/mxq
web/lighttpd.conf
Expand Down
5 changes: 5 additions & 0 deletions .vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set nosmarttab
48 changes: 47 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MXQ_VERSION_MAJOR = 0
MXQ_VERSION_MINOR = 26
MXQ_VERSION_PATCH = 1
MXQ_VERSION_PATCH = 2
MXQ_VERSION_EXTRA = "beta"
MXQ_VERSIONDATE = 2016

Expand Down Expand Up @@ -341,6 +341,10 @@ mxqd_control.h += mxqd.h

mx_getopt.h += mx_getopt.h

### keywordset.h -------------------------------------------------------

keywordset.h += keywordset.h

########################################################################

### mx_getopt.o --------------------------------------------------------
Expand Down Expand Up @@ -412,6 +416,16 @@ mxqadmin.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqadmin.o

### mxqset.o ----------------------------------------------------------

mxqsset.o: $(mx_mysql.h)
mxqsset.o: $(keywordset.h)
mxqkill.o: $(mxq.h)
mxqkill.o: $(mxq_group.h)
mxqset.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqsset.o

### mxqkill.o ----------------------------------------------------------

mxqkill.o: $(mx_log.h)
Expand Down Expand Up @@ -472,6 +486,7 @@ mxqd.o: $(mxq_daemon.h)
mxqd.o: $(mxq_group.h)
mxqd.o: $(mxq_job.h)
mxqd.o: $(mx_mysql.h)
mxqd.o: $(keywordset.h)
mxqd.o: CFLAGS += $(CFLAGS_MYSQL)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_PATH)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_TMPDIR)
Expand All @@ -490,10 +505,18 @@ mxqsub.o: $(mxq.h)
mxqsub.o: $(mxq_group.h)
mxqsub.o: $(mxq_job.h)
mxqsub.o: $(mx_util.h)
mxqsub.o: $(keywordset.h)
mxqsub.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqsub.o

### keywordset.o -----------------------------------------------------

keywordset.o: $(keywordset.h)
keywordset.o: xmalloc.h

clean: CLEAN += keywordset.o

########################################################################

### mxqd ---------------------------------------------------------------
Expand All @@ -509,6 +532,7 @@ mxqd: mxq_group.o
mxqd: mxq_job.o
mxqd: mx_mysql.o
mxqd: mxqd_control.o
mxqd: keywordset.o
mxqd: LDLIBS += $(LDLIBS_MYSQL)

build: mxqd
Expand All @@ -524,6 +548,7 @@ mxqsub: mx_getopt.o
mxqsub: mx_util.o
mxqsub: mx_log.o
mxqsub: mx_mysql.o
mxqsub: keywordset.o
mxqsub: LDLIBS += $(LDLIBS_MYSQL)

build: mxqsub
Expand Down Expand Up @@ -566,6 +591,21 @@ clean: CLEAN += mxqadmin
install:: mxqadmin
$(call quiet-installforuser,$(SUID_MODE),$(UID_CLIENT),$(GID_CLIENT),mxqadmin,${DESTDIR}${BINDIR}/mxqadmin)

### mxqset ---------------------------------------------------------------

mxqset: mx_mysql.o
mxqset: mx_log.o
mxqset: mx_util.o
mxqset: keywordset.o
mxqset: LDLIBS += $(LDLIBS_MYSQL)

build: mxqset

clean: CLEAN += mxqset

install:: mxqset
$(call quiet-installforuser,$(SUID_MODE),$(UID_CLIENT),$(GID_CLIENT),mxqset,${DESTDIR}${BINDIR}/mxqset)

### mxqkill ------------------------------------------------------------

mxqkill: mx_log.o
Expand Down Expand Up @@ -678,3 +718,9 @@ test_mxqd_control: LDLIBS += $(LDLIBS_MYSQL)
clean: CLEAN += test_mxqd_control

test: test_mxqd_control

test_keywordset: $(test_keywordset.h)
test_keywordset: test_keywordset.o
test_keywordset: keywordset.o
clean: CLEAN += test_keywordset.o
test: test_keywordset
133 changes: 133 additions & 0 deletions keywordset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include "keywordset.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "xmalloc.h"

#define KEYWORDSET_INITIAL_SLOTS (4-2)

struct keywordset {
int nr_slots;
int used;
char **names;
};

static int find_name(struct keywordset *kws, char *name, size_t len) {
int i;
int j;
for ( i = 0; i < kws->used ; i++ ) {
j = 0;
while(1) {
if (kws->names[i][j] == 0)
break;
if (kws->names[i][j] != name[j])
break;
j++;
if (j==len)
return i;
}
}
return -1;
}

static void expand(struct keywordset *kws) {
int new_slots=(kws->nr_slots+2)*2-2;
kws->names=xrealloc(kws->names,new_slots*sizeof(*kws->names));
kws->nr_slots=new_slots;
}

static void add_name(struct keywordset *kws, char *name, size_t len) {
int i=find_name(kws, name, len);
if (i>=0) {
free(kws->names[i]);
kws->names[i] = xstrndup(name, len);
} else {
if (kws->used == kws->nr_slots)
expand(kws);
kws->names[kws->used++] = xstrndup(name, len);
}
}

static void remove_name(struct keywordset *kws, char *name, size_t len) {
int i=find_name(kws, name, len);
if (i>=0) {
free(kws->names[i]);
memmove(&(kws->names[i]), &(kws->names[i+1]), (kws->used-i-1)*sizeof(*kws->names));
kws->used--;
}
}

void keywordset_update(struct keywordset *kws, char *input) {
char *c=input;
char *name_start;
int add;
while (*c) {
while (*c && isspace(*c))
c++;
if (*c == '-') {
add = 0;
c++;
} else
add = 1;
if (*c) {
name_start=c++;
while (*c && !isspace(*c))
c++;
if (add)
add_name(kws, name_start, c-name_start);
else
remove_name(kws, name_start, c-name_start);
}
}
}

struct keywordset *keywordset_new(char *input) {
struct keywordset *kws = xmalloc(sizeof(*kws));
kws->nr_slots = KEYWORDSET_INITIAL_SLOTS;
kws->used = 0;
kws->names = xmalloc(KEYWORDSET_INITIAL_SLOTS*sizeof(*kws->names));
if (input)
keywordset_update(kws, input);
return kws;
}

static int cmp(const void *a, const void *b) {
return strcmp(*(char **)a, *(char **)b);
}

char *keywordset_get(struct keywordset *kws) {
char **names=xmalloc(kws->used * sizeof(*names));
memcpy(names, kws->names, kws->used * sizeof(*names));
qsort(names, kws->used, sizeof(*names), cmp);
size_t len = 0;
int i;
for (i=0; i<kws->used; i++) {
len += strlen(names[i]);
}
size_t outlen = len + (kws->used >= 2 ? kws->used-1 : 0);
char *out=xmalloc(outlen + 1 );
char *p=out;
for ( i = 0 ; i < kws->used ; i++) {
p=stpcpy(p, names[i]);
*p++ = ' ';
}
out[outlen] = 0;
free(names);
return(out);
}

int keywordset_ismember(struct keywordset *kws, char *name) {
if (find_name(kws, name, strlen(name)) >= 0)
return 1;
else
return 0;
}

void keywordset_free(struct keywordset *kws) {
int i;
for ( i = 0 ; i < kws->used ; i++)
free(kws->names[i]);
free(kws->names);
free(kws);
}
10 changes: 10 additions & 0 deletions keywordset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _KEYWORDSET_H
#define _KEYWORDSET_H

struct keywordset *keywordset_new(char *input);
void keywordset_update(struct keywordset *kws, char *input);
char *keywordset_get(struct keywordset *kws);
int keywordset_ismember(struct keywordset *kwd, char *name);
void keywordset_free(struct keywordset *kws);

#endif
2 changes: 1 addition & 1 deletion mxq.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# define MXQ_MAX_PENDING_JOBS_PER_GROUP 10000
#endif

static void mxq_print_generic_version(void)
__attribute__ ((unused)) static void mxq_print_generic_version(void)
{
printf(
"%s - " MXQ_VERSIONFULL "\n"
Expand Down
5 changes: 4 additions & 1 deletion mxq_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#include "mx_util.h"
#include "mx_mysql.h"

#define GROUP_FIELDS_CNT 33
#define GROUP_FIELDS_CNT 34
#define GROUP_FIELDS \
" group_id," \
" group_name," \
" group_status," \
" group_flags," \
" group_priority," \
" group_disabled_servers," \
" user_uid," \
" user_name," \
" user_gid," \
Expand Down Expand Up @@ -62,6 +63,7 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro
res += mx_mysql_bind_var(result, idx++, uint8, &(g->group_status));
res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_flags));
res += mx_mysql_bind_var(result, idx++, uint16, &(g->group_priority));
res += mx_mysql_bind_var(result, idx++, string, &(g->group_disabled_servers));

res += mx_mysql_bind_var(result, idx++, uint32, &(g->user_uid));
res += mx_mysql_bind_var(result, idx++, string, &(g->user_name));
Expand Down Expand Up @@ -105,6 +107,7 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro

void mxq_group_free_content(struct mxq_group *g)
{
mx_free_null(g->group_disabled_servers);
mx_free_null(g->group_name);
mx_free_null(g->user_name);
mx_free_null(g->user_group);
Expand Down
1 change: 1 addition & 0 deletions mxq_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct mxq_group {
uint8_t group_status;
uint64_t group_flags;
uint16_t group_priority;
char * group_disabled_servers;

uint32_t user_uid;
char * user_name;
Expand Down
Loading