Separating info out of the libsmbclient.h include file

Tom Jansen tom at ninja.nl
Mon Oct 21 19:05:01 GMT 2002


>> Richard Sharpe wrote:
>>
>>> A problem has arrisen with libsmbclient in head, in that there is too 
>>> much
>>> info exposed in libsmbclient.h.

Ok,

I've had a rainy day and decided to fix some problems with libsmbclient.
First of all, applications didn't compile because of libsmbclient.h 
troubles. These should all be fixed by the patches.

Second of all my patches address the problem that got me back to coding 
again: there was way to much internal info in libsmbclient.h. This is 
solved by moving all internal structs to libsmb_internal.h (should be 
placed in the include dir)

All the internal data that I could think of is hidden now.

This patch also fixes a problem with listing shares on _all_ servers. I 
introduced a really stupid bug in the context migration.

I also verified the "list shares by IP" problem. It does not exist with 
this version of libsmbclient.

Note on the attached files:

libsmb.diff: diffs for libsmb/libsmbclient.c libsmb/libsmb_compat.c 
libsmb/libsmb_cache.c

libsmbclient.h.diff: diff for include/libsmbclient.h

libsmb_internal.h: header file for all internal pieces of libsmbclient. 
Should be placed in include/


This is a request for comment with patches attached : )

Tom
-------------- next part --------------
Index: libsmb_cache.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/libsmb_cache.c,v
retrieving revision 1.4
diff -u -r1.4 libsmb_cache.c
--- libsmb_cache.c	28 Sep 2002 20:44:23 -0000	1.4
+++ libsmb_cache.c	21 Oct 2002 18:42:32 -0000
@@ -23,11 +23,7 @@
 
 #include "includes.h"
 
-/*
- * Define this to get the real SMBCFILE and SMBCSRV structures 
- */
-#define _SMBC_INTERNAL
-#include "../include/libsmbclient.h"
+#include "../include/libsmb_internal.h"
 
 /*
  * Structure we use if internal caching mechanism is used 
Index: libsmb_compat.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/libsmb_compat.c,v
retrieving revision 1.3
diff -u -r1.3 libsmb_compat.c
--- libsmb_compat.c	28 Sep 2002 20:44:23 -0000	1.3
+++ libsmb_compat.c	21 Oct 2002 18:42:33 -0000
@@ -24,11 +24,7 @@
 
 #include "includes.h"
 
-/*
- * Define this to get the real SMBCFILE and SMBCSRV structures 
- */
-#define _SMBC_INTERNAL
-#include "../include/libsmbclient.h"
+#include "../include/libsmb_internal.h"
 
 struct smbc_compat_fdlist {
 	SMBCFILE * file;
@@ -272,7 +268,7 @@
 	return (int) file;
 }
 
-int smbc_list_print_jobs(const char *purl, smbc_get_print_job_info fn)
+int smbc_list_print_jobs(const char *purl, smbc_list_print_job_fn fn)
 {
 	return statcont->list_print_jobs(statcont, purl, fn);
 }
Index: libsmbclient.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/libsmbclient.c,v
retrieving revision 1.60
diff -u -r1.60 libsmbclient.c
--- libsmbclient.c	28 Sep 2002 20:09:30 -0000	1.60
+++ libsmbclient.c	21 Oct 2002 18:42:33 -0000
@@ -23,7 +23,7 @@
 
 #include "includes.h"
 
-#include "../include/libsmbclient.h"
+#include "../include/libsmb_internal.h"
 
 /*
  * Functions exported by libsmb_cache.c that we need here
@@ -219,7 +219,7 @@
 }
 
 /* 
- * Remove a server from the list server_table if it's unused.
+ * Remove a server from the cached server list it's unused.
  * On success, 0 is returned. 1 is returned if the server could not be removed.
  * 
  * Also useable outside libsmbclient
@@ -229,11 +229,11 @@
 	SMBCFILE * file;
 
 	/* are we being fooled ? */
