'ext_bones_merge_dest'.
Sprout from exp_bones 2004-09-14 02:15:45 UTC cvs2svn <admin@example.com> 'This commit was manufactured by cvs2svn to create branch 'exp_bones'.'
Cherrypick from master 2004-10-14 01:26:59 UTC Master Builder <glbuilder@cern.ch> 'Incremented build number [GLBUILDER]':
org.glite.lb.server/Makefile
org.glite.lb.server/config/startup
org.glite.lb.server/project/configure.properties.xml
org.glite.lb.server/project/version.properties
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/il_notification.c
org.glite.lb.server/src/il_notification.h
org.glite.lb.server/src/lb_authz.c
org.glite.lb.server/src/lb_authz.h
org.glite.lb.server/src/lb_proto.c
org.glite.lb.server/src/lbs_db.c
org.glite.lb.server/src/notification.c
org.glite.lb.server/test/oneJob.qry
org.glite.lb.server/test/test_query_events.cpp
-include Makefile.inc
YACC=bison -y
+CC=gcc
VPATH=${top_srcdir}/src:${top_srcdir}/test
AT3=perl -I${top_srcdir}/project ${top_srcdir}/project/at3
-I${ares_prefix}/include \
${COVERAGE_FLAGS} \
-I${mysql_prefix}/include \
- -I${globus_prefix}/include/${nothrflavour}
+ -I${globus_prefix}/include/${nothrflavour} \
+ -I${gridsite_prefix}/include -I${globus_prefix}/include/${nothrflavour}/openssl
TEST_LIBS:=-L${cppunit}/lib -lcppunit
GLOBUS_LIBS:= -L${globus_prefix}/lib \
-lglobus_common_${nothrflavour} \
- -lglobus_gssapi_gsi_${nothrflavour}
+ -lglobus_gssapi_gsi_${nothrflavour} \
# XXX: our vomsc.la depends on badly installed expat
-L${expat_prefix}/lib -lexpat \
${GLOBUS_LIBS}
+# -L${gridsite_prefix}/lib -lgridsite -lxml2
+
COMMON_LIB:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour}
+# -lvomsc
+
SERVER_OBJS:= bkserverd.o get_events.o index.o jobstat.o jobstat_supp.o \
write2rgma.o lbs_db.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
lb_xml_parse_V21.o \
compile: glite_lb_bkserverd glite_lb_bkindex
-check: test_xml
+check: compile test.xml test.query
-echo check.query not complete yet
test_xml: test_xml.cpp
${CXX} -c ${CFLAGS} ${TEST_INC} $<
- ${LINKXX} -o $@ test_xml.o lb_xml_parse.o ${COMMON_LIB} ${TEST_LIBS}
+ ${LINKXX} -o $@ test_xml.o lb_xml_parse.o ${COMMON_LIB} ${TEST_LIBS} ${EXT_LIBS}
+
+test.query: test_query_events
+ ./test_query_events ${top_srcdir}/test
+
+test.xml: test_xml
./test_xml
lb_xml_parse.c: lb_xml_parse.c.T
install:
-mkdir -p ${PREFIX}/bin ${PREFIX}/etc ${PREFIX}/etc/init.d
+ -mkdir -p ${PREFIX}/share/doc/${package}-${version}
+ ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version}
for p in bkserverd bkindex; do \
${INSTALL} -m 755 "glite_lb_$$p" "${PREFIX}/bin/glite-lb-$$p"; \
done
[ -f $GLITE_LOCATION_VAR/etc/lb.conf ] && . $GLITE_LOCATION_VAR/etc/lb.conf
[ -n "$GLITE_LB_SERVER_PIDFILE" ] && pidfile=$GLITE_LB_SERVER_PIDFILE ||
- pidfile=$GLITE_LOCATION_VAR/glite_lb_bkserverd.pid
+ pidfile=$GLITE_LOCATION_VAR/glite-lb-bkserverd.pid
start()
{
[ -n "$GLITE_LB_SERVER_PORT" ] && port="-p $GLITE_LB_SERVER_PORT"
- echo -n Starting glite_lb_bkserver ...
- su $GLITE_USER -c "$GLITE_LOCATION/bin/glite_lb_bkserverd \
- $creds -i $pidfile" && echo " done"
+ echo -n Starting glite-lb-bkserver ...
+ su $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-bkserverd \
+ $creds -i $pidfile $port" && echo " done"
}
stop()
if [ -f $pidfile ]; then
pid=`cat $pidfile`
kill $pid
- echo -n Stopping glite_lb_bkserverd \($pid\) ...
+ echo -n Stopping glite-lb-bkserverd \($pid\) ...
try=0
while ps p $pid >/dev/null 2>&1; do
sleep 1;
echo " done"
rm -f $pidfile
else
- echo $pidfile does not exist - glite_lb_bkserverd not running? >&2
+ echo $pidfile does not exist - glite-lb-bkserverd not running? >&2
return 1
fi
}
if [ -f $pidfile ]; then
pid=`cat $pidfile`
if ps p $pid >/dev/null 2>&1; then
- echo glite_lb_bkserverd running as $pid
+ echo glite-lb-bkserverd running as $pid
return 0
fi
fi
- echo glite_lb_bkserverd not running
+ echo glite-lb-bkserverd not running
return 1
}
Revision history:
$Log$
+ Revision 1.2 2004/09/08 13:38:03 akrenek
+ query event unit test (not complete yet)
+
Revision 1.1 2004/07/07 12:08:09 akrenek
*** empty log message ***
ares_prefix=${with.ares.prefix}
mysql_prefix=${with.mysql.prefix}
cppunit=${with.cppunit.prefix}
+gridsite_prefix=${with.gridsite.prefix}
</echo>
</target>
</project>
-#Tue Sep 14 04:13:15 CEST 2004
-module.version=0.0.0
-module.build=7
+#Thu Oct 14 03:24:40 CEST 2004
+module.version=0.1.0
+module.build=41
module.age=0
#include <globus_common.h>
-#include "glite/wmsutils/tls/ssl_helpers/ssl_inits.h"
#include "glite/lb/consumer.h"
#include "glite/lb/purge.h"
#include "glite/lb/context.h"
{"limits", 1, NULL, 'L'},
{"notif-dur", 1, NULL, 'N'},
{"notif-il-sock", 1, NULL, 'X'},
+ {"notif-il-fprefix", 1, NULL, 'Y'},
{NULL,0,NULL,0}
};
"\t =2\t don't enforce indices at all\n"
"\t--strict-locking=1\t lock jobs also on storing events (may be slow)\n"
"\t--notif-il-sock\t socket to send notifications\n"
+ "\t--notif-il-fprefix\t file prefix for notifications\n"
,me);
}
if (geteuid()) snprintf(pidfile,sizeof pidfile,"%s/edg-bkserverd.pid",
getenv("HOME"));
- while ((opt = getopt_long(argc,argv,"a:c:k:C:V:p:drm:ns:l:L:N:i:S:D:X:",opts,NULL)) != EOF) switch (opt) {
+ while ((opt = getopt_long(argc,argv,"a:c:k:C:V:p:drm:ns:l:L:N:i:S:D:X:Y:",opts,NULL)) != EOF) switch (opt) {
case 'a': fake_host = strdup(optarg); break;
case 'c': cert = optarg; break;
case 'k': key = optarg; break;
break;
case 'N': notif_duration = atoi(optarg) * (60*60); break;
case 'X': notif_ilog_socket_path = strdup(optarg); break;
+ case 'Y': notif_ilog_file_prefix = strdup(optarg); break;
case 'i': strcpy(pidfile,optarg); break;
case 'R': if (super_users) {
fprintf(stderr,"%s: super-users already defined, second occurence ignored\n",
if (!cert || !key) fprintf(stderr,"%s: key or certificate file not specified - unable to watch them for changes!\n",argv[0]);
if (cadir) setenv("X509_CERT_DIR",cadir,1);
- if (edg_wll_gss_acquire_cred_gsi(cert, &mycred, &mysubj, &gss_code)) {
+ edg_wll_gss_watch_creds(cert,&cert_mtime);
+ if (edg_wll_gss_acquire_cred_gsi(cert, key, &mycred, &mysubj, &gss_code)) {
dprintf(("Running unauthenticated\n"));
} else {
int i;
switch (edg_wll_gss_watch_creds(cert,&cert_mtime)) {
case 0: break;
case 1:
- ret = edg_wll_gss_acquire_cred_gsi(cert, &newcred, NULL, &gss_code);
+ ret = edg_wll_gss_acquire_cred_gsi(cert, key, &newcred, NULL, &gss_code);
if (ret == 0) {
dprintf(("reloading credentials"));
gss_release_cred(&min_stat, &mycred);
ctx->p_tmp_timeout.tv_sec = SLAVE_TIMEOUT;
ctx->poolSize = 1;
+ free(ctx->connPool);
ctx->connPool = calloc(1,sizeof(edg_wll_ConnPool));
ctx->connToUse = 0;
#define DEFAULT_SOCKET "/tmp/notif_interlogger.sock"
char *notif_ilog_socket_path = DEFAULT_SOCKET;
+char *notif_ilog_file_prefix = FILE_PREFIX;
#define tv_sub(a,b) {\
(a).tv_usec -= (b).tv_usec;\
goto out;
}
- asprintf(&event_file, "%s.%s", FILE_PREFIX, reg_id_s);
+ asprintf(&event_file, "%s.%s", notif_ilog_file_prefix, reg_id_s);
if(event_file == NULL) {
edg_wll_SetError(context, ret=ENOMEM, "asprintf()");
goto out;
#endif
extern char *notif_ilog_socket_path;
+extern char *notif_ilog_file_prefix;
/** Send ULM notification string to interlogger.
* Stores notification to file according to registration id and send it
#ifndef NO_VOMS
-#include <voms_apic.h>
#include <openssl/ssl.h>
#include <libxml/parser.h>
#undef WITHOUT_TRIO
+#include "glite/security/voms/voms_apic.h"
#include "glite/wmsutils/jobid/strmd5.h"
#include "glite/wmsutils/jobid/cjobid.h"
#include "glite/lb/producer.h"
#include "lb_authz.h"
#include "lbs_db.h"
-GACLentry *GACLparseEntry(xmlNodePtr cur);
+/* XXX should be defined in gridsite-gacl.h */
+GRSTgaclEntry *GACLparseEntry(xmlNodePtr cur);
static int
add_groups(edg_wll_Context ctx, struct voms *voms_cert, char *vo_name,
X509 *peer_cert = NULL;
X509 *p_cert;
- maj_stat = gss_export_sec_context(&min_stat, gss->context, &buffer);
+ maj_stat = gss_export_sec_context(&min_stat, &gss->context, &buffer);
if (GSS_ERROR(maj_stat))
return -1; /* XXX */
+ /* The GSSAPI specs requires gss_export_sec_context() to destroy the context
+ * after exporting. So we have to resurrect the context here by importing
+ * from just generated buffer. I'm eagerly waiting for adaptations in the
+ * VOMS API to avoid these hacks */
+ maj_stat = gss_import_sec_context(&min_stat, &buffer, &gss->context);
+
bio = BIO_new(BIO_s_mem());
if (bio == NULL) {
ret = -1;
#if !defined(NO_VOMS) && !defined(NO_GACL)
static int
-parse_creds(edg_wll_VomsGroups *groups, char *subject, GACLuser **gacl_user)
+parse_creds(edg_wll_VomsGroups *groups, char *subject, GRSTgaclUser **gacl_user)
{
- GACLcred *cred = NULL;
- GACLuser *user = NULL;
+ GRSTgaclCred *cred = NULL;
+ GRSTgaclUser *user = NULL;
int ret;
int i;
- GACLinit();
+ GRSTgaclInit();
- cred = GACLnewCred("person");
+ cred = GRSTgaclCredNew("person");
if (cred == NULL)
return ENOMEM;
- if (!GACLaddToCred(cred, "dn", subject)) {
+ if (!GRSTgaclCredAddValue(cred, "dn", subject)) {
ret = EINVAL; /* GACL_ERR */
goto fail;
}
- user = GACLnewUser(cred);
+ user = GRSTgaclUserNew(cred);
if (user == NULL) {
ret = ENOMEM;
goto fail;
cred = NULL; /* GACLnewUser() doesn't copy content, just store the pointer */
for (i = 0; i < groups->len; i++) {
- cred = GACLnewCred("voms-cred");
+ cred = GRSTgaclCredNew("voms-cred");
if (cred == NULL) {
ret = ENOMEM;
goto fail;
}
- if (!GACLaddToCred(cred, "vo", groups->val[i].vo) ||
- !GACLaddToCred(cred, "group", groups->val[i].name)) {
+ if (!GRSTgaclCredAddValue(cred, "vo", groups->val[i].vo) ||
+ !GRSTgaclCredAddValue(cred, "group", groups->val[i].name)) {
ret = EINVAL; /* GACL_ERR */
goto fail;
}
- if (!GACLuserAddCred(user, cred)) {
+ if (!GRSTgaclUserAddCred(user, cred)) {
ret = EINVAL; /* GACL_ERR */
goto fail;
}
fail:
if (cred)
- GACLfreeCred(cred);
+ GRSTgaclCredFree(cred);
if (user)
- GACLfreeUser(user);
+ GRSTgaclUserFree(user);
return ret;
}
static int
-cmp_gacl_names(struct _GACLnamevalue *n1, struct _GACLnamevalue *n2)
+cmp_gacl_names(GRSTgaclNamevalue *n1, GRSTgaclNamevalue *n2)
{
if (n1 == NULL && n2 == NULL)
return 1;
- for ( ; n1; n1 = n1->next, n2 = n2->next) {
+ for ( ; n1; n1 = (GRSTgaclNamevalue *)n1->next, n2 = (GRSTgaclNamevalue *) n2->next) {
if (n2 == NULL)
return 0;
if (strcmp(n1->name, n2->name) != 0 ||
}
static int
-cmp_gacl_creds(GACLcred *c1, GACLcred *c2)
+cmp_gacl_creds(GRSTgaclCred *c1, GRSTgaclCred *c2)
{
if (strcmp(c1->type, c2->type) != 0)
return 0;
}
static int
-addEntry(GACLacl *acl, GACLentry *entry)
+addEntry(GRSTgaclAcl *acl, GRSTgaclEntry *entry)
{
- GACLentry *cur = NULL;
+ GRSTgaclEntry *cur = NULL;
if ( acl == NULL )
return EINVAL;
if ( acl->firstentry == NULL )
- return (GACLaddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0;
+ return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0;
for ( cur = acl->firstentry; cur; cur = cur->next )
if ( cmp_gacl_creds(cur->firstcred, entry->firstcred)
&& cur->denied == entry->denied )
return EEXIST;
- return (GACLaddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0;
+ return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0;
}
static int
-delEntry(GACLacl *acl, GACLentry *entry)
+delEntry(GRSTgaclAcl *acl, GRSTgaclEntry *entry)
{
- GACLentry *cur = NULL, *prev = NULL;
+ GRSTgaclEntry *cur = NULL, *prev = NULL;
int found = 0;
if (acl == NULL || acl->firstentry == NULL)
prev->next = cur->next;
else
acl->firstentry = cur->next;
- GACLfreeEntry(cur);
+ GRSTgaclEntryFree(cur);
found = 1;
break;
}
}
static int
-create_cred(char *userid, int user_type, GACLcred **cred)
+create_cred(char *userid, int user_type, GRSTgaclCred **cred)
{
- GACLcred *c = NULL;
+ GRSTgaclCred *c = NULL;
char *group = NULL;
if (user_type == EDG_WLL_USER_SUBJECT) {
- c = GACLnewCred("person");
+ c = GRSTgaclCredNew("person");
if (c == NULL)
return ENOMEM;
- if (!GACLaddToCred(c, "dn", userid)) {
- GACLfreeCred(c);
+ if (!GRSTgaclCredAddValue(c, "dn", userid)) {
+ GRSTgaclCredFree(c);
return -1; /* GACL_ERR */
}
} else if(user_type == EDG_WLL_USER_VOMS_GROUP) {
- c = GACLnewCred("voms-cred");
+ c = GRSTgaclCredNew("voms-cred");
if (c == NULL)
return ENOMEM;
group = strchr(userid, ':');
if ( !group )
return EINVAL;
*group++ = '\0';
- if (!GACLaddToCred(c, "vo", userid) ||
- !GACLaddToCred(c, "group", group)) {
- GACLfreeCred(c);
+ if (!GRSTgaclCredAddValue(c, "vo", userid) ||
+ !GRSTgaclCredAddValue(c, "group", group)) {
+ GRSTgaclCredFree(c);
return -1; /* GACL_ERR */
}
} else
}
static int
-change_acl(GACLacl *acl, GACLentry *entry, int operation)
+change_acl(GRSTgaclAcl *acl, GRSTgaclEntry *entry, int operation)
/* creds, permission, permission_type */
{
if (operation == EDG_WLL_ACL_ADD)
edg_wll_change_acl(edg_wll_Acl acl, char *user_id, int user_id_type,
int permission, int perm_type, int operation)
{
- GACLcred *cred = NULL;
- GACLentry *entry = NULL;
+ GRSTgaclCred *cred = NULL;
+ GRSTgaclEntry *entry = NULL;
int ret;
- GACLinit();
+ GRSTgaclInit();
if (acl == NULL || acl->value == NULL)
return EINVAL;
if (ret)
return ret;
- entry = GACLnewEntry();
+ entry = GRSTgaclEntryNew();
if (entry == NULL) {
ret = ENOMEM;
goto end;
}
- if (!GACLaddCred(entry, cred)) {
+ if (!GRSTgaclEntryAddCred(entry, cred)) {
ret = -1; /* GACLErr */
goto end;
}
if (perm_type == EDG_WLL_PERM_ALLOW)
- GACLallowPerm(entry, permission);
+ GRSTgaclEntryAllowPerm(entry, permission);
else if (perm_type == EDG_WLL_PERM_DENY)
- GACLdenyPerm(entry, permission);
+ GRSTgaclEntryDenyPerm(entry, permission);
else {
ret = EINVAL;
goto end;
if (ret)
{
/* XXX: mem leak?
- GACLfreeEntry(entry);
+ GRSTgaclEntryFree(entry);
*/
goto end;
}
edg_wll_CheckACL(edg_wll_Context ctx, edg_wll_Acl acl, int requested_perm)
{
int ret;
- GACLuser *user = NULL;
- GACLperm perm;
+ GRSTgaclUser *user = NULL;
+ unsigned int perm;
if (acl == NULL || acl->value == NULL)
return edg_wll_SetError(ctx,EINVAL,"CheckACL");
return edg_wll_SetError(ctx,ret,"parse_creds()");
}
- perm = GACLtestUserAcl(acl->value, user);
+ perm = GRSTgaclAclTestUser(acl->value, user);
- GACLfreeUser(user);
+ /* XXX GRSTgaclUserFree(user); */
if (perm & requested_perm) return edg_wll_ResetError(ctx);
else return edg_wll_SetError(ctx,EPERM,"CheckACL");
}
int
-edg_wll_EncodeACL(GACLacl *acl, char **str)
+edg_wll_EncodeACL(GRSTgaclAcl *acl, char **str)
{
int tmp_fd, ret;
FILE *fd = NULL;
fd = fdopen(tmp_fd, "r");
- ret = GACLsaveAcl(filename, acl);
+ ret = GRSTgaclAclSave(acl, filename);
unlink(filename);
if (ret == 0) {
ret = -1; /* GACL_ERR */
}
int
-edg_wll_DecodeACL(char *buf, GACLacl **result_acl)
+edg_wll_DecodeACL(char *buf, GRSTgaclAcl **result_acl)
{
/* Got from GACLloadAcl() available from GACL API */
xmlDocPtr doc;
xmlNodePtr cur;
- GACLacl *acl;
- GACLentry *entry;
+ GRSTgaclAcl *acl;
+ GRSTgaclEntry *entry;
doc = xmlParseMemory(buf, strlen(buf));
if (doc == NULL) return EINVAL;
cur = cur->xmlChildrenNode;
- acl = GACLnewAcl();
+ acl = GRSTgaclAclNew();
while (cur != NULL)
{
entry = GACLparseEntry(cur);
if (entry == NULL)
{
- GACLfreeAcl(acl);
+ GRSTgaclAclFree(acl);
xmlFreeDoc(doc);
return EINVAL;
}
- GACLaddEntry(acl, entry);
+ GRSTgaclAclAddEntry(acl, entry);
cur=cur->next;
}
if ( !tmp )
return ENOMEM;
- tmp->value = GACLnewAcl();
+ tmp->value = GRSTgaclAclNew();
tmp->string = NULL;
*acl = tmp;
return 0;
void
edg_wll_FreeAcl(edg_wll_Acl acl)
{
- if ( acl->value ) GACLfreeAcl(acl->value);
+ /* XXX if ( acl->value ) GRSTgaclAclFree(acl->value); */
if ( acl->string ) free(acl->string);
free(acl);
}
char *acl_str = NULL;
edg_wll_Stmt stmt = NULL;
int ret;
- GACLacl *gacl = NULL;
+ GRSTgaclAcl *gacl = NULL;
char *jobstr = edg_wlc_JobIdGetUnique(jobid);
if (jobid == NULL || jobstr == NULL)
if (stmt) edg_wll_FreeStmt(&stmt);
if (acl_id) free(acl_id);
if (acl_str) free(acl_str);
- if (gacl) GACLfreeAcl(gacl);
+ if (gacl) GRSTgaclAclFree(gacl);
if (jobstr) free(jobstr);
return edg_wll_Error(ctx, NULL, NULL);
#define LB_AUTHZ_H
#ifndef NO_GACL
-#include <gacl.h>
+#include <gridsite.h>
#endif
typedef struct _edg_wll_Acl {
#ifndef NO_GACL
- GACLacl *value;
+ GRSTgaclAcl *value;
#else
void *value; /* XXX */
#endif
edg_wll_CheckACL(edg_wll_Context, edg_wll_Acl, int);
extern int
-edg_wll_DecodeACL(char *, GACLacl **);
+edg_wll_DecodeACL(char *, GRSTgaclAcl **);
extern int
-edg_wll_EncodeACL(GACLacl *, char **);
+edg_wll_EncodeACL(GRSTgaclAcl *, char **);
extern int
edg_wll_GetACL(edg_wll_Context, edg_wlc_JobId, edg_wll_Acl *);
else if (!strncmp(requestPTR,KEY_PURGE_REQUEST,sizeof(KEY_PURGE_REQUEST)-1)) {
edg_wll_PurgeRequest request;
+ ctx->p_tmp_timeout.tv_sec = 86400;
+
if ( !parsePurgeRequest(ctx,messageBody,(int (*)()) edg_wll_StringToStat,&request) )
edg_wll_PurgeServer(ctx, (const edg_wll_PurgeRequest *)&request);
edg_wll_DumpRequest request;
edg_wll_DumpResult result;
+ ctx->p_tmp_timeout.tv_sec = 86400;
+
memset(&request,0,sizeof(request));
memset(&result,0,sizeof(result));
edg_wll_LoadRequest request;
edg_wll_LoadResult result;
+ ctx->p_tmp_timeout.tv_sec = 86400;
+
memset(&request,0,sizeof(request));
memset(&result,0,sizeof(result));
pw = slash+1;
db = colon+1;
- if (!mysql_real_connect((MYSQL *) ctx->mysql,host,user,pw,db,0,NULL,0)) {
+ /* ljocha: CLIENT_FOUND_ROWS added to make authorization check
+ * working in update_notif().
+ * Hope it does not break anything else */
+ if (!mysql_real_connect((MYSQL *) ctx->mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) {
free(buf);
return my_err();
}
#include "lbs_db.h"
-static char *get_user(edg_wll_Context ctx, int create);
-static int update_notif(edg_wll_Context, const edg_wll_NotifId,
- const char *, const char *, const char *);
+static char *get_user(edg_wll_Context ctx, int create);
+static int check_notif_request(edg_wll_Context, const edg_wll_NotifId, char **);
+static int split_cond_list(edg_wll_Context, edg_wll_QueryRec const * const *,
+ edg_wll_QueryRec ***, char ***);
+static int update_notif(edg_wll_Context, const edg_wll_NotifId,
+ const char *, const char *, const char *);
+
int edg_wll_NotifNewServer(
edg_wll_Context ctx,
const edg_wll_NotifId nid,
time_t *valid)
{
- int i, j,
- ct,
- new_rows;
+ int i;
char *q = NULL,
*nid_s = NULL,
*time_s = NULL,
goto cleanup;
/* Format conditions
- * - first of all separate all jobids
- * - then format new condition list without jobids and encode it into an XML string
+ * - separate all jobids
+ * - format new condition list without jobids
*/
- if ( !conditions || !conditions[0] )
- {
- edg_wll_SetError(ctx, EINVAL, "Empty condition list");
+ if ( split_cond_list(ctx, conditions, &nconds, &jobs) )
goto cleanup;
- }
- for ( new_rows = ct = i = 0; conditions[i]; i++ )
- {
- if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID )
- new_rows++;
- for ( j = 0; conditions[i][j].attr; j++ )
- if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID )
- ct++;
- }
- if ( !ct )
- {
- edg_wll_SetError(ctx, EINVAL, "Notification has to bind to at least one jobID");
- goto cleanup;
- }
- if ( !(jobs = calloc(ct+1, sizeof(char *)))
- || !(nconds = calloc(new_rows+1, sizeof(edg_wll_QueryRec *))) )
- {
- edg_wll_SetError(ctx, errno, NULL);
- goto cleanup;
- }
- for ( ct = i = 0; conditions[i]; i++ )
- for ( j = 0; conditions[i][j].attr; j++ )
- if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID )
- if ( !(jobs[ct++] = edg_wlc_JobIdGetUnique(conditions[i][j].value.j)) )
- {
- edg_wll_SetError(ctx, errno, NULL);
- goto cleanup;
- }
- for ( new_rows = i = 0; conditions[i]; i++ )
- if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID )
- /* !!! DO NOT DEALLOCATE this arrays (it is not neccessary to allocate new
- * mem - it's used only once and only for xml parsing
- */
- nconds[new_rows++] = (edg_wll_QueryRec *) (conditions[i]);
+
+ /*
+ * encode new cond. list into a XML string
+ */
if ( edg_wll_JobQueryRecToXML(ctx, (edg_wll_QueryRec const * const *) nconds, &xml_conds) )
{
/* XXX: edg_wll_JobQueryRecToXML() do not set errors in context!
const char *address_override,
time_t *valid)
{
- char *time_s = NULL;
+ char *time_s = NULL,
+ *addr_s = NULL;
if ( !address_override )
goto cleanup;
}
+ if ( check_notif_request(ctx, nid, NULL) )
+ goto cleanup;
+
/* Format time of validity
*/
*valid = time(NULL);
}
time_s[strlen(time_s)-1] = 0;
- update_notif(ctx, nid, NULL, address_override, (const char *)(time_s+1));
+ /* Format the address
+ */
+ if ( address_override )
+ {
+ char *aux;
+
+ if ( !(aux = strchr(address_override, ':')) )
+ {
+ edg_wll_SetError(ctx, EINVAL, "Addres overrirde not in format host:port");
+ goto cleanup;
+ }
+ if ( !strncmp(address_override, "0.0.0.0", aux-address_override) )
+ trio_asprintf(&addr_s, "%s:%s", ctx->connPool[ctx->connToUse].peerName, aux+1);
+ }
+
+
+ update_notif(ctx, nid, NULL, addr_s? addr_s: address_override, (const char *)(time_s+1));
cleanup:
if ( time_s ) free(time_s);
+ if ( addr_s ) free(addr_s);
return edg_wll_Error(ctx, NULL, NULL);
}
+
int edg_wll_NotifChangeServer(
edg_wll_Context ctx,
- const edg_wll_NotifId id,
+ const edg_wll_NotifId nid,
edg_wll_QueryRec const * const *conditions,
edg_wll_NotifChangeOp op)
{
- return edg_wll_SetError(ctx, EINVAL, "Not yet implemented");
+ int i;
+ char *q = NULL,
+ *nid_s = NULL,
+ *xml_conds = NULL,
+ **jobs = NULL;
+ edg_wll_QueryRec **nconds = NULL;
+
+
+ /* Format notification ID
+ */
+ if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
+ goto cleanup;
+
+ if ( check_notif_request(ctx, nid, NULL) )
+ goto cleanup;
+
+ switch ( op )
+ {
+ case EDG_WLL_NOTIF_REPLACE:
+ /* Format conditions
+ * - separate all jobids
+ * - format new condition list without jobids
+ */
+ if ( split_cond_list(ctx, conditions, &nconds, &jobs) )
+ goto cleanup;
+
+ /*
+ * encode new cond. list into a XML string
+ */
+ if ( edg_wll_JobQueryRecToXML(ctx, (edg_wll_QueryRec const * const *) nconds, &xml_conds) )
+ {
+ /* XXX: edg_wll_JobQueryRecToXML() do not set errors in context!
+ * can't get propper error number :(
+ */
+ edg_wll_SetError(ctx, errno, "Can't encode data into xml");
+ goto cleanup;
+ }
+
+ /* Format DB insert statement
+ */
+ if ( update_notif(ctx, nid, xml_conds, NULL, NULL) )
+ goto cleanup;
+
+ if ( jobs )
+ {
+ /* Format DB insert statement
+ */
+ trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
+ if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ goto cleanup;
+
+ for ( i = 0; jobs[i]; i++ )
+ {
+ free(q);
+ trio_asprintf(&q,
+ "insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
+ nid_s, jobs[i]);
+ if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
+ {
+ /* XXX: Remove uncoplete registration?
+ * Which error has to be returned?
+ */
+ free(q);
+ trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
+ edg_wll_ExecStmt(ctx, q, NULL);
+ free(q);
+ trio_asprintf(&q,"delete from notif_registrations where notifid='%|Ss'", nid_s);
+ edg_wll_ExecStmt(ctx, q, NULL);
+ goto cleanup;
+ }
+ }
+ }
+ break;
+
+ case EDG_WLL_NOTIF_ADD:
+ break;
+ case EDG_WLL_NOTIF_REMOVE:
+ break;
+ default:
+ break;
+ }
+
+cleanup:
+ if ( q ) free(q);
+ if ( xml_conds ) free(xml_conds);
+ if ( nid_s ) free(nid_s);
+ if ( jobs )
+ {
+ for ( i = 0; jobs[i]; i++ )
+ free(jobs[i]);
+ free(jobs);
+ }
+ if ( nconds ) free(nconds);
+
+ return edg_wll_Error(ctx, NULL, NULL);
}
int edg_wll_NotifRefreshServer(
char *time_s = NULL;
+ if ( check_notif_request(ctx, nid, NULL) )
+ goto cleanup;
+
/* Format time of validity
*/
*valid = time(NULL);
edg_wll_Context ctx,
edg_wll_NotifId *nid)
{
- char *owner = NULL,
- *nid_s = NULL,
+ char *nid_s = NULL,
*stmt;
int ret;
- if ( !(owner = get_user(ctx, 0)) )
- {
- if ( !edg_wll_Error(ctx, NULL, NULL) )
- edg_wll_SetError(ctx, EPERM, "Unknown user");
-
- return edg_wll_Error(ctx, NULL, NULL);
- }
+ if ( check_notif_request(ctx, nid, NULL) )
+ goto cleanup;
if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
goto cleanup;
- /* Only the owner could remove the notification registration
- */
- trio_asprintf(&stmt,
- "delete from notif_registrations where notifid='%|Ss' and userid='%|Ss'",
- nid_s, owner);
+ trio_asprintf(&stmt, "delete from notif_registrations where notifid='%|Ss'", nid_s);
if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
goto cleanup;
free(stmt);
- if ( ret == 0 )
- {
- trio_asprintf(&stmt,
- "select notifid from notif_registrations where notifid='%|Ss'", nid_s);
- ret = edg_wll_ExecStmt(ctx, stmt, NULL);
- if ( ret == 0 )
- edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
- else if ( ret > 0 )
- edg_wll_SetError(ctx, EPERM, NULL);
-
- goto cleanup;
- }
trio_asprintf(&stmt, "delete from notif_jobs where notifid='%|Ss'", nid_s);
edg_wll_ExecStmt(ctx, stmt, NULL);
cleanup:
- if ( owner ) free(owner);
if ( nid_s ) free(nid_s);
if ( stmt ) free(stmt);
return edg_wll_Error(ctx, NULL, NULL);
}
+
static char *get_user(edg_wll_Context ctx, int create)
{
edg_wll_Stmt stmt = NULL;
if ( !ctx->peerName )
{
- edg_wll_SetError(ctx, EPERM, "Annonymous notifications not allowed");
+ edg_wll_SetError(ctx, EPERM, "Annonymous access not allowed");
goto cleanup;
}
trio_asprintf(&q, "select userid from users where cert_subj='%|Ss'", ctx->peerName);
return userid;
}
-static int update_notif(
- edg_wll_Context ctx,
- const edg_wll_NotifId nid,
- const char *conds,
- const char *dest,
- const char *valid)
+
+static int check_notif_request(
+ edg_wll_Context ctx,
+ const edg_wll_NotifId nid,
+ char **owner)
{
- char *owner = NULL,
- *nid_s = NULL,
- *stmt, *aux;
+ char *nid_s = NULL,
+ *stmt, *user;
int ret;
- if ( !(owner = get_user(ctx, 0)) )
+ if ( !(user = get_user(ctx, 0)) )
{
if ( !edg_wll_Error(ctx, NULL, NULL) )
edg_wll_SetError(ctx, EPERM, "Unknown user");
if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
goto cleanup;
+ trio_asprintf(&stmt,
+ "select notifid from notif_registrations "
+ "where notifid='%|Ss' and userid='%|Ss'",
+ nid_s, user);
+
+ if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
+ goto cleanup;
+ if ( ret == 0 )
+ {
+ free(stmt);
+ trio_asprintf(&stmt,
+ "select notifid from notif_registrations where notifid='%|Ss'", nid_s);
+ ret = edg_wll_ExecStmt(ctx, stmt, NULL);
+ if ( ret == 0 )
+ edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
+ else if ( ret > 0 )
+ edg_wll_SetError(ctx, EPERM, "Only owner could access the notification");
+ }
+
+cleanup:
+ if ( !edg_wll_Error(ctx, NULL, NULL) && owner )
+ *owner = user;
+ else
+ free(user);
+ if ( nid_s ) free(nid_s);
+ if ( stmt ) free(stmt);
+
+ return edg_wll_Error(ctx, NULL, NULL);
+}
+
+
+ /* Format conditions
+ * - first of all separate all jobids
+ * - then format new condition list without jobids and encode it into an XML string
+ */
+static int split_cond_list(
+ edg_wll_Context ctx,
+ edg_wll_QueryRec const * const *conditions,
+ edg_wll_QueryRec ***nconds_out,
+ char ***jobs_out)
+{
+ edg_wll_QueryRec **nconds = NULL;
+ char **jobs = NULL;
+ int i, j, jobs_ct, nconds_ct;
+
+
+ if ( !conditions || !conditions[0] )
+ return edg_wll_SetError(ctx, EINVAL, "Empty condition list");
+
+ for ( nconds_ct = jobs_ct = i = 0; conditions[i]; i++ )
+ {
+ if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID )
+ nconds_ct++;
+ for ( j = 0; conditions[i][j].attr; j++ )
+ if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID )
+ jobs_ct++;
+ }
+
+ if ( jobs_out && jobs_ct )
+ if ( !(jobs = calloc(jobs_ct+1, sizeof(char *))) )
+ {
+ edg_wll_SetError(ctx, errno, NULL);
+ goto cleanup;
+ }
+
+ if ( nconds_out && nconds_ct )
+ if ( !(nconds = calloc(nconds_ct+1, sizeof(edg_wll_QueryRec *))) )
+ {
+ edg_wll_SetError(ctx, errno, NULL);
+ goto cleanup;
+ }
+
+ if ( jobs ) for ( jobs_ct = i = 0; conditions[i]; i++ )
+ for ( j = 0; conditions[i][j].attr; j++ )
+ if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID )
+ if ( !(jobs[jobs_ct++] = edg_wlc_JobIdGetUnique(conditions[i][j].value.j)) )
+ {
+ edg_wll_SetError(ctx, errno, NULL);
+ goto cleanup;
+ }
+
+ if ( nconds ) for ( nconds_ct = i = 0; conditions[i]; i++ )
+ if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID )
+ /* !!! DO NOT DEALLOCATE this arrays (it is not neccessary to allocate new
+ * mem - it's used only once and only for xml parsing
+ */
+ nconds[nconds_ct++] = (edg_wll_QueryRec *) (conditions[i]);
+
+ if ( jobs_out ) { *jobs_out = jobs; jobs = NULL; }
+ if ( nconds_out ) { *nconds_out = nconds; nconds = NULL; }
+
+cleanup:
+ if ( nconds ) free(nconds);
+ if ( jobs )
+ {
+ for ( i = 0; jobs[i]; i++ )
+ free(jobs[i]);
+ free(jobs);
+ }
+
+ return edg_wll_Error(ctx, NULL, NULL);
+}
+
+
+static int update_notif(
+ edg_wll_Context ctx,
+ const edg_wll_NotifId nid,
+ const char *conds,
+ const char *dest,
+ const char *valid)
+{
+ char *nid_s = NULL,
+ *stmt, *aux;
+ int ret;
+
+
+ if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
+ goto cleanup;
+
/* Format SQL update string
* (Only the owner could update the notification registration)
*/
- stmt = strdup("update notif_registrations set");
+ if ( !(stmt = strdup("update notif_registrations set")) )
+ {
+ edg_wll_SetError(ctx, errno, "updating notification records");
+ goto cleanup;
+ }
if ( dest )
{
trio_asprintf(&aux, "%s destination='%|Ss'", stmt, dest);
}
if ( conds )
{
- trio_asprintf(&aux, "%s %sconditions='%|Ss'",
+ trio_asprintf(&aux, "%s %sconditions='<and>%|Ss</and>'",
stmt, (dest||valid)? ",": "", conds);
free(stmt);
stmt = aux;
}
- trio_asprintf(&aux, "%s where notifid='%|Ss' and userid='%|Ss'",
- stmt, nid_s, owner);
+ trio_asprintf(&aux, "%s where notifid='%|Ss'", stmt, nid_s);
free(stmt);
stmt = aux;
ret = edg_wll_ExecStmt(ctx, stmt, NULL);
if ( ret == 0 )
edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
+ /*
+ * XXX: Be happy?
+ * May be: Rows matched: 1 Changed: 0 Warnings: 0 :-)
else if ( ret > 0 )
edg_wll_SetError(ctx, EPERM, "Updating notification records");
+ */
}
cleanup:
- if ( owner ) free(owner);
if ( nid_s ) free(nid_s);
if ( stmt ) free(stmt);
return edg_wll_Error(ctx, NULL, NULL);
}
+
+
--- /dev/null
+SELECT e.event,j.userid,j.dg_jobid,e.code,e.prog,e.host,u.cert_subj,e.time_stamp,e.usec,e.level,e.arrived FROM events e,users u,jobs j WHERE e.jobid=j.jobid AND e.userid=u.userid AND e.code != 0 AND (j.jobid='WrCEKje9QTXFiSOZuPMLtw')
+0 294de3557d9d00b3d2d8a1e6aab028cf https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 17 UserInterface lhun.ics.muni.cz anonymous 2003-08-07 11:08:40 432100 8 2003-08-07 11:08:40
+1 294de3557d9d00b3d2d8a1e6aab028cf https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 2 NetworkServer lhun.ics.muni.cz anonymous 2003-08-07 11:09:05 664600 8 2003-08-07 11:09:05
+
+select name,value from short_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 0
+JDL x
+JOBTYPE SIMPLE
+NS NNNSSSS
+NSUBJOBS 0
+PARENT https://lhun.ics.muni.cz:4850/Qt7utj80miXexi7bkxyhnA
+SEQCODE (nil)
+SRC_INSTANCE (nil)
+
+select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 0
+
+select name,value from short_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1
+FROM UserInterface
+FROM_HOST sending component hostname
+FROM_INSTANCE sending component instance
+LOCAL_JOBID new jobId (Condor Globus ...)
+SEQCODE UI=000002:NS=0000000001:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000
+SRC_INSTANCE
+
+select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1
--- /dev/null
+#include <fstream>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include <glite/lb/consumer.h>
+#include <glite/lb/context-int.h>
+
+#include "lbs_db.h"
+#include "get_events.h"
+
+using namespace std;
+
+static const char *test_dir;
+
+class QueryEventsTest: public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(QueryEventsTest);
+ CPPUNIT_TEST(oneJob);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ edg_wll_Context ctx;
+
+ ifstream qry_file;
+
+ vector<pair<string,vector<string> > > queries;
+
+public:
+ void oneJob();
+ int ExecStmt(const char *, edg_wll_Stmt *);
+
+ void setUp() {
+ edg_wll_InitContext(&ctx);
+ ctx->mysql = (void *) this; /* XXX */
+ }
+
+};
+
+void QueryEventsTest::oneJob()
+{
+ edg_wll_QueryRec job[2];
+ const edg_wll_QueryRec *jobs[2] = { job,NULL} ;
+ edg_wll_Event *events;
+
+ job[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
+ job[0].op = EDG_WLL_QUERY_OP_EQUAL ;
+ edg_wlc_JobIdParse("https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw",
+ &job[0].value.j);
+ job[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
+
+ string file(test_dir);
+ file += "/oneJob.qry";
+ qry_file.open(file.c_str());
+
+ while (!qry_file.eof()) {
+ string query,line;
+ vector<string> rows;
+
+ getline(qry_file,query);
+ cout << "read: " << query <<endl;
+ rows.clear();
+
+ while (!qry_file.eof()) {
+ getline(qry_file,line);
+ if (line == "") break;
+
+ rows.push_back(line);
+ }
+ rows.push_back("END");
+ queries.push_back(pair<string,vector<string> >(query,rows));
+ }
+
+ qry_file.close();
+
+ CPPUNIT_ASSERT(!edg_wll_QueryEventsServer(ctx,1,jobs,NULL,&events));
+}
+
+int QueryEventsTest::ExecStmt(const char *qry, edg_wll_Stmt *stmt_out)
+{
+ vector<pair<string,vector<string> > >::iterator stmt = queries.begin();
+
+ for (; stmt != queries.end(); stmt++) {
+ const char *q = stmt->first.c_str();
+
+ /* XXX: there some spaces at the end of qry */
+ if (!strncmp(q,qry,strlen(q))) break;
+ }
+
+ if (stmt == queries.end()) {
+ cerr << "query not found" << endl;
+ CPPUNIT_ASSERT(0);
+ }
+ vector<string>::iterator *rows = new vector<string>::iterator(stmt->second.begin());
+
+ *stmt_out = (edg_wll_Stmt) rows;
+ return stmt->second.size()-1;
+}
+
+extern "C" {
+
+int edg_wll_ExecStmt(edg_wll_Context ctx,char *qry,edg_wll_Stmt *stmt)
+{
+ cout << "edg_wll_ExecStmt: " << qry << endl;
+
+ class QueryEventsTest *tst = (class QueryEventsTest *)(ctx->mysql);
+ return tst->ExecStmt(qry, stmt);
+}
+
+int edg_wll_FetchRow(edg_wll_Stmt stmt, char **cols)
+{
+ vector<string>::iterator *rows = (vector<string>::iterator *) stmt;
+ char *row,*p,i=0;
+
+ if (**rows == "END") return 0;
+ row = strdup((*rows)->c_str());
+ (*rows)++;
+ for (p = strtok(row,"\t"); p; p = strtok(NULL,"\t"))
+ cols[i++] = strdup(p);
+
+ return i;
+}
+
+void edg_wll_FreeStmt(edg_wll_Stmt *) {}
+
+int debug;
+
+int edg_wll_QueryColumns(edg_wll_Stmt stmt, char**cols) {}
+char *edg_wll_TimeToDB(long t) {}
+
+time_t edg_wll_DBToTime(char *c) {}
+edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, char*str) {}
+
+
+
+
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(QueryEventsTest);
+
+int main (int ac,const char *av[])
+{
+ CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+ CppUnit::TextUi::TestRunner runner;
+
+ test_dir = ac >= 2 ? av[1] : "../test";
+
+ runner.addTest(suite);
+ return runner.run() ? 0 : 1;
+}