Obsolete
/
libipc-old
Archived
3
0
Fork 0

networkd -> ipcd

pollfd
Karchnu 2020-07-01 14:24:45 +02:00
parent 2bba5cb232
commit b6f32819e5
4 changed files with 34 additions and 39 deletions

View File

@ -43,14 +43,14 @@ struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname)
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} }
// when networkd is not working properly (or do not retrieve the service): srv->fd = 0 // when ipcd is not working properly (or do not retrieve the service): srv->fd = 0
struct ipc_error ipc_contact_networkd (int *pfd, const char *sname) struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname)
{ {
T_R ((pfd == NULL), IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM); T_R ((pfd == NULL), IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM);
T_R ((sname == NULL), IPC_ERROR_CONTACT_NETWORKD__NO_SERVICE_NAME_PARAM); T_R ((sname == NULL), IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM);
char *networkvar = getenv ("IPC_NETWORK"); char *ipcd_var = getenv ("IPC_NETWORK");
if (networkvar == NULL) { if (ipcd_var == NULL) {
*pfd = 0; *pfd = 0;
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} }
@ -63,7 +63,7 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname)
columnthensname[0] = ';'; columnthensname[0] = ';';
memcpy (columnthensname + 1, sname, strlen (sname)); memcpy (columnthensname + 1, sname, strlen (sname));
if (strncmp (networkvar, sname, strlen (sname)) != 0 && strstr (networkvar, columnthensname) == NULL) { if (strncmp (ipcd_var, sname, strlen (sname)) != 0 && strstr (ipcd_var, columnthensname) == NULL) {
*pfd = 0; *pfd = 0;
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} }
@ -72,31 +72,31 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname)
SECURE_BUFFER_DECLARATION (char, buf, PATH_MAX); SECURE_BUFFER_DECLARATION (char, buf, PATH_MAX);
TEST_IPC_RR (service_path (buf, "network"), "cannot get network service path"); TEST_IPC_RR (service_path (buf, "network"), "cannot get network service path");
int networkdfd = 0; int ipcd_fd = 0;
TEST_IPC_RETURN_ON_ERROR (usock_connect (&networkdfd, buf)); TEST_IPC_RETURN_ON_ERROR (usock_connect (&ipcd_fd, buf));
SECURE_DECLARATION (struct ipc_message, msg); SECURE_DECLARATION (struct ipc_message, msg);
msg.type = MSG_TYPE_NETWORK_LOOKUP; msg.type = MSG_TYPE_NETWORK_LOOKUP;
msg.user_type = MSG_TYPE_NETWORK_LOOKUP; msg.user_type = MSG_TYPE_NETWORK_LOOKUP;
SECURE_BUFFER_DECLARATION (char, content, BUFSIZ); SECURE_BUFFER_DECLARATION (char, content, BUFSIZ);
snprintf (content, BUFSIZ, "%s;%s", sname, networkvar); snprintf (content, BUFSIZ, "%s;%s", sname, ipcd_var);
msg.length = strlen (content); msg.length = strlen (content);
msg.payload = content; msg.payload = content;
TEST_IPC_RR (ipc_write_fd (networkdfd, &msg), "cannot send a message to networkd"); TEST_IPC_RR (ipc_write_fd (ipcd_fd, &msg), "cannot send a message to networkd");
struct ipc_error ret = ipc_receive_fd (networkdfd, pfd); struct ipc_error ret = ipc_receive_fd (ipcd_fd, pfd);
if (ret.error_code == IPC_ERROR_NONE) { if (ret.error_code == IPC_ERROR_NONE) {
usock_close (networkdfd); usock_close (ipcd_fd);
} }
return ret; return ret;
} }
// Create context, contact networkd, connects to the service. // Create context, contact ipcd, connects to the service.
struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname) struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname)
{ {
T_R ((ctx == NULL), IPC_ERROR_CONNECTION__NO_CTX); T_R ((ctx == NULL), IPC_ERROR_CONNECTION__NO_CTX);
@ -107,9 +107,9 @@ struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname)
SECURE_DECLARATION(struct pollfd, pollfd); SECURE_DECLARATION(struct pollfd, pollfd);
pollfd.events = POLLIN; pollfd.events = POLLIN;
TEST_IPC_P (ipc_contact_networkd (&pollfd.fd, sname), "error during networkd connection"); TEST_IPC_P (ipc_contact_ipcd (&pollfd.fd, sname), "error during networkd connection");
// if networkd did not initiate the connection // if ipcd did not initiate the connection
if (pollfd.fd <= 0) { if (pollfd.fd <= 0) {
// gets the service path // gets the service path
SECURE_BUFFER_DECLARATION (char, buf, PATH_MAX); SECURE_BUFFER_DECLARATION (char, buf, PATH_MAX);
@ -336,7 +336,7 @@ struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx
struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ctx, int index) struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ctx, int index)
{ {
// If the socket is associated to another one for networkd: // If the socket is associated to another one for ipcd:
// read and write automatically and provide a new IPC_EVENT_TYPE indicating the switch. // read and write automatically and provide a new IPC_EVENT_TYPE indicating the switch.
if (ctx->switchdb.collection != NULL) { if (ctx->switchdb.collection != NULL) {
int talkingfd = ctx->pollfd[index].fd; int talkingfd = ctx->pollfd[index].fd;
@ -370,7 +370,7 @@ struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ct
if (buf != NULL) if (buf != NULL)
free (buf); free (buf);
// Everything is OK: inform networkd of a successful transfer. // Everything is OK: inform ipcd of a successful transfer.
IPC_EVENT_SET (event, IPC_EVENT_TYPE_SWITCH, index, ctx->pollfd[index].fd, NULL); IPC_EVENT_SET (event, IPC_EVENT_TYPE_SWITCH, index, ctx->pollfd[index].fd, NULL);
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} else if (msize == 0) { } else if (msize == 0) {

View File

@ -40,8 +40,8 @@ static struct ipc_errors_verbose ipc_errors_verbose[] = {
, {IPC_ERROR_WAIT_EVENT__NO_CLIENTS_PARAM, "ipc_wait_event: no clients param"} , {IPC_ERROR_WAIT_EVENT__NO_CLIENTS_PARAM, "ipc_wait_event: no clients param"}
, {IPC_ERROR_WAIT_EVENT__NO_EVENT_PARAM , "ipc_wait_event: no event param"} , {IPC_ERROR_WAIT_EVENT__NO_EVENT_PARAM , "ipc_wait_event: no event param"}
, {IPC_ERROR_CONTACT_NETWORKD__NO_SERVICE_NAME_PARAM, "ipc_contact_networkd: no service name param"} , {IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM, "ipc_contact_ipcd: no service name param"}
, {IPC_ERROR_CONTACT_NETWORKD__NO_SERVER_PARAM , "ipc_contact_networkd: no server param"} , {IPC_ERROR_CONTACT_IPCD__NO_SERVER_PARAM , "ipc_contact_ipcd: no server param"}
, {IPC_ERROR_HANDLE_NEW_CONNECTION__MALLOC, "ipc_handle_new_connection: error on malloc function"} , {IPC_ERROR_HANDLE_NEW_CONNECTION__MALLOC, "ipc_handle_new_connection: error on malloc function"}
@ -133,7 +133,7 @@ static struct ipc_errors_verbose ipc_errors_verbose[] = {
, {IPC_ERROR_CONNECTION__NO_CTX, "IPC_ERROR_CONNECTION__NO_CTX"} , {IPC_ERROR_CONNECTION__NO_CTX, "IPC_ERROR_CONNECTION__NO_CTX"}
, {IPC_ERROR_CTX_INIT__MALLOC_CTX, "IPC_ERROR_CTX_INIT__MALLOC_CTX"} , {IPC_ERROR_CTX_INIT__MALLOC_CTX, "IPC_ERROR_CTX_INIT__MALLOC_CTX"}
, {IPC_ERROR_CTX_INIT__MALLOC_POLLFD, "IPC_ERROR_CTX_INIT__MALLOC_POLLFD"} , {IPC_ERROR_CTX_INIT__MALLOC_POLLFD, "IPC_ERROR_CTX_INIT__MALLOC_POLLFD"}
, {IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM, "IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM"} , {IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM, "IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM"}
, {IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX, "IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX"} , {IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX, "IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX"}
, {IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES, "IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES"} , {IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES, "IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES"}
, {IPC_ERROR_MESSAGE_DEL__INDEX_ERROR, "IPC_ERROR_MESSAGE_DEL__INDEX_ERROR"} , {IPC_ERROR_MESSAGE_DEL__INDEX_ERROR, "IPC_ERROR_MESSAGE_DEL__INDEX_ERROR"}

View File

@ -122,8 +122,8 @@ enum ipc_error_code {
, IPC_ERROR_DEL_FD__EMPTIED_LIST = 33 , IPC_ERROR_DEL_FD__EMPTIED_LIST = 33
, IPC_ERROR_DEL_FD__EMPTY_LIST = 34 , IPC_ERROR_DEL_FD__EMPTY_LIST = 34
, IPC_ERROR_DEL_FD__CANNOT_FIND_CLIENT = 35 , IPC_ERROR_DEL_FD__CANNOT_FIND_CLIENT = 35
, IPC_ERROR_CONTACT_NETWORKD__NO_SERVICE_NAME_PARAM = 36 , IPC_ERROR_CONTACT_IPCD__NO_SERVICE_NAME_PARAM = 36
, IPC_ERROR_CONTACT_NETWORKD__NO_SERVER_PARAM = 37 , IPC_ERROR_CONTACT_IPCD__NO_SERVER_PARAM = 37
, IPC_ERROR_DEL__EMPTY_LIST = 38 , IPC_ERROR_DEL__EMPTY_LIST = 38
, IPC_ERROR_DEL__EMPTIED_LIST = 39 , IPC_ERROR_DEL__EMPTIED_LIST = 39
, IPC_ERROR_DEL__CANNOT_FIND_CLIENT = 40 , IPC_ERROR_DEL__CANNOT_FIND_CLIENT = 40
@ -185,7 +185,7 @@ enum ipc_error_code {
, IPC_ERROR_CONNECTION__NO_CTX = 95 , IPC_ERROR_CONNECTION__NO_CTX = 95
, IPC_ERROR_CTX_INIT__MALLOC_CTX = 96 , IPC_ERROR_CTX_INIT__MALLOC_CTX = 96
, IPC_ERROR_CTX_INIT__MALLOC_POLLFD = 97 , IPC_ERROR_CTX_INIT__MALLOC_POLLFD = 97
, IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM = 98 , IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM = 98
, IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX = 99 , IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX = 99
, IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100 , IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100
, IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101 , IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101
@ -351,29 +351,24 @@ void ipc_messages_free (struct ipc_messages *);
**/ **/
struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m); struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m);
struct ipc_error ipc_ctx_init (struct ipc_ctx **);
struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx); struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx);
struct ipc_error service_path (char *path, const char *sname); struct ipc_error service_path (char *path, const char *sname);
struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index); struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index);
/**
* Used by ipc_server_init and ipc_connection
*/
struct ipc_error ipc_ctx_init (struct ipc_ctx **);
void ipc_connection_print (struct ipc_connection_info *cinfo); void ipc_connection_print (struct ipc_connection_info *cinfo);
void ipc_connections_print (struct ipc_ctx *cinfos); void ipc_connections_print (struct ipc_ctx *cinfos);
// Last parameter is the index for the server fd in the context structure. // Last parameter is the index for the server fd in the context structure.
struct ipc_error ipc_accept_add (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index); struct ipc_error ipc_accept_add (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index);
struct ipc_error ipc_contact_networkd (int *pfd, const char *sname); struct ipc_error ipc_contact_ipcd (int *pfd, const char *sname);
struct ipc_error service_path (char *path, const char *sname); struct ipc_error service_path (char *path, const char *sname);
/*** /***
* networkd enumerations, structures and functions * ipcd enumerations, structures and functions
**/ **/
struct networkd { struct ipcd {
int cpt; int cpt;
struct ipc_connection_info *srv; struct ipc_connection_info *srv;
struct ipc_ctx *clients; struct ipc_ctx *clients;
@ -381,7 +376,7 @@ struct networkd {
}; };
struct ipc_error struct ipc_error
ipc_wait_event_networkd (struct ipc_ctx *cinfos ipc_wait_event_ipcd (struct ipc_ctx *cinfos
, struct ipc_connection_info *cinfo // cinfo is NULL for clients , struct ipc_connection_info *cinfo // cinfo is NULL for clients
, struct ipc_event *event, struct ipc_switchings *switchdb, int *timer); , struct ipc_event *event, struct ipc_switchings *switchdb, int *timer);

View File

@ -20,12 +20,12 @@
/** /**
* TODO: * TODO:
* describe a protocol to get this working into networkd * describe a protocol to get this working into ipcd
* asking networkd for a fd with an URI * asking ipcd for a fd with an URI
* URI should contain: who (the service name), where (destination), how (protocol) * URI should contain: who (the service name), where (destination), how (protocol)
* networkd initiates a communication with the requested service * ipcd initiates a communication with the requested service
* networkd sends the fd * ipcd sends the fd
* get a networkd working with this * get a ipcd working with this
*/ */
struct ipc_error ipc_receive_fd (int sock, int *fd) struct ipc_error ipc_receive_fd (int sock, int *fd)