Rev 12127: Use service struct pointers rather than integers where
possible. in file:///home/jelmer/bzr.samba/SAMBA_4_0/
Jelmer Vernooij
jelmer at samba.org
Wed May 9 12:00:36 GMT 2007
At file:///home/jelmer/bzr.samba/SAMBA_4_0/
------------------------------------------------------------
revno: 12127
revision-id: jelmer at samba.org-20070509120026-tu719814our09bl5
parent: jelmer at samba.org-20070509112813-hfcw7ovikq4o69bj
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Wed 2007-05-09 14:00:26 +0200
message:
Use service struct pointers rather than integers where possible.
modified:
source/param/loadparm.c svn-v2:2 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-trunk-source%2fparam%2floadparm.c
=== modified file 'source/param/loadparm.c'
--- a/source/param/loadparm.c 2007-05-09 11:28:13 +0000
+++ b/source/param/loadparm.c 2007-05-09 12:00:26 +0000
@@ -1174,7 +1174,7 @@
service.
***************************************************************************/
-static int add_a_service(struct loadparm_context *ctx,
+static struct service *add_a_service(struct loadparm_context *ctx,
const struct service *pservice, const char *name)
{
int i;
@@ -1197,7 +1197,7 @@
data = pdata;
}
ctx->ServicePtrs[i]->param_opt = NULL;
- return i;
+ return ctx->ServicePtrs[i];
}
}
@@ -1215,7 +1215,7 @@
if (!tsp) {
DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
- return (-1);
+ return NULL;
}
else {
ctx->ServicePtrs = tsp;
@@ -1223,7 +1223,7 @@
}
if (!ctx->ServicePtrs[ctx->iNumServices]) {
DEBUG(0,("add_a_service: out of memory!\n"));
- return (-1);
+ return NULL;
}
ctx->iNumServices++;
@@ -1236,7 +1236,7 @@
copy_service(ctx->ServicePtrs[i], &tservice, NULL);
if (name)
string_set(ctx, &ctx->ServicePtrs[i]->szService, name);
- return i;
+ return ctx->ServicePtrs[i];
}
/***************************************************************************
@@ -1248,13 +1248,12 @@
const char *pszHomename, int iDefaultService,
const char *user, const char *pszHomedir)
{
- int i;
pstring newHomedir;
- i = add_a_service(ctx, ctx->ServicePtrs[iDefaultService], pszHomename);
+ struct service *svc = add_a_service(ctx, ctx->ServicePtrs[iDefaultService], pszHomename);
- if (i < 0)
- return (False);
+ if (svc == NULL)
+ return false;
if (!(*(ctx->ServicePtrs[iDefaultService]->szPath))
|| strequal(ctx->ServicePtrs[iDefaultService]->szPath, lp_pathname(-1))) {
@@ -1264,16 +1263,16 @@
string_sub(newHomedir,"%H", pszHomedir, sizeof(newHomedir));
}
- string_set(ctx, &ctx->ServicePtrs[i]->szPath, newHomedir);
+ string_set(svc, &svc->szPath, newHomedir);
- if (!(*(ctx->ServicePtrs[i]->comment))) {
+ if (!(*(svc->comment))) {
pstring comment;
slprintf(comment, sizeof(comment) - 1,
"Home directory of %s", user);
- string_set(ctx, &ctx->ServicePtrs[i]->comment, comment);
+ string_set(ctx, &svc->comment, comment);
}
- ctx->ServicePtrs[i]->bAvailable = sDefault.bAvailable;
- ctx->ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
+ svc->bAvailable = sDefault.bAvailable;
+ svc->bBrowseable = sDefault.bBrowseable;
DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename,
user, newHomedir));
@@ -1285,7 +1284,7 @@
Add a new service, based on an old one.
***************************************************************************/
-int lp_add_service(struct loadparm_context *ctx,
+struct service *lp_add_service(struct loadparm_context *ctx,
const char *pszService, int iDefaultService)
{
return (add_a_service(ctx, ctx->ServicePtrs[iDefaultService], pszService));
@@ -1299,25 +1298,25 @@
const char *name, const char *fstype)
{
pstring comment;
- int i = add_a_service(ctx, &sDefault, name);
+ struct service *svc = add_a_service(ctx, &sDefault, name);
- if (i < 0)
- return (False);
+ if (svc == NULL)
+ return false;
slprintf(comment, sizeof(comment) - 1,
"%s Service (%s)", fstype, Globals.szServerString);
- string_set(ctx, &ctx->ServicePtrs[i]->szPath, tmpdir());
- string_set(ctx, &ctx->ServicePtrs[i]->comment, comment);
- string_set(ctx, &ctx->ServicePtrs[i]->fstype, fstype);
- ctx->ServicePtrs[i]->iMaxConnections = -1;
- ctx->ServicePtrs[i]->bAvailable = true;
- ctx->ServicePtrs[i]->bRead_only = true;
- ctx->ServicePtrs[i]->bPrint_ok = false;
- ctx->ServicePtrs[i]->bBrowseable = false;
+ string_set(ctx, &svc->szPath, tmpdir());
+ string_set(ctx, &svc->comment, comment);
+ string_set(ctx, &svc->fstype, fstype);
+ svc->iMaxConnections = -1;
+ svc->bAvailable = true;
+ svc->bRead_only = true;
+ svc->bPrint_ok = false;
+ svc->bBrowseable = false;
if (strcasecmp(fstype, "IPC") == 0) {
- lp_do_parameter(ctx, i, "ntvfs handler", "default");
+ string_set(ctx, &svc->ntvfs_handler, "default");
}
DEBUG(3, ("adding hidden service %s\n", name));
@@ -1333,9 +1332,9 @@
const char *pszPrintername, int iDefaultService)
{
const char *comment = "From Printcap";
- int i = add_a_service(ctx, ctx->ServicePtrs[iDefaultService], pszPrintername);
+ struct service *svc = add_a_service(ctx, ctx->ServicePtrs[iDefaultService], pszPrintername);
- if (i < 0)
+ if (svc == NULL)
return false;
/* note that we do NOT default the availability flag to true - */
@@ -1344,13 +1343,13 @@
/* entry (if/when the 'available' keyword is implemented!). */
/* the printer name is set to the service name. */
- string_set(ctx, &ctx->ServicePtrs[i]->szPrintername, pszPrintername);
- string_set(ctx, &ctx->ServicePtrs[i]->comment, comment);
- ctx->ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
+ string_set(ctx, &svc->szPrintername, pszPrintername);
+ string_set(ctx, &svc->comment, comment);
+ svc->bBrowseable = sDefault.bBrowseable;
/* Printers cannot be read_only. */
- ctx->ServicePtrs[i]->bRead_only = false;
+ svc->bRead_only = false;
/* Printer services must be printable. */
- ctx->ServicePtrs[i]->bPrint_ok = true;
+ svc->bPrint_ok = true;
DEBUG(3, ("adding printer service %s\n", pszPrintername));
@@ -2145,8 +2144,7 @@
/* issued by the post-processing of a previous section. */
DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
- if ((iServiceIndex = add_a_service(ctx, &sDefault, pszSectionName))
- < 0) {
+ if (add_a_service(ctx, &sDefault, pszSectionName) == NULL) {
DEBUG(0, ("Failed to add a new service\n"));
return false;
}
More information about the samba-cvs
mailing list