lib/vpwentry/decode.cc
changeset 0 6f7a81934006
child 2 b3afb9f1e801
equal deleted inserted replaced
-1:000000000000 0:6f7a81934006
       
     1 // Copyright (C) 2000 Bruce Guenter <bruceg@em.ca>
       
     2 //
       
     3 // This program is free software; you can redistribute it and/or modify
       
     4 // it under the terms of the GNU General Public License as published by
       
     5 // the Free Software Foundation; either version 2 of the License, or
       
     6 // (at your option) any later version.
       
     7 //
       
     8 // This program is distributed in the hope that it will be useful,
       
     9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    11 // GNU General Public License for more details.
       
    12 //
       
    13 // You should have received a copy of the GNU General Public License
       
    14 // along with this program; if not, write to the Free Software
       
    15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    16 
       
    17 #include <config.h>
       
    18 #include <ctype.h>
       
    19 #include <string.h>
       
    20 #include "vpwentry.h"
       
    21 #include "vdomain/vdomain.h"
       
    22 #include "misc/strtou.h"
       
    23 
       
    24 static const char* from_uint(const char* ptr, unsigned& uint)
       
    25 {
       
    26   const char* tmp;
       
    27   uint = strtou(ptr, &tmp);
       
    28   return (*tmp == 0) ? ++tmp : 0;
       
    29 }
       
    30 
       
    31 const char* vpwentry::decode_flags(const char* ptr, const char* end)
       
    32 {
       
    33   while(ptr < end) {
       
    34     unsigned flag = *(unsigned char*)ptr++;
       
    35     if(!flag)
       
    36       return ptr;
       
    37     if(ptr >= end)
       
    38       return 0;
       
    39     bool value = *(unsigned char*)ptr++;
       
    40     switch(flag) {
       
    41     case vdomain::ATTR_MAILBOX_ENABLED:
       
    42       is_mailbox_enabled = value;
       
    43       break;
       
    44     default:
       
    45       return 0;
       
    46     }
       
    47   }
       
    48   return 0;
       
    49 }
       
    50 
       
    51 const char* vpwentry::decode_base(const char* ptr, const char* end)
       
    52 {
       
    53   pass = ptr;
       
    54   ptr += pass.length() + 1;
       
    55   if(ptr >= end) return 0;
       
    56   
       
    57   mailbox = ptr;
       
    58   ptr += mailbox.length() + 1;
       
    59   if(ptr >= end) return 0;
       
    60   
       
    61   const char* start = ptr;
       
    62   while(ptr < end && *ptr != 0)
       
    63     ptr += strlen(ptr) + 1;
       
    64   if(ptr == start)
       
    65     forwards = "";
       
    66   else
       
    67     forwards = mystring(start, ptr-start-1);
       
    68   if(ptr++ >= end) return 0;
       
    69   
       
    70   personal = ptr;
       
    71   ptr += personal.length() + 1;
       
    72   if(ptr >= end) return 0;
       
    73   
       
    74   return ptr;
       
    75 }
       
    76 
       
    77 const char* vpwentry::decode_values(const char* ptr, const char* end)
       
    78 {
       
    79   if((ptr = from_uint(ptr, hardquota)) == 0 || ptr >= end) return 0;
       
    80   if((ptr = from_uint(ptr, softquota)) == 0 || ptr >= end) return 0;
       
    81   if((ptr = from_uint(ptr, msgsize)) == 0 || ptr >= end) return 0;
       
    82   if((ptr = from_uint(ptr, msgcount)) == 0 || ptr >= end) return 0;
       
    83   if((ptr = from_uint(ptr, ctime)) == 0 || ptr >= end) return 0;
       
    84   if((ptr = from_uint(ptr, expiry)) == 0 || ptr > end) return 0;
       
    85   return ptr;
       
    86 }