Assert that we don't always have a valid session.
[citadel.git] / citadel / support.c
index bb27760cf43acd4bbe83997edf65a2ca1e6463ad..16e10e6f8e38f25ca4ba5583bdd83393f0ccc61d 100644 (file)
@@ -1,47 +1,44 @@
 /*
- * $Id$
- *
  * Server-side utility functions
- *
  */
 
 #include "sysdep.h"
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <libcitadel.h>
+
 #include "citadel.h"
-#include "server.h"
 #include "support.h"
 
-
 /*
  * strproc()  -  make a string 'nice'
  */
 void strproc(char *string)
 {
-       int a;
+       int a, b;
 
        if (string == NULL) return;
-       if (strlen(string)==0) return;
+       if (IsEmptyStr(string)) return;
 
        /* Convert non-printable characters to blanks */
-       for (a=0; a<strlen(string); ++a) {
+       for (a=0; !IsEmptyStr(&string[a]); ++a) {
                if (string[a]<32) string[a]=32;
                if (string[a]>126) string[a]=32;
        }
 
+       /* a is now the length of our string. */
        /* Remove leading and trailing blanks */
-       while( (string[0]<33) && (strlen(string)>0) )
-               strcpy(string,&string[1]);
-       while( (string[strlen(string)-1]<33) && (strlen(string)>0) )
-               string[strlen(string)-1]=0;
+       while( (string[a-1]<33) && (!IsEmptyStr(string)) )
+               string[--a]=0;
+       b = 0;
+       while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
+               b++;
+       if (b > 0)
+               memmove(string,&string[b], a - b + 1);
 
        /* Remove double blanks */
-       for (a=0; a<strlen(string); ++a) {
+       for (a=0; !IsEmptyStr(&string[a]); ++a) {
                if ((string[a]==32)&&(string[a+1]==32)) {
                        strcpy(&string[a],&string[a+1]);
                        a=0;
@@ -49,7 +46,7 @@ void strproc(char *string)
        }
 
        /* remove characters which would interfere with the network */
-       for (a=0; a<strlen(string); ++a) {
+       for (a=0; !IsEmptyStr(&string[a]); ++a) {
                while (string[a]=='!') strcpy(&string[a],&string[a+1]);
                while (string[a]=='@') strcpy(&string[a],&string[a+1]);
                while (string[a]=='_') strcpy(&string[a],&string[a+1]);
@@ -83,20 +80,9 @@ int getstring(FILE *fp, char *string)
                        string[a-1]=0;
                } while(string[0]=='#');
        return(strlen(string));
-       }
+}
 
 
-/*
- * pattern2()  -  searches for patn within search string, returns pos 
- */ 
-int pattern2(char *search, char *patn)
-{
-       int a;
-       for (a=0; a<strlen(search); ++a) {
-               if (!strncasecmp(&search[a],patn,strlen(patn))) return(a);
-               }
-       return(-1);
-       }
 
 
 /*
@@ -112,7 +98,7 @@ void mesg_locate(char *targ, size_t n, const char *searchfor,
        for (a=0; a<numdirs; ++a) {
                snprintf(buf, sizeof buf, "%s/%s", dirs[a], searchfor);
                if (!stat(buf, &test)) {
-                       snprintf(targ,n,"%s/%s", dirs[a], searchfor);
+                       snprintf(targ, n, "%s/%s", dirs[a], searchfor);
                        return;
                }
        }