⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decode.c

📁 C语言实现的一个简易的SMPT服务器代码
💻 C
字号:
/* *  Embedded SMTP Server Base64 Decoder * *  ./software/ch5/emsmtpd/decode.c * *  mtj@cogitollc.com * *  Copyright 2001,2002 M. Tim Jones <mtj@cogitollc.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * 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. * */#include <stdio.h>#include <fcntl.h>#include "server.h"/* *  b64decode() * *  Performs Base64 content decoding.  'src' pointer contains the *  input data reference, and 'dest' pointer where the decoded *  attachment should be stored. * *  Returns -1 on error or the number of octets decoded into 'dest'. * */int b64decode(char *src, char *dest){  unsigned char c;  int state = 0, attachlen = 0;  while (1) {    c = *src++;    if (isupper(c)) c = c - 'A';    else if (isdigit(c)) c -= '0' - 52;    else if (islower(c)) c -= 'a' - 26;    else if (c == '/') c = 63;    else if (c == '+') c = 62;    else if (c == '=') {      switch(state++) {        case 3:          if (*src == 0x0d) goto fini;          state = 0;          break;        case 2:          if ((*src == '=') || (*src == 0x0d) ||              (*src == 0x0a)) goto fini;        default:          return(-1);      }      continue;    } else continue;    switch(state++) {        case 0:          dest[attachlen] = c << 2;          break;        case 1:          dest[attachlen++] |= c >> 4;          dest[attachlen] = c << 4;          break;        case 2:          dest[attachlen++] |= c >> 2;          dest[attachlen] = c << 6;          break;        case 3:          dest[attachlen++] |= c;          state = 0;          break;    }    if (attachlen >= MAX_ATTACHMENT) return -1;  }fini:  return(attachlen);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -