Re: [qmailadmin] Stupid C questions

2004-01-09 Thread Tom Collins
On Jan 8, 2004, at 6:56 PM, Rick Widmer wrote:
1.  Does switch/case work with strings?
No.  Only with byte/int/long/word datatypes.

It might be possible to build some sort of table of the commands and 
the functions to call:

typedef struct {
char*command,
void (*function)(),
} functableentry;
const functableentry functable[] = {
{ showusers, show_users },
{ showaliases, show_aliases }
}
notfound = 1;
for (i = 0; notfound  i  (sizeof(functable) / sizeof(functable[0])); 
i++) {
	if (strcmp (functable[i].command, command) == 0) {
		notfound = 0;
		functable[i].function();
	}
}
if (notfound) {
	printf (invalid command: %s\n, command);
}

Note that with this system, you need to come up with a standard 
function call (identical parameters and return value) to use for each 
function in the table.  Something like this could really clean up 
command.c.

2.  How much trouble is it to add or remove .c source files?  Say all 
the code in alias.c is obsolete except for a function or two and I 
want to move those functions to a different file and remove it.
Not much trouble at all.  We can just add or remove it from CVS and 
Makefile.am.

--
Tom Collins  -  [EMAIL PROTECTED]
QmailAdmin: http://qmailadmin.sf.net/  Vpopmail: http://vpopmail.sf.net/
Info on the Sniffter hand-held Network Tester: http://sniffter.com/


Re: [qmailadmin] Stupid C questions

2004-01-09 Thread Rick Widmer
Yesterday I worked on template.c removing unused tags and moving large
blocks of code to separate functions, some to different files.  There
are now 26 options with the form:
case '?' :
  single line of code;
  break;
4 like this, which I don't see any reason to mess with:

case '?' :
  if(MaxSomething  -1) {
 printf( number / number );
  } else {
 printf( number / unlimited );
  }
  break;
and 9 others that are still farily long chunks of code that are very
likely to become functions today.  I really like the way it looks with
all the single line actions in the switch.
I ran into some TmpBuf* variables which were declared in qmailadmin.c
and qmailadminx.h then used locally all over the program.  I was worried
about interaction, so I went through each function in which they
appeared, and if they were initialized within the function I renamed
them from TmpBuf* to Buffer*, and declared them locally.  It turns out
there were no interactions, now there is no question - they aren't
shared globals any more.
Tom Collins wrote:

 On Jan 8, 2004, at 6:56 PM, Rick Widmer wrote:

 1.  Does switch/case work with strings?

 No.  Only with byte/int/long/word datatypes.
If we want to move from

/cgi-bin/qmailadmin/com/commandname?...

to

/qmailadmin/program.cgi?command=commandname

why not just go with single character commands that we can switch() on?

/qmailadmin/program.cgi?command=c

However, if I was doing this with PHP, a URL might look like:

http://server.x.com/qmailadmin/maildomain.com/name/edit.php

qmailadmin is a PHP program without the .php extension.  I use the
following settings in httpd.com to make it execute:
Location /qmailadmin
ForceType applocation/x-httpd-php
/Location
/maildomain.com/username/edit.php would be available in PATH_INFO and
used to control operation of the program.  This example would be editing
[EMAIL PROTECTED]  The .php at the end is just there for show, I
never actually check the 'file extension'.
That works for PHP.  It looks like ScriptAlias will allow something
similar for a c program.  Are there any objections doing something like
this?  Is there anyone who would have a hard time controlling the Apache
configuration on the mail server?  Some web sites can not use the
ForceType trick because they can't change their Apache configuration,
but I'd be suprised if that was a problem on mail servers.  Now is the
time to find out if this will be a big problem for someone...
Rick








Re: [qmailadmin] Stupid C questions

2004-01-09 Thread Tom Collins
On Jan 9, 2004, at 4:33 PM, Rick Widmer wrote:
Yesterday I worked on template.c removing unused tags and moving large
blocks of code to separate functions, some to different files.  There
are now 26 options with the form:
case '?' :
  single line of code;
  break;
Note, that you could even do this:

	case '?': some_function_here(); break;

You might want to put the break on a separate line, so you can be sure 
to see it.  Missing breaks cause big problems.

I ran into some TmpBuf* variables which were declared in qmailadmin.c
and qmailadminx.h then used locally all over the program.  I was 
worried
about interaction, so I went through each function in which they
appeared, and if they were initialized within the function I renamed
them from TmpBuf* to Buffer*, and declared them locally.  It turns out
there were no interactions, now there is no question - they aren't
shared globals any more.
That's a good idea.  Both qmailadmin and vpopmail use shared globals 
and it's just not a good idea.  Upgrading some of the functions to pass 
values instead of relying on the global variables (like NewU) would be 
a good idea.

If we want to move from

/cgi-bin/qmailadmin/com/commandname?...

to

/qmailadmin/program.cgi?command=commandname

why not just go with single character commands that we can switch() on?

/qmailadmin/program.cgi?command=c
I'd prefer to stick with cmd=commandname for readability.

However, if I was doing this with PHP, a URL might look like:

http://server.x.com/qmailadmin/maildomain.com/name/edit.php

qmailadmin is a PHP program without the .php extension.  I use the
following settings in httpd.com to make it execute:
Location /qmailadmin
ForceType applocation/x-httpd-php
/Location
Not everyone uses Apache -- QmailAdmin works with other web servers.  
Keeping all parameters as values in the URL means that you can also 
move them to hidden fields in a POST.  There's flexibility in being 
able to pass values in the URL (GET style) and/or form data (POST 
style).  You could even store some values in a cookie (like the 
username and domain name) to make the URLs smaller.  If the user isn't 
accepting cookies, just include them in the URL (from template.c).

--
Tom Collins  -  [EMAIL PROTECTED]
QmailAdmin: http://qmailadmin.sf.net/  Vpopmail: http://vpopmail.sf.net/
Info on the Sniffter hand-held Network Tester: http://sniffter.com/


[qmailadmin] Stupid C questions

2004-01-08 Thread Rick Widmer
I know these are very basic language questions, but since I am working 
on QmailAdmin, please humor me...

1.  Does switch/case work with strings?

switch( command ) {
  case showusers :
show_users();
break;
  case showaliases :
show_aliases();
break;
  }

2.  How much trouble is it to add or remove .c source files?  Say all 
the code in alias.c is obsolete except for a function or two and I want 
to move those functions to a different file and remove it.

Right now I am searching for code that is never called and removing it.

Rick