#include "common.h"
#include "hash.h"
#include "str.h"
+#include "str-table.h"
#include "strescape.h"
#include "ostream.h"
#include "connect-limit.h"
struct userip {
char *username;
- char *service;
+ const char *service;
struct ip_addr ip;
};
};
struct connect_limit {
+ struct str_table *strings;
+
/* userip => unsigned int refcount */
HASH_TABLE(struct userip *, void *) userip_hash;
/* (userip, pid) => struct session */
struct connect_limit *limit;
limit = i_new(struct connect_limit, 1);
+ limit->strings = str_table_init();
hash_table_create(&limit->userip_hash, default_pool, 0,
userip_hash, userip_cmp);
hash_table_create(&limit->session_hash, default_pool, 0,
*_limit = NULL;
hash_table_destroy(&limit->userip_hash);
hash_table_destroy(&limit->session_hash);
+ str_table_deinit(&limit->strings);
i_free(limit);
}
{
struct userip userip_lookup = {
.username = (char *)key->username,
- .service = (char *)key->service,
+ .service = key->service,
.ip = key->ip,
};
void *value;
struct userip userip_lookup = {
.username = (char *)key->username,
- .service = (char *)key->service,
+ .service = key->service,
.ip = key->ip,
};
if (!hash_table_lookup_full(limit->userip_hash, &userip_lookup,
&userip, &value)) {
userip = i_new(struct userip, 1);
userip->username = i_strdup(key->username);
- userip->service = i_strdup(key->service);
+ userip->service = str_table_ref(limit->strings, key->service);
userip->ip = key->ip;
value = POINTER_CAST(1);
hash_table_insert(limit->userip_hash, userip, value);
hash_table_update(limit->userip_hash, userip, value);
} else {
hash_table_remove(limit->userip_hash, userip);
+ str_table_unref(limit->strings, &userip->service);
i_free(userip->username);
- i_free(userip->service);
i_free(userip);
}
}
struct session *session;
struct userip userip_lookup = {
.username = (char *)key->username,
- .service = (char *)key->service,
+ .service = key->service,
.ip = key->ip,
};