Dpid services list is now a vector.
This commit is contained in:
+20
-12
@@ -19,6 +19,9 @@
|
||||
/*! \file
|
||||
* Main functions to set-up dpi information and to initialise sockets
|
||||
*/
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h> /* for exit */
|
||||
#include <fcntl.h> /* for F_SETFD, F_GETFD, FD_CLOEXEC */
|
||||
@@ -45,6 +48,8 @@ using namespace std::literals::string_literals;
|
||||
|
||||
#define QUEUE 5
|
||||
|
||||
struct service;
|
||||
|
||||
volatile sig_atomic_t caught_sigchld = 0;
|
||||
char *SharedKey = NULL;
|
||||
|
||||
@@ -92,16 +97,17 @@ void free_plugin_list(struct dp **dpi_attr_list_ptr, int numdpis)
|
||||
|
||||
/*! Free memory used by the services list
|
||||
*/
|
||||
void free_services_list(Dlist *s_list)
|
||||
void free_services_list(std::vector< service * > *s_list)
|
||||
{
|
||||
int i = 0;
|
||||
struct service *s;
|
||||
|
||||
for (i=0; i < dList_length(s_list) ; i++) {
|
||||
s = reinterpret_cast< service * >( dList_nth_data(s_list, i) );
|
||||
for (i=0; i < s_list->size() ; i++) {
|
||||
s = s_list->at( i );
|
||||
dFree(s->name);
|
||||
delete s;
|
||||
}
|
||||
dList_free(s_list);
|
||||
delete s_list;
|
||||
}
|
||||
|
||||
/*! Signal handler for SIGINT, SIGQUIT, and SIGTERM. Calls cleanup
|
||||
@@ -449,7 +455,7 @@ static int services_alpha_comp(const struct service *s1,
|
||||
* \li Returns number of available services on success
|
||||
* \li -1 on failure
|
||||
*/
|
||||
int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
|
||||
int fill_services_list(struct dp *attlist, int numdpis, std::vector< service * > **services_list)
|
||||
{
|
||||
FILE *dpidrc_stream;
|
||||
char *p, *line = NULL, *service, *path;
|
||||
@@ -494,7 +500,7 @@ int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
|
||||
fclose(dpidrc_stream);
|
||||
return -1;
|
||||
}
|
||||
*services_list = dList_new(8);
|
||||
*services_list = std::make_unique< std::vector< struct service * > >().release();
|
||||
|
||||
/* dpidrc parser loop */
|
||||
for (;(line = dGetline_unsafe(dpidrc_stream)) != NULL; dFree(line)) {
|
||||
@@ -513,12 +519,12 @@ int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
|
||||
if (strcmp(service, "dpi_dir") == 0)
|
||||
continue;
|
||||
|
||||
s = dNew(struct service, 1);
|
||||
s = std::make_unique< struct service >().release();
|
||||
/* init services list entry */
|
||||
s->name = dStrdup(service);
|
||||
s->dp_index = -1;
|
||||
|
||||
dList_append(*services_list, s);
|
||||
(*services_list)->push_back( s );
|
||||
/* search the dpi for a service by its path */
|
||||
for (i = 0; i < numdpis; i++)
|
||||
if ((p = strstr(attlist[i].path, path)) && *(p - 1) == '/' &&
|
||||
@@ -530,13 +536,13 @@ int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
|
||||
}
|
||||
fclose(dpidrc_stream);
|
||||
|
||||
dList_sort(*services_list, (dCompareFunc)services_alpha_comp);
|
||||
std::sort( begin( **services_list ), end( **services_list ), services_alpha_comp );
|
||||
|
||||
dFree(dpidrc);
|
||||
dFree(sys_dpidir);
|
||||
dFree(user_dpidir);
|
||||
|
||||
return (dList_length(*services_list));
|
||||
return (*services_list)->size();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -888,9 +894,11 @@ void send_sockport(int sock_fd, char *dpi_tag, struct dp *dpi_attr_list)
|
||||
|
||||
dReturn_if_fail((dpi_id = get_message(sock_fd, dpi_tag)) != NULL);
|
||||
|
||||
serv = reinterpret_cast< service * >( dList_find_custom(services_list,dpi_id,(dCompareFunc)service_match) );
|
||||
auto found= std::find_if( begin( *services_list ), end( *services_list ),
|
||||
[dpi_id]( const auto &service ){ return 0 == service_match( service, dpi_id ); } );
|
||||
serv= found == end( *services_list ) ? nullptr : *found;
|
||||
|
||||
if (serv == NULL || (i = serv->dp_index) == -1)
|
||||
if (serv == nullptr || (i = serv->dp_index) == -1)
|
||||
for (i = 0; i < numdpis; i++)
|
||||
if (!strncmp(dpi_attr_list[i].id, dpi_id,
|
||||
dpi_attr_list[i].id - strchr(dpi_attr_list[i].id, '.')))
|
||||
|
||||
Reference in New Issue
Block a user