-/* @(#) $Id$ */
+/* @(#) $Id: ./src/addagent/b64.c, 2011/09/08 dcid Exp $
+ */
/*
* Copyright (C), 2000-2004 by the monit project group.
* All Rights Reserved.
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
- * Implementation of base64 encoding/decoding.
+ * Implementation of base64 encoding/decoding.
*
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com>
*
out = (char *)calloc(sizeof(char), size*4/3+4);
if(!out)
return NULL;
-
+
p = out;
for(i = 0; i < size; i+=3) {
* 'dest'. The dest buffer is NUL terminated.
* Return NULL in case of error
*/
-char *decode_base64(const char *src)
+char *decode_base64(const char *src)
{
- if(src && *src)
+ if(src && *src)
{
char *dest;
unsigned char *p;
int k, l = strlen(src)+1;
unsigned char *buf;
-
+
/* The size of the dest will always be less than
* the source
*/
dest = (char *)calloc(sizeof(char), l + 13);
if(!dest)
return(NULL);
-
+
p = (unsigned char *)dest;
-
+
buf = malloc(l);
if(!buf)
return(NULL);
/* Ignore non base64 chars as per the POSIX standard */
- for(k=0, l=0; src[k]; k++)
+ for(k=0, l=0; src[k]; k++)
{
- if(is_base64(src[k]))
+ if(is_base64(src[k]))
{
buf[l++]= src[k];
}
- }
+ }
- for(k=0; k<l; k+=4)
+ for(k=0; k<l; k+=4)
{
char c1='A', c2='A', c3='A', c4='A';
unsigned char b1=0, b2=0, b3=0, b4=0;
c1= buf[k];
- if(k+1<l)
+ if(k+1<l)
{
c2= buf[k+1];
}
{
char *s;
char *d;
-
+
if(argc < 2)
{
printf("%s string\n",argv[0]);
d = decode_base64(s);
printf("decode:%s\n",d);
-
+
exit(0);
}