-	if (!context || !context->_initialized || !srv) return 1;
+	if (!context || !context->internal->_initialized || !srv) return 1;
 
 	
 	/* Check all open files/directories for a relation with this server */
-	for (file = context->_files; file; file=file->next) {
+	for (file = context->internal->_files; file; file=file->next) {
 		if (file->srv == srv) {
 			/* Still used */
 			DEBUG(3, ("smbc_remove_usused_server: %p still used by %p.\n", 
@@ -242,7 +242,7 @@
 		}
 	}
 
-	DLIST_REMOVE(context->_servers, srv);
+	DLIST_REMOVE(context->internal->_servers, srv);
 
 	cli_shutdown(&srv->cli);
 
@@ -475,7 +475,7 @@
 	SMBCFILE *file = NULL;
 	int fd;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
 		return NULL;
@@ -542,7 +542,7 @@
 		file->offset  = 0;
 		file->file    = True;
 
-		DLIST_ADD(context->_files, file);
+		DLIST_ADD(context->internal->_files, file);
 		return file;
 
 	}
@@ -573,7 +573,7 @@
 static SMBCFILE *smbc_creat_ctx(SMBCCTX *context, const char *path, mode_t mode)
 {
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return NULL;
@@ -591,7 +591,7 @@
 {
 	int ret;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -600,7 +600,7 @@
 
 	DEBUG(4, ("smbc_read(%p, %d)\n", file, (int)count));
 
-	if (!file || !DLIST_CONTAINS(context->_files, file)) {
+	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
 		errno = EBADF;
 		return -1;
@@ -641,14 +641,14 @@
 {
 	int ret;
 
-	if (!context || context->_initialized) {
+	if (!context || context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 
 	}
 
-	if (!file || !DLIST_CONTAINS(context->_files, file)) {
+	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
 		errno = EBADF;
 		return -1;
@@ -686,14 +686,14 @@
 {
         SMBCSRV *srv; 
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 
 	}
 
-	if (!file || !DLIST_CONTAINS(context->_files, file)) {
+	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
    
 		errno = EBADF;
 		return -1;
@@ -715,7 +715,7 @@
 		 * from the server cache if unused */
 		errno = smbc_errno(context, &file->srv->cli);  
 		srv = file->srv;
-		DLIST_REMOVE(context->_files, file);
+		DLIST_REMOVE(context->internal->_files, file);
 		SAFE_FREE(file->fname);
 		SAFE_FREE(file);
 		context->callbacks.remove_unused_server_fn(context, srv);
@@ -737,7 +737,7 @@
 		 * from the server cache if unused */
 		errno = smbc_errno(context, &file->srv->cli);  
 		srv = file->srv;
-		DLIST_REMOVE(context->_files, file);
+		DLIST_REMOVE(context->internal->_files, file);
 		SAFE_FREE(file->fname);
 		SAFE_FREE(file);
 		context->callbacks.remove_unused_server_fn(context, srv);
@@ -745,7 +745,7 @@
 		return -1;
 	}
 
-	DLIST_REMOVE(context->_files, file);
+	DLIST_REMOVE(context->internal->_files, file);
 	SAFE_FREE(file->fname);
 	SAFE_FREE(file);
 
@@ -762,7 +762,7 @@
 		 SMB_INO_T *ino)
 {
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
  
 		errno = EINVAL;
  		return -1;
@@ -798,7 +798,7 @@
 	pstring path;
 	SMBCSRV *srv = NULL;
 
-	if (!context || context->_initialized) {
+	if (!context || context->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
 		return -1;
@@ -893,7 +893,7 @@
 	SMBCSRV *srv = NULL;
 
 	if (!ocontext || !ncontext ||
-	    !ocontext->_initialized || !ncontext->_initialized) {
+	    !ocontext->internal->_initialized || !ncontext->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
 		return -1;
@@ -961,14 +961,14 @@
 {
 	size_t size;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 		
 	}
 
-	if (!file || !DLIST_CONTAINS(context->_files, file)) {
+	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
 		errno = EBADF;
 		return -1;
@@ -1021,7 +1021,7 @@
 ino_t smbc_inode(SMBCCTX *context, const char *name)
 {
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -1089,7 +1089,7 @@
 	uint16 mode = 0;
 	SMB_INO_T ino = 0;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;  /* Best I can think of ... */
 		return -1;
@@ -1172,14 +1172,14 @@
 	uint16 mode;
 	SMB_INO_T ino = 0;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 
 	}
 
-	if (!file || !DLIST_CONTAINS(context->_files, file)) {
+	if (!file || !DLIST_CONTAINS(context->internal->_files, file)) {
 
 		errno = EBADF;
 		return -1;
@@ -1272,9 +1272,6 @@
 
 	ZERO_STRUCTP(dirent);
 
-	ZERO_STRUCTP(dirent);
-
-
 	if (dir->dir_list == NULL) {
 
 		dir->dir_list = malloc(sizeof(struct smbc_dir_list));
@@ -1355,8 +1352,6 @@
 			dirent_type = SMBC_FILE_SHARE; /* FIXME, error? */
 			break;
 		}
-		ZERO_STRUCTP(dir->dir_list);
-
 	}
 	else dirent_type = dir->dir_type;
 
@@ -1391,9 +1386,8 @@
 	SMBCSRV *srv  = NULL;
 	SMBCFILE *dir = NULL;
 	struct in_addr rem_ip;
-	int slot = 0;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return NULL;
@@ -1489,7 +1483,6 @@
 			return NULL;
 
 		}
-		ZERO_STRUCTP(dir->dir_end);
 
 		dir->srv = srv;
 
@@ -1669,7 +1662,7 @@
 
 	}
 
-	DLIST_ADD(context->_files, dir);
+	DLIST_ADD(context->internal->_files, dir);
 	return dir;
 
 }
@@ -1681,14 +1674,14 @@
 static int smbc_closedir_ctx(SMBCCTX *context, SMBCFILE *dir)
 {
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 
 	}
 
-	if (!dir || !DLIST_CONTAINS(context->_files, dir)) {
+	if (!dir || !DLIST_CONTAINS(context->internal->_files, dir)) {
 
 		errno = EBADF;
 		return -1;
@@ -1697,7 +1690,7 @@
 
 	smbc_remove_dir(dir); /* Clean it up */
 
-	DLIST_REMOVE(context->_files, dir);
+	DLIST_REMOVE(context->internal->_files, dir);
 
 	if (dir) {
 
@@ -1720,14 +1713,14 @@
 
 	/* Check that all is ok first ... */
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return NULL;
 
 	}
 
-	if (!dir || !DLIST_CONTAINS(context->_files, dir)) {
+	if (!dir || !DLIST_CONTAINS(context->internal->_files, dir)) {
 
 		errno = EBADF;
 		return NULL;
@@ -1756,12 +1749,12 @@
 
 		/* Hmmm, do I even need to copy it? */
 
-		memcpy(context->_dirent, dirent, dirent->dirlen); /* Copy the dirent */
-		dirp = (struct smbc_dirent *)context->_dirent;
+		memcpy(context->internal->_dirent, dirent, dirent->dirlen); /* Copy the dirent */
+		dirp = (struct smbc_dirent *)context->internal->_dirent;
 		dirp->comment = (char *)(&dirp->name + dirent->namelen + 1);
 		dir->dir_next = dir->dir_next->next;
 
-		return (struct smbc_dirent *)context->_dirent;
+		return (struct smbc_dirent *)context->internal->_dirent;
 	}
 
 }
@@ -1778,14 +1771,14 @@
 
 	/* Check that all is ok first ... */
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 
 	}
 
-	if (!dir || !DLIST_CONTAINS(context->_files, dir)) {
+	if (!dir || !DLIST_CONTAINS(context->internal->_files, dir)) {
 
 		errno = EBADF;
 		return -1;
@@ -1864,7 +1857,7 @@
 	fstring server, share, user, password, workgroup;
 	pstring path;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -1950,7 +1943,7 @@
 	fstring server, share, user, password, workgroup;
 	pstring path;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -2047,14 +2040,14 @@
 static off_t smbc_telldir_ctx(SMBCCTX *context, SMBCFILE *dir)
 {
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
 
 	}
 
-	if (!dir || !DLIST_CONTAINS(context->_files, dir)) {
+	if (!dir || !DLIST_CONTAINS(context->internal->_files, dir)) {
 
 		errno = EBADF;
 		return -1;
@@ -2111,7 +2104,7 @@
 	struct smbc_dirent *dirent = (struct smbc_dirent *)offset;
 	struct smbc_dir_list *list_ent = NULL;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -2157,7 +2150,7 @@
 static int smbc_fstatdir_ctx(SMBCCTX *context, SMBCFILE *dir, struct stat *st)
 {
 
-	if (context || !context->_initialized) {
+	if (context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -2179,7 +2172,7 @@
 	fstring server, share, user, password;
 	pstring path;
 	
-	if (!context || context->_initialized) {
+	if (!context || context->internal->_initialized) {
 
 		errno = EINVAL;
 		return NULL;
@@ -2216,8 +2209,8 @@
 	int bytes, saverr, tot_bytes = 0;
 	char buf[4096];
 
-	if (!c_file || !c_file->_initialized || !c_print ||
-	    !c_print->_initialized) {
+	if (!c_file || !c_file->internal->_initialized || !c_print ||
+	    !c_print->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -2286,13 +2279,13 @@
  * Routine to list print jobs on a printer share ...
  */
 
-static int smbc_list_print_jobs_ctx(SMBCCTX *context, const char *fname, void (*fn)(struct print_job_info *))
+static int smbc_list_print_jobs_ctx(SMBCCTX *context, const char *fname, smbc_list_print_job_fn fn)
 {
 	SMBCSRV *srv;
 	fstring server, share, user, password, workgroup;
 	pstring path;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -2322,7 +2315,7 @@
 
 	}
 
-	if (cli_print_queue(&srv->cli, fn) < 0) {
+	if (cli_print_queue(&srv->cli, (void (*)(struct print_job_info *))fn) < 0) {
 
 		errno = smbc_errno(context, &srv->cli);
 		return -1;
@@ -2344,7 +2337,7 @@
 	pstring path;
 	int err;
 
-	if (!context || !context->_initialized) {
+	if (!context || !context->internal->_initialized) {
 
 		errno = EINVAL;
 		return -1;
@@ -2395,14 +2388,23 @@
 {
 	SMBCCTX * context;
 
-	context = malloc(sizeof(*context));
+	context = malloc(sizeof(SMBCCTX));
 	if (!context) {
 		errno = ENOMEM;
 		return NULL;
 	}
-	
+
 	ZERO_STRUCTP(context);
 
+	context->internal = malloc(sizeof(struct smbc_internal_data));
+	if (!context->internal) {
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	ZERO_STRUCTP(context->internal);
+
+	
 	/* ADD REASONABLE DEFAULTS */
 	context->debug            = 0;
 	context->timeout          = 20000; /* 20 seconds */
@@ -2457,25 +2459,25 @@
 		SMBCFILE * f;
 		DEBUG(1,("Performing aggressive shutdown.\n"));
 		
-		f = context->_files;
+		f = context->internal->_files;
 		while (f) {
 			context->close(context, f);
 			f = f->next;
 		}
-		context->_files = NULL;
+		context->internal->_files = NULL;
 
 		/* First try to remove the servers the nice way. */
 		if (context->callbacks.purge_cached_fn(context)) {
 			SMBCSRV * s;
 			DEBUG(1, ("Could not purge all servers, Nice way shutdown failed.\n"));
-			s = context->_servers;
+			s = context->internal->_servers;
 			while (s) {
 				cli_shutdown(&s->cli);
 				context->callbacks.remove_cached_srv_fn(context, s);
 				SAFE_FREE(s);
 				s = s->next;
 			}
-			context->_servers = NULL;
+			context->internal->_servers = NULL;
 		}
 	}
 	else {
@@ -2485,12 +2487,12 @@
 			errno = EBUSY;
 			return 1;
 		}
-		if (context->_servers) {
+		if (context->internal->_servers) {
 			DEBUG(1, ("Active servers in context, free_context failed.\n"));
 			errno = EBUSY;
 			return 1;
 		}
-		if (context->_files) {
+		if (context->internal->_files) {
 			DEBUG(1, ("Active files in context, free_context failed.\n"));
 			errno = EBUSY;
 			return 1;
@@ -2503,6 +2505,7 @@
 	SAFE_FREE(context->user);
 	
 	DEBUG(3, ("Context %p succesfully freed\n", context));
+	SAFE_FREE(context->internal);
 	SAFE_FREE(context);
 	return 0;
 }
@@ -2521,13 +2524,13 @@
 	int pid;
 	char *user = NULL, *home = NULL;
 
-	if (!context) {
+	if (!context || !context->internal) {
 		errno = EBADF;
 		return NULL;
 	}
 
 	/* Do not initialise the same client twice */
-	if (context->_initialized) { 
+	if (context->internal->_initialized) { 
 		return 0;
 	}
 
@@ -2634,7 +2637,7 @@
 	 * FIXME: Should we check the function pointers here? 
 	 */
 
-	context->_initialized = 1;
+	context->internal->_initialized = 1;
 	
 	return context;
 }
-------------- next part --------------
? libsmb_internal.h
Index: libsmbclient.h
===================================================================
RCS file: /cvsroot/samba/source/include/libsmbclient.h,v
retrieving revision 1.20
diff -u -r1.20 libsmbclient.h
--- libsmbclient.h	20 Aug 2002 12:38:43 -0000	1.20
+++ libsmbclient.h	21 Oct 2002 18:36:00 -0000
@@ -35,6 +35,10 @@
 *   \ingroup libsmbclient
 *   Data structures, types, and constants
 */
+/** \defgroup callback Callback function types
+*   \ingroup libsmbclient
+*   Callback functions
+*/
 /** \defgroup file File Functions
 *   \ingroup libsmbclient
 *   Functions used to access individual file contents
@@ -51,7 +55,7 @@
 *   \ingroup libsmbclient
 *   Functions used to access printing functionality
 */
-/** \defgroup attribute Miscellaneous Functions
+/** \defgroup misc Miscellaneous Functions
 *   \ingroup libsmbclient
 *   Functions that don't fit in to other categories
 */
@@ -62,7 +66,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#define SMBC_MAX_NAME       1023
 #define SMBC_WORKGROUP      1
 #define SMBC_SERVER         2
 #define SMBC_FILE_SHARE     3
@@ -73,12 +76,6 @@
 #define SMBC_FILE           8
 #define SMBC_LINK           9
 
-#define SMBC_FILE_MODE (S_IFREG | 0444)
-#define SMBC_DIR_MODE  (S_IFDIR | 0555)
-
-#define SMBC_MAX_FD         10000
-
-
 /**@ingroup structure
  * Structure that represents a directory entry.
  *
@@ -116,12 +113,12 @@
 	char name[1];
 };
 
-#ifndef _CLIENT_H
 
 /**@ingroup structure
  * Structure that represents a print job.
  *
  */
+#ifndef _CLIENT_H
 struct print_job_info 
 {
 	/** numeric ID of the print job
@@ -149,9 +146,29 @@
 	 */
 	time_t t;
 };
-#endif /* ifndef _CLIENT_H */
+#endif _CLIENT_H
+
+
+/**@ingroup structure
+ * Server handle 
+ */
+typedef struct _SMBCSRV  SMBCSRV;
 
 /**@ingroup structure
+ * File or directory handle 
+ */
+typedef struct _SMBCFILE SMBCFILE;
+
+/**@ingroup structure
+ * File or directory handle 
+ */
+typedef struct _SMBCCTX SMBCCTX;
+
+
+
+
+
+/**@ingroup callback
  * Authentication callback function type.
  * 
  * Type for the the authentication function called by the library to
@@ -187,51 +204,114 @@
                                       char *pw, int pwlen);
 
 
-/**@ingroup structure
+/**@ingroup callback
  * Print job info callback function type.
  *
  * @param i         pointer to print job information structure
  *
  */ 
-typedef void (*smbc_get_print_job_info)(struct print_job_info *i);
+typedef void (*smbc_list_print_job_fn)(struct print_job_info *i);
+		
 
-typedef struct _SMBCSRV {
-	struct cli_state cli;
-	dev_t dev;
-	BOOL no_pathinfo2;
-	int server_fd;
+/**@ingroup callback
+ * Check if a server is still good
+ *
+ * @param c         pointer to smb context
+ *
+ * @param srv       pointer to server to check
+ *
+ * @return          0 when connection is good. 1 on error.
+ *
+ */ 
+typedef int (*smbc_check_server_fn)(SMBCCTX * c, SMBCSRV *srv);
 
-	struct _SMBCSRV *next, *prev;
-	
-} SMBCSRV;
+/**@ingroup callback
+ * Remove a server if unused
+ *
+ * @param c         pointer to smb context
+ *
+ * @param srv       pointer to server to remove
+ *
+ * @return          0 on success. 1 on failure.
+ *
+ */ 
+typedef int (*smbc_remove_unused_server_fn)(SMBCCTX * c, SMBCSRV *srv);
+
+
+/**@ingroup callback
+ * Add a server to the cache system
+ *
+ * @param c         pointer to smb context
+ *
+ * @param srv       pointer to server to add
+ *
+ * @param server    server name 
+ *
+ * @param share     share name
+ *
+ * @param workgroup workgroup used to connect
+ *
+ * @param username  username used to connect
+ *
+ * @return          0 on success. 1 on failure.
+ *
+ */ 
+typedef int (*smbc_add_cached_srv_fn)   (SMBCCTX * c, SMBCSRV *srv, 
+				    char * server, char * share, 
+				    char * workgroup, char * username);
+
+
+/**@ingroup callback
+ * Look up a server in the cache system
+ *
+ * @param c         pointer to smb context
+ *
+ * @param server    server name to match
+ *
+ * @param share     share name to match
+ *
+ * @param workgroup workgroup to match
+ *
+ * @param username  username to match
+ *
+ * @return          pointer to SMBCSRV on success. NULL on failure.
+ *
+ */ 
+typedef SMBCSRV * (*smbc_get_cached_srv_fn)   (SMBCCTX * c, char * server, 
+					       char * share, char * workgroup, char * username);
+
+
+/**@ingroup callback
+ * Check if a server is still good
+ *
+ * @param c         pointer to smb context
+ *
+ * @param srv       pointer to server to remove
+ *
+ * @return          0 when found and removed. 1 on failure.
+ *
+ */ 
+typedef int (*smbc_remove_cached_srv_fn)(SMBCCTX * c, SMBCSRV *srv);
 
-/* 
- * Keep directory entries in a list 
- */
-struct smbc_dir_list {
-	struct smbc_dir_list *next;
-	struct smbc_dirent *dirent;
-};
 
-/*
- * Structure for open file management
+/**@ingroup callback
+ * Try to remove all servers from the cache system and disconnect
+ *
+ * @param c         pointer to smb context
+ *
+ * @return          0 when found and removed. 1 on failure.
+ *
  */ 
-typedef struct _SMBCFILE {
-	int cli_fd; 
-	char *fname;
-	off_t offset;
-	SMBCSRV *srv;
-	BOOL file;
-	struct smbc_dir_list *dir_list, *dir_end, *dir_next;
-	int dir_type, dir_error;
+typedef int (*smbc_purge_cached_fn)     (SMBCCTX * c);
+
+
 
-	struct _SMBCFILE *next, *prev;
-} SMBCFILE;
 
 /**@ingroup structure
  * Structure that contains a client context information 
+ * This structure is know as SMBCCTX
  */
-typedef struct _SMBCCTX {
+struct _SMBCCTX {
 	/** debug level 
 	 */
 	int     debug;
@@ -255,42 +335,42 @@
 	/** callable functions for files:
 	 * For usage and return values see the smbc_* functions
 	 */ 
-	SMBCFILE * (*open)    (struct _SMBCCTX *c, const char *fname, int flags, mode_t mode);
-	SMBCFILE * (*creat)   (struct _SMBCCTX *c, const char *path, mode_t mode);
-	ssize_t    (*read)    (struct _SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
-	ssize_t    (*write)   (struct _SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
-	int        (*unlink)  (struct _SMBCCTX *c, const char *fname);
-	int        (*rename)  (struct _SMBCCTX *ocontext, const char *oname, 
-			       struct _SMBCCTX *ncontext, const char *nname);
-	off_t      (*lseek)   (struct _SMBCCTX *c, SMBCFILE * file, off_t offset, int whence);
-	int        (*stat)    (struct _SMBCCTX *c, const char *fname, struct stat *st);
-	int        (*fstat)   (struct _SMBCCTX *c, SMBCFILE *file, struct stat *st);
-	int        (*close)   (struct _SMBCCTX *c, SMBCFILE *file);
+	SMBCFILE * (*open)    (SMBCCTX *c, const char *fname, int flags, mode_t mode);
+	SMBCFILE * (*creat)   (SMBCCTX *c, const char *path, mode_t mode);
+	ssize_t    (*read)    (SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
+	ssize_t    (*write)   (SMBCCTX *c, SMBCFILE *file, void *buf, size_t count);
+	int        (*unlink)  (SMBCCTX *c, const char *fname);
+	int        (*rename)  (SMBCCTX *ocontext, const char *oname, 
+			       SMBCCTX *ncontext, const char *nname);
+	off_t      (*lseek)   (SMBCCTX *c, SMBCFILE * file, off_t offset, int whence);
+	int        (*stat)    (SMBCCTX *c, const char *fname, struct stat *st);
+	int        (*fstat)   (SMBCCTX *c, SMBCFILE *file, struct stat *st);
+	int        (*close)   (SMBCCTX *c, SMBCFILE *file);
 
 	/** callable functions for dirs
 	 */ 
-	SMBCFILE * (*opendir) (struct _SMBCCTX *c, const char *fname);
-	int        (*closedir)(struct _SMBCCTX *c, SMBCFILE *dir);
-	struct smbc_dirent * (*readdir)(struct _SMBCCTX *c, SMBCFILE *dir);
-	int        (*getdents)(struct _SMBCCTX *c, SMBCFILE *dir, 
+	SMBCFILE * (*opendir) (SMBCCTX *c, const char *fname);
+	int        (*closedir)(SMBCCTX *c, SMBCFILE *dir);
+	struct smbc_dirent * (*readdir)(SMBCCTX *c, SMBCFILE *dir);
+	int        (*getdents)(SMBCCTX *c, SMBCFILE *dir, 
 			       struct smbc_dirent *dirp, int count);
-	int        (*mkdir)   (struct _SMBCCTX *c, const char *fname, mode_t mode);
-	int        (*rmdir)   (struct _SMBCCTX *c, const char *fname);
-	off_t      (*telldir) (struct _SMBCCTX *c, SMBCFILE *dir);
-	int        (*lseekdir)(struct _SMBCCTX *c, SMBCFILE *dir, off_t offset);
-	int        (*fstatdir)(struct _SMBCCTX *c, SMBCFILE *dir, struct stat *st);
+	int        (*mkdir)   (SMBCCTX *c, const char *fname, mode_t mode);
+	int        (*rmdir)   (SMBCCTX *c, const char *fname);
+	off_t      (*telldir) (SMBCCTX *c, SMBCFILE *dir);
+	int        (*lseekdir)(SMBCCTX *c, SMBCFILE *dir, off_t offset);
+	int        (*fstatdir)(SMBCCTX *c, SMBCFILE *dir, struct stat *st);
 
 	/** callable functions for printing
 	 */ 
-	int        (*print_file)(struct _SMBCCTX *c_file, const char *fname, 
-				 struct _SMBCCTX *c_print, const char *printq);
-	SMBCFILE * (*open_print_job)(struct _SMBCCTX *c, const char *fname);
-	int        (*list_print_jobs)(struct _SMBCCTX *c, const char *fname, void (*fn)(struct print_job_info *));
-	int        (*unlink_print_job)(struct _SMBCCTX *c, const char *fname, int id);
+	int        (*print_file)(SMBCCTX *c_file, const char *fname, 
+				 SMBCCTX *c_print, const char *printq);
+	SMBCFILE * (*open_print_job)(SMBCCTX *c, const char *fname);
+	int        (*list_print_jobs)(SMBCCTX *c, const char *fname, smbc_list_print_job_fn fn);
+	int        (*unlink_print_job)(SMBCCTX *c, const char *fname, int id);
 
 
 	/** Callbacks
-	 * These callbacks _always_ have to be intialized because they will not be checked
+	 * These callbacks _always_ have to be initialized because they will not be checked
 	 * at dereference for increased speed.
 	 */
 	struct _smbc_callbacks {
@@ -300,11 +380,11 @@
 		
 		/** check if a server is still good
 		 */
-		int (*check_server_fn)(struct _SMBCCTX * c, SMBCSRV *srv);
+		smbc_check_server_fn check_server_fn;
 
 		/** remove a server if unused
 		 */
-		int (*remove_unused_server_fn)(struct _SMBCCTX * c, SMBCSRV *srv);
+		smbc_remove_unused_server_fn remove_unused_server_fn;
 
 		/** Cache subsystem
 		 * For an example cache system see samba/source/libsmb/libsmb_cache.c
@@ -313,21 +393,19 @@
 
 		/** server cache addition 
 		 */
-		int (*add_cached_srv_fn)   (struct _SMBCCTX * c, SMBCSRV *srv, 
-					    char * server, char * share, 
-					    char * workgroup, char * username);
+		smbc_add_cached_srv_fn add_cached_srv_fn;
+
 		/** server cache lookup 
 		 */
-		SMBCSRV * (*get_cached_srv_fn)   (struct _SMBCCTX * c, char * server, 
-					    char * share, char * workgroup, char * username);
+		smbc_get_cached_srv_fn get_cached_srv_fn;
+
 		/** server cache removal
 		 */
-		int (*remove_cached_srv_fn)(struct _SMBCCTX * c, SMBCSRV *srv);
+		smbc_remove_cached_srv_fn remove_cached_srv_fn;
 		
 		/** server cache purging, try to remove all cached servers (disconnect)
 		 */
-		int (*purge_cached_fn)     (struct _SMBCCTX * c);
-		
+		smbc_purge_cached_fn purge_cached_fn;
 	} callbacks;
 
 
@@ -335,27 +413,12 @@
 	 */
 	struct smbc_server_cache * server_cache;
 
-	/** INTERNAL functions
-	 * do _NOT_ touch these from your program !
-	 */
-
-	/** INTERNAL: is this handle initialized ? 
-	 */
-	int     _initialized;
-
-	/** INTERNAL: dirent pointer location 
+	/** INTERNAL DATA
+	 * do _NOT_ touch this from your program !
 	 */
-	char    _dirent[512];  
-
-	/** INTERNAL: server connection list
-	 */
-	SMBCSRV * _servers;
+	struct smbc_internal_data * internal;
 	
-	/** INTERNAL: open file/dir list
-	 */
-	SMBCFILE * _files;
-	
-} SMBCCTX;
+};
 
 
 /**@ingroup misc
@@ -990,7 +1053,7 @@
  *                  - EINVAL fname was NULL or smbc_init not called
  *                  - EACCES ???
  */
-int smbc_list_print_jobs(const char *purl, smbc_get_print_job_info fn);
+int smbc_list_print_jobs(const char *purl, smbc_list_print_job_fn fn);
 
 /**@ingroup print
  * Delete a print job 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libsmb_internal.h
Type: text/x-chdr
Size: 1021 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20021021/14d017ed/libsmb_internal.bin


More information about the samba-technical mailing list