diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,7 @@ libdistrencommon_la_SOURCES = src/common src/common/execio.c src/common/execio.h \ src/common/misc.c src/common/misc.h \ src/common/options.c src/common/options.h \ - src/common/protocol.h \ + src/common/protocol.c src/common/protocol.h \ src/common/remoteio.h \ src/common/remoteio.c src/common/libremoteio.h #see http://sources.redhat.com/autobook/autobook/autobook_91.html diff --git a/src/common/protocol.c b/src/common/protocol.c new file mode 100644 --- /dev/null +++ b/src/common/protocol.c @@ -0,0 +1,50 @@ +/* + Copyright 2009 Nathan Phillip Brink + + This file is a part of DistRen. + + DistRen is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DistRen is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with DistRen. If not, see . +*/ + +#include "protocol.h" + +#include + +#define DISTREN_REQUEST_MAGIC (0x32423434) + +int distren_request_new(struct distren_request **req, uint32_t len, enum distren_request_type type) +{ + struct distren_request *newreq; + + newreq = malloc(sizeof(struct distren_request)); + if(!newreq) + { + (*req) = NULL; + return 1; + } + + newreq->magic = DISTREN_REQUEST_MAGIC; + newreq->len = len; + newreq->enumsize = sizeof(enum distren_request_type); + newreq->type = type; + + (*req) = newreq; + return 0; +} + +int distren_request_free(struct distren_request *req) +{ + free(req); + return 0; +} diff --git a/src/common/protocol.h b/src/common/protocol.h --- a/src/common/protocol.h +++ b/src/common/protocol.h @@ -17,6 +17,11 @@ along with DistRen. If not, see . */ +#ifndef DISTREN_PROTOCOL_H +#define DISTREN_PROTOCOL_H + +#include + /** Server types: */ @@ -63,3 +68,23 @@ enum distren_request_type DISTREN_REQUEST_GETWORK = 11, }; + +struct distren_request +{ + uint32_t magic; + uint32_t len; + uint8_t enumsize; + enum distren_request_type type; +}; + +/** + initializes request + */ +int distren_request_new(struct distren_request **req, uint32_t len, enum distren_request_type type); + +/** + frees request + */ +int distren_request_free(struct distren_request *req); + +#endif