Capi doesn't use dList anymore.

This commit is contained in:
2026-01-11 01:13:05 -05:00
parent b7e2884b68
commit 740c1d4192
+16 -15
View File
@@ -37,7 +37,8 @@
/* for testing dpi chat */ /* for testing dpi chat */
#include "bookmark.hh" #include "bookmark.hh"
typedef struct { struct capi_conn_t
{
DilloUrl *url; /**< local copy of web->url */ DilloUrl *url; /**< local copy of web->url */
void *bw; void *bw;
char *server; char *server;
@@ -48,7 +49,7 @@ typedef struct {
ChainLink *InfoRecv; ChainLink *InfoRecv;
int Ref; int Ref;
} capi_conn_t; };
/** Flags for conn */ /** Flags for conn */
enum { enum {
@@ -61,7 +62,7 @@ enum {
* Local data * Local data
*/ */
/** Data list for active dpi connections */ /** Data list for active dpi connections */
static Dlist *CapiConns; /* Data list for active connections; it holds static std::vector< capi_conn_t * > CapiConns; /* Data list for active connections; it holds
* pointers to capi_conn_t structures. */ * pointers to capi_conn_t structures. */
/** Last URL asked for view source */ /** Last URL asked for view source */
static DilloUrl *CapiVsUrl = NULL; static DilloUrl *CapiVsUrl = NULL;
@@ -80,8 +81,6 @@ void a_Capi_ccc(int Op, int Branch, int Dir, ChainLink *Info,
*/ */
void a_Capi_init(void) void a_Capi_init(void)
{ {
/* create an empty list */
CapiConns = dList_new(32);
/* init cache */ /* init cache */
a_Cache_init(); a_Cache_init();
} }
@@ -115,7 +114,8 @@ static capi_conn_t *
*/ */
static capi_conn_t *Capi_conn_valid(capi_conn_t *conn) static capi_conn_t *Capi_conn_valid(capi_conn_t *conn)
{ {
return reinterpret_cast< capi_conn_t * >( dList_find(CapiConns, conn) ); auto found= std::find( begin( CapiConns ), end( CapiConns ), conn );
return found == end( CapiConns ) ? nullptr : *found;
} }
/** /**
@@ -125,7 +125,7 @@ static void Capi_conn_ref(capi_conn_t *conn)
{ {
if (++conn->Ref == 1) { if (++conn->Ref == 1) {
/* add the connection data to list */ /* add the connection data to list */
dList_append(CapiConns, (void *)conn); CapiConns.push_back( conn );
} }
_MSG(" Capi_conn_ref #%d %p\n", conn->Ref, conn); _MSG(" Capi_conn_ref #%d %p\n", conn->Ref, conn);
} }
@@ -140,7 +140,7 @@ static void Capi_conn_unref(capi_conn_t *conn)
/* We may validate conn here, but it doesn't *seem* necessary */ /* We may validate conn here, but it doesn't *seem* necessary */
if (--conn->Ref == 0) { if (--conn->Ref == 0) {
/* remove conn preserving the list order */ /* remove conn preserving the list order */
dList_remove(CapiConns, (void *)conn); CapiConns.erase( std::find( begin( CapiConns ), end( CapiConns ), conn ) );
/* free dynamic memory */ /* free dynamic memory */
delete conn->url; delete conn->url;
dFree(conn->server); dFree(conn->server);
@@ -153,7 +153,7 @@ static void Capi_conn_unref(capi_conn_t *conn)
/** /**
* Compare function for searching a conn by server string * Compare function for searching a conn by server string
*/ */
static int Capi_conn_by_server_cmp(const void *v1, const void *v2) static int Capi_conn_by_server_cmp(const capi_conn_t *v1, const char *v2)
{ {
const capi_conn_t *node = reinterpret_cast< const capi_conn_t * >( v1 ); const capi_conn_t *node = reinterpret_cast< const capi_conn_t * >( v1 );
const char *server = reinterpret_cast< const char * >( v2 ); const char *server = reinterpret_cast< const char * >( v2 );
@@ -164,9 +164,10 @@ static int Capi_conn_by_server_cmp(const void *v1, const void *v2)
/** /**
* Find connection data by server * Find connection data by server
*/ */
static capi_conn_t *Capi_conn_find(char *server) static capi_conn_t *Capi_conn_find(const char *const server)
{ {
return reinterpret_cast< capi_conn_t * >( dList_find_custom(CapiConns, (void*)server, Capi_conn_by_server_cmp) ); const auto found= std::find_if( begin( CapiConns ), end( CapiConns ), [server]( const auto &node ) { return node->server == server; } );
return *found;
} }
/** /**
@@ -178,8 +179,8 @@ static void Capi_conn_resume(void)
DataBuf *dbuf; DataBuf *dbuf;
capi_conn_t *conn; capi_conn_t *conn;
for (i = 0; i < dList_length(CapiConns); ++i) { for (i = 0; i < CapiConns.size(); ++i) {
conn = reinterpret_cast< capi_conn_t * >( dList_nth_data (CapiConns, i) ); conn = CapiConns.at( i );
if (conn->Flags & PENDING) { if (conn->Flags & PENDING) {
dbuf = a_Chain_dbuf_new(conn->datastr,(int)strlen(conn->datastr), 0); dbuf = a_Chain_dbuf_new(conn->datastr,(int)strlen(conn->datastr), 0);
if (conn->InfoSend) { if (conn->InfoSend) {
@@ -202,8 +203,8 @@ void a_Capi_conn_abort_by_url(const DilloUrl *url)
int i; int i;
capi_conn_t *conn; capi_conn_t *conn;
for (i = 0; i < dList_length(CapiConns); ++i) { for (i = 0; i < CapiConns.size(); ++i) {
conn = reinterpret_cast< capi_conn_t * >( dList_nth_data (CapiConns, i) ); conn = CapiConns.at( i );
if (a_Url_cmp(conn->url, url) == 0) { if (a_Url_cmp(conn->url, url) == 0) {
if (conn->InfoSend) { if (conn->InfoSend) {
a_Capi_ccc(OpAbort, 1, BCK, conn->InfoSend, NULL, NULL); a_Capi_ccc(OpAbort, 1, BCK, conn->InfoSend, NULL, NULL);