* Define this to get the real SMBCFILE and SMBCSRV structures
*/
#define _SMBC_INTERNAL
-#include "libsmbclient.h"
+#include "include/libsmbclient.h"
/*
* Structure we use if internal caching mechanism is used
* This function is only used if the external cache is not enabled
*/
static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
- char * server, char * share,
- char * workgroup, char * username)
+ const char * server, const char * share,
+ const char * workgroup, const char * username)
{
struct smbc_server_cache * srvcache = NULL;
- if (!(srvcache = malloc(sizeof(*srvcache)))) {
+ if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) {
errno = ENOMEM;
DEBUG(3, ("Not enough space for server cache allocation\n"));
return 1;
srvcache->server = new;
- srvcache->server_name = strdup(server);
+ srvcache->server_name = SMB_STRDUP(server);
if (!srvcache->server_name) {
errno = ENOMEM;
goto failed;
}
- srvcache->share_name = strdup(share);
+ srvcache->share_name = SMB_STRDUP(share);
if (!srvcache->share_name) {
errno = ENOMEM;
goto failed;
}
- srvcache->workgroup = strdup(workgroup);
+ srvcache->workgroup = SMB_STRDUP(workgroup);
if (!srvcache->workgroup) {
errno = ENOMEM;
goto failed;
}
- srvcache->username = strdup(username);
+ srvcache->username = SMB_STRDUP(username);
if (!srvcache->username) {
errno = ENOMEM;
goto failed;
* returns server_fd on success, -1 on error (not found)
* This function is only used if the external cache is not enabled
*/
-static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, char * server,
- char * share, char * workgroup, char * user)
+static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, const char * server,
+ const char * share, const char * workgroup, const char * user)
{
struct smbc_server_cache * srv = NULL;
*/
static int smbc_purge_cached(SMBCCTX * context)
{
- struct smbc_server_cache * srv = NULL;
+ struct smbc_server_cache * srv;
+ struct smbc_server_cache * next;
int could_not_purge_all = 0;
- for (srv=((struct smbc_server_cache *) context->server_cache);srv;srv=srv->next) {
+ for (srv = ((struct smbc_server_cache *) context->server_cache),
+ next = (srv ? srv->next :NULL);
+ srv;
+ srv = next, next = (srv ? srv->next : NULL)) {
+
if (smbc_remove_unused_server(context, srv->server)) {
/* could not be removed */
could_not_purge_all = 1;