diff --git a/qse/include/qse/net/Makefile.am b/qse/include/qse/net/Makefile.am index c8431816..48630e4b 100644 --- a/qse/include/qse/net/Makefile.am +++ b/qse/include/qse/net/Makefile.am @@ -1,4 +1,4 @@ pkgincludedir= $(includedir)/qse/net -pkginclude_HEADERS = http.h htre.h htrd.h httpd.h +pkginclude_HEADERS = http.h htre.h htrd.h httpd.h upxd.h diff --git a/qse/include/qse/net/httpd.h b/qse/include/qse/net/httpd.h index fc06819e..aaad49ac 100644 --- a/qse/include/qse/net/httpd.h +++ b/qse/include/qse/net/httpd.h @@ -1,5 +1,5 @@ /* - * $Id: htrd.h 223 2008-06-26 06:44:41Z baconevi $ + * $Id$ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. diff --git a/qse/include/qse/net/upxd.h b/qse/include/qse/net/upxd.h new file mode 100644 index 00000000..2a340589 --- /dev/null +++ b/qse/include/qse/net/upxd.h @@ -0,0 +1,89 @@ +/* + * $Id$ + * + Copyright 2006-2011 Chung, Hyung-Hwan. + This file is part of QSE. + + QSE is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + QSE 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with QSE. If not, see . + */ + +#ifndef _QSE_NET_UPXD_H_ +#define _QSE_NET_UPXD_H_ + +#include +#include + +typedef struct qse_upxd_t qse_upxd_t; +typedef struct qse_upxd_client_t qse_upxd_client_t; +typedef struct qse_upxd_server_t qse_upxd_server_t; + +enum qse_upxd_errnum_t +{ + QSE_UPXD_ENOERR, + QSE_UPXD_ENOMEM, + QSE_UPXD_EINVAL, + QSE_UPXD_EACCES, + QSE_UPXD_ENOENT, + QSE_UPXD_EEXIST, + QSE_UPXD_EINTR, + QSE_UPXD_EAGAIN, + + QSE_UPXD_ENOIMPL, + QSE_UPXD_EOTHER +}; +typedef qse_upxd_errnum_t qse_upxd_errnum_t; + +struct qse_upxd_server_t +{ + qse_upxd_server_t* next; + /* ------------------------------ */ + qse_nwad_t nwad; + qse_ubi_t handle; +}; + +struct qse_upxd_client_t +{ + qse_nwad_t remote_addr; + qse_nwad_t local_addr; +}; + +struct qse_upxd_cbs_t +{ + struct + { + int (*open) (qse_upxd_t* upxd, qse_upxd_server_t* server); + void (*close) (qse_upxd_t* upxd, qse_upxd_server_t* server); + + qse_ssize_t (*recv) ( + qse_upxd_t* upxd, + qse_upxd_client_t* client, + qse_mchar_t* buf, qse_size_t bufsize); + + qse_ssize_t (*send) ( + qse_upxd_t* upxd, + qse_upxd_client_t* client, + const qse_mchar_t* buf, qse_size_t bufsize); + } server; +}; + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/qse/lib/net/Makefile.am b/qse/lib/net/Makefile.am index 34fdce10..2cf4d0da 100644 --- a/qse/lib/net/Makefile.am +++ b/qse/lib/net/Makefile.am @@ -15,7 +15,8 @@ libqsenet_la_SOURCES = \ httpd-cgi.c \ httpd-proxy.c \ httpd-resol.c \ - httpd-task.c + httpd-task.c \ + upxd.c libqsenet_la_LDFLAGS = -version-info 1:0:0 -no-undefined -L../cmn -L$(libdir) libqsenet_la_LIBADD = -lqsecmn diff --git a/qse/lib/net/upxd.c b/qse/lib/net/upxd.c new file mode 100644 index 00000000..53bf44b3 --- /dev/null +++ b/qse/lib/net/upxd.c @@ -0,0 +1,109 @@ +/* + * $Id$ + * + Copyright 2006-2011 Chung, Hyung-Hwan. + This file is part of QSE. + + QSE is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + QSE 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with QSE. If not, see . + */ + +#include "upxd.h" + +qse_upxd_t* qse_upxd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) +{ + qse_upxd_t* upxd; + + upxd = (qse_upxd_t*) QSE_MMGR_ALLOC ( + mmgr, QSE_SIZEOF(*upxd) + xtnsize + ); + if (upxd == QSE_NULL) return QSE_NULL; + + if (qse_upxd_init (upxd, mmgr) <= -1) + { + QSE_MMGR_FREE (upxd->mmgr, upxd); + return QSE_NULL; + } + + return upxd; +} + +void qse_upxd_close (qse_upxd_t* upxd) +{ + qse_upxd_fini (upxd); + QSE_MMGR_FREE (upxd->mmgr, upxd); +} + +int qse_upxd_init (qse_upxd_t* upxd, qse_mmgr_t* mmgr) +{ + QSE_MEMSET (upxd, 0, QSE_SIZEOF(*upxd)); + upxd->mmgr = mmgr; + return 0; +} + +void qse_upxd_fini (qse_upxd_t* upxd) +{ + free_server_list (upxd, upxd->server.list); + QSE_ASSERT (upxd->server.navail == 0); + upxd->server.list = QSE_NULL; +} + +void qse_upxd_stop (qse_upxd_t* upxd) +{ + upxd->stopreq = 1; +} + +qse_upxd_errnum_t qse_upxd_geterrnum (qse_upxd_t* upxd) +{ + return upxd->errnum; +} + +void qse_upxd_seterrnum (qse_upxd_t* upxd, qse_upxd_errnum_t errnum) +{ + upxd->errnum = errnum; +} + +int qse_upxd_addserver (qse_upxd_t* upxd, const qse_nwad_t* nwad) +{ + qse_upxd_server_t* server; + + server = QSE_MMGR_ALLOC (upxd->mmgr, QSE_SIZEOF(*server)); + if (server == QSE_NULL) + { + upxd->errnum = QSE_UPXD_ENOMEM; + return -1; + } + + QSE_MEMSET (server, 0, QSE_SIZEOF(*server)); + server->nwad = *nwad; + + if (upxd->cbs->server.open (upxd, server) <= -1) + { + QSE_MMGR_FREE (upxd->mmgr, server); + return -1; + } + + server->next = upxd->server.list; + upxd->server.list = server; +} + +int qse_upxd_loop (qse_upxd_t* upxd, qse_upxd_cbls_t* cbs) +{ + upxd->stopreq = 0; + + while (!upxd->stopreq) + { + } + + return 0; +} diff --git a/qse/lib/net/upxd.h b/qse/lib/net/upxd.h new file mode 100644 index 00000000..ce4e393b --- /dev/null +++ b/qse/lib/net/upxd.h @@ -0,0 +1,36 @@ +/* + * $Id$ + * + Copyright 2006-2011 Chung, Hyung-Hwan. + This file is part of QSE. + + QSE is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + QSE 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with QSE. If not, see . + */ + +#ifndef _QSE_LIB_NET_UPXD_H_ +#define _QSE_LIB_NET_UPXD_H_ + +#include + +struct qse_upxd_t +{ + int stopreq; + + struct + { + qse_upxd_server_t* list; + } server; +}; + +#endif