<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17564">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_voicemail: Refactor email generation functions<br><br>Refactors generic functions used for email generation<br>into utils.c so that they can be used by multiple<br>modules, including app_voicemail and app_minivm,<br>to avoid code duplication.<br><br>ASTERISK-29715 #close<br><br>Change-Id: I1de0ed3483623e9599711129edc817c45ad237ee<br>---<br>M apps/app_minivm.c<br>M apps/app_voicemail.c<br>M include/asterisk/file.h<br>M include/asterisk/utils.h<br>M main/file.c<br>M main/utils.c<br>6 files changed, 193 insertions(+), 300 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/64/17564/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_minivm.c b/apps/app_minivm.c</span><br><span>index 8f1064e..69370ef 100644</span><br><span>--- a/apps/app_minivm.c</span><br><span>+++ b/apps/app_minivm.c</span><br><span>@@ -161,7 +161,6 @@</span><br><span> #include <dirent.h></span><br><span> #include <locale.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #include "asterisk/paths.h" /* use various paths */</span><br><span> #include "asterisk/lock.h"</span><br><span> #include "asterisk/file.h"</span><br><span>@@ -542,8 +541,6 @@</span><br><span> #define SENDMAIL "/usr/sbin/sendmail -t"</span><br><span> </span><br><span> #define SOUND_INTRO "vm-intro"</span><br><span style="color: hsl(0, 100%, 40%);">-#define B64_BASEMAXINLINE 256 /*!< Buffer size for Base 64 attachment encoding */</span><br><span style="color: hsl(0, 100%, 40%);">-#define B64_BASELINELEN 72 /*!< Line length for Base 64 encoded messages */</span><br><span> #define EOL "\r\n"</span><br><span> </span><br><span> #define MAX_DATETIME_FORMAT 512</span><br><span>@@ -659,15 +656,6 @@</span><br><span> signed char record_gain;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief Structure for base64 encoding */</span><br><span style="color: hsl(0, 100%, 40%);">-struct b64_baseio {</span><br><span style="color: hsl(0, 100%, 40%);">- int iocp;</span><br><span style="color: hsl(0, 100%, 40%);">- int iolen;</span><br><span style="color: hsl(0, 100%, 40%);">- int linelength;</span><br><span style="color: hsl(0, 100%, 40%);">- int ateof;</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned char iobuf[B64_BASEMAXINLINE];</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*! \brief Voicemail time zones */</span><br><span> struct minivm_zone {</span><br><span> char name[80]; /*!< Name of this time zone */</span><br><span>@@ -853,134 +841,6 @@</span><br><span> AST_LIST_UNLOCK(&message_templates);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*!\internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief read buffer from file (base64 conversion) */</span><br><span style="color: hsl(0, 100%, 40%);">-static int b64_inbuf(struct b64_baseio *bio, FILE *fi)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- int l;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (bio->ateof)</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE, fi)) != B64_BASEMAXINLINE) {</span><br><span style="color: hsl(0, 100%, 40%);">- bio->ateof = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- if (l == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Assume EOF */</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- bio->iolen = l;</span><br><span style="color: hsl(0, 100%, 40%);">- bio->iocp = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!\internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief read character from file to buffer (base64 conversion) */</span><br><span style="color: hsl(0, 100%, 40%);">-static int b64_inchar(struct b64_baseio *bio, FILE *fi)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- if (bio->iocp >= bio->iolen) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!b64_inbuf(bio, fi))</span><br><span style="color: hsl(0, 100%, 40%);">- return EOF;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return bio->iobuf[bio->iocp++];</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!\internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief write buffer to file (base64 conversion) */</span><br><span style="color: hsl(0, 100%, 40%);">-static int b64_ochar(struct b64_baseio *bio, int c, FILE *so)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- if (bio->linelength >= B64_BASELINELEN) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (fputs(EOL,so) == EOF)</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- bio->linelength= 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (putc(((unsigned char) c), so) == EOF)</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- bio->linelength++;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!\internal</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Encode file to base64 encoding for email attachment (base64 conversion) */</span><br><span style="color: hsl(0, 100%, 40%);">-static int base_encode(char *filename, FILE *so)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned char dtable[B64_BASEMAXINLINE];</span><br><span style="color: hsl(0, 100%, 40%);">- int i,hiteof= 0;</span><br><span style="color: hsl(0, 100%, 40%);">- FILE *fi;</span><br><span style="color: hsl(0, 100%, 40%);">- struct b64_baseio bio;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- memset(&bio, 0, sizeof(bio));</span><br><span style="color: hsl(0, 100%, 40%);">- bio.iocp = B64_BASEMAXINLINE;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(fi = fopen(filename, "rb"))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Failed to open file: %s: %s\n", filename, strerror(errno));</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (i= 0; i<9; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[i]= 'A'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[i+9]= 'J'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[26+i]= 'a'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[26+i+9]= 'j'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- for (i= 0; i < 8; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[i+18]= 'S'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[26+i+18]= 's'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- for (i= 0; i < 10; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[52+i]= '0'+i;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[62]= '+';</span><br><span style="color: hsl(0, 100%, 40%);">- dtable[63]= '/';</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- while (!hiteof){</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned char igroup[3], ogroup[4];</span><br><span style="color: hsl(0, 100%, 40%);">- int c,n;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- igroup[0]= igroup[1]= igroup[2]= 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (n= 0; n < 3; n++) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((c = b64_inchar(&bio, fi)) == EOF) {</span><br><span style="color: hsl(0, 100%, 40%);">- hiteof= 1;</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- igroup[n]= (unsigned char)c;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (n> 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[0]= dtable[igroup[0]>>2];</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[1]= dtable[((igroup[0]&3)<<4) | (igroup[1]>>4)];</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[2]= dtable[((igroup[1]&0xF)<<2) | (igroup[2]>>6)];</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[3]= dtable[igroup[2]&0x3F];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (n<3) {</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[3]= '=';</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (n<2)</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[2]= '=';</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (i= 0;i<4;i++)</span><br><span style="color: hsl(0, 100%, 40%);">- b64_ochar(&bio, ogroup[i], so);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Put end of line - line feed */</span><br><span style="color: hsl(0, 100%, 40%);">- if (fputs(EOL, so) == EOF)</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- fclose(fi);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static int get_date(char *s, int len)</span><br><span> {</span><br><span> struct ast_tm tm;</span><br><span>@@ -1481,7 +1341,7 @@</span><br><span> fprintf(p, "Content-Description: Voicemail sound attachment.\n");</span><br><span> fprintf(p, "Content-Disposition: attachment; filename=\"voicemail%s.%s\"\n\n", counter ? counter : "", format);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- base_encode(fname, p);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_base64_encode_file_path(fname, p, EOL);</span><br><span> fprintf(p, "\n\n--%s--\n.\n", bound);</span><br><span> }</span><br><span> fclose(p);</span><br><span>diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c</span><br><span>index ee7752d..6f909d4 100644</span><br><span>--- a/apps/app_voicemail.c</span><br><span>+++ b/apps/app_voicemail.c</span><br><span>@@ -529,7 +529,6 @@</span><br><span> /* Default mail command to mail voicemail. Change it with the</span><br><span> * mailcmd= command in voicemail.conf */</span><br><span> #define SENDMAIL "/usr/sbin/sendmail -t"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #define INTRO "vm-intro"</span><br><span> </span><br><span> #define MAX_MAIL_BODY_CONTENT_SIZE 134217728L // 128 Mbyte</span><br><span>@@ -539,8 +538,6 @@</span><br><span> </span><br><span> #define MINPASSWORD 0 /*!< Default minimum mailbox password length */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define BASELINELEN 72</span><br><span style="color: hsl(0, 100%, 40%);">-#define BASEMAXINLINE 256</span><br><span> #ifdef IMAP_STORAGE</span><br><span> #define ENDL "\r\n"</span><br><span> #else</span><br><span>@@ -744,14 +741,6 @@</span><br><span> </span><br><span> */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-struct baseio {</span><br><span style="color: hsl(0, 100%, 40%);">- int iocp;</span><br><span style="color: hsl(0, 100%, 40%);">- int iolen;</span><br><span style="color: hsl(0, 100%, 40%);">- int linelength;</span><br><span style="color: hsl(0, 100%, 40%);">- int ateof;</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned char iobuf[BASEMAXINLINE];</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #define MAX_VM_MBOX_ID_LEN (AST_MAX_EXTENSION)</span><br><span> #define MAX_VM_CONTEXT_LEN (AST_MAX_CONTEXT)</span><br><span> /* MAX_VM_MAILBOX_LEN allows enough room for the '@' and NULL terminator */</span><br><span>@@ -1928,22 +1917,6 @@</span><br><span> return snprintf(dest, len, "%s/msg%04d", dir, num);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* same as mkstemp, but return a FILE * */</span><br><span style="color: hsl(0, 100%, 40%);">-static FILE *vm_mkftemp(char *template)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- FILE *p = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- int pfd = mkstemp(template);</span><br><span style="color: hsl(0, 100%, 40%);">- chmod(template, VOICEMAIL_FILE_MODE & ~my_umask);</span><br><span style="color: hsl(0, 100%, 40%);">- if (pfd > -1) {</span><br><span style="color: hsl(0, 100%, 40%);">- p = fdopen(pfd, "w+");</span><br><span style="color: hsl(0, 100%, 40%);">- if (!p) {</span><br><span style="color: hsl(0, 100%, 40%);">- close(pfd);</span><br><span style="color: hsl(0, 100%, 40%);">- pfd = -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return p;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*! \brief basically mkdir -p $dest/$context/$ext/$folder</span><br><span> * \param dest String. base directory.</span><br><span> * \param len Length of dest.</span><br><span>@@ -2697,7 +2670,7 @@</span><br><span> </span><br><span> /* Make a temporary file instead of piping directly to sendmail, in case the mail</span><br><span> command hangs. */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(p = vm_mkftemp(tmp))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(p = ast_file_mkftemp(tmp, VOICEMAIL_FILE_MODE & ~my_umask))) {</span><br><span> ast_log(AST_LOG_WARNING, "Unable to store '%s' (can't create temporary file)\n", fn);</span><br><span> if (tempcopy) {</span><br><span> ast_free(vmu->email);</span><br><span>@@ -4771,134 +4744,6 @@</span><br><span> return ast_filedelete(file, NULL);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief utility used by inchar(), for base_encode()</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int inbuf(struct baseio *bio, FILE *fi)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- int l;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (bio->ateof)</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if ((l = fread(bio->iobuf, 1, BASEMAXINLINE, fi)) != BASEMAXINLINE) {</span><br><span style="color: hsl(0, 100%, 40%);">- bio->ateof = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- if (l == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Assume EOF */</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- bio->iolen = l;</span><br><span style="color: hsl(0, 100%, 40%);">- bio->iocp = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief utility used by base_encode()</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int inchar(struct baseio *bio, FILE *fi)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- if (bio->iocp>=bio->iolen) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!inbuf(bio, fi))</span><br><span style="color: hsl(0, 100%, 40%);">- return EOF;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return bio->iobuf[bio->iocp++];</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief utility used by base_encode()</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int ochar(struct baseio *bio, int c, FILE *so)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- if (bio->linelength >= BASELINELEN) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (fputs(ENDL, so) == EOF) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- bio->linelength = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (putc(((unsigned char) c), so) == EOF) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- bio->linelength++;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Performs a base 64 encode algorithm on the contents of a File</span><br><span style="color: hsl(0, 100%, 40%);">- * \param filename The path to the file to be encoded. Must be readable, file is opened in read mode.</span><br><span style="color: hsl(0, 100%, 40%);">- * \param so A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * TODO: shouldn't this (and the above 3 support functions) be put into some kind of external utility location, such as funcs/func_base64.c ?</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * \return zero on success, -1 on error.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int base_encode(char *filename, FILE *so)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- static const unsigned char dtable[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',</span><br><span style="color: hsl(0, 100%, 40%);">- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',</span><br><span style="color: hsl(0, 100%, 40%);">- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',</span><br><span style="color: hsl(0, 100%, 40%);">- '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};</span><br><span style="color: hsl(0, 100%, 40%);">- int i, hiteof = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- FILE *fi;</span><br><span style="color: hsl(0, 100%, 40%);">- struct baseio bio;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- memset(&bio, 0, sizeof(bio));</span><br><span style="color: hsl(0, 100%, 40%);">- bio.iocp = BASEMAXINLINE;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(fi = fopen(filename, "rb"))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s\n", filename, strerror(errno));</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- while (!hiteof){</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned char igroup[3], ogroup[4];</span><br><span style="color: hsl(0, 100%, 40%);">- int c, n;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- memset(igroup, 0, sizeof(igroup));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (n = 0; n < 3; n++) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((c = inchar(&bio, fi)) == EOF) {</span><br><span style="color: hsl(0, 100%, 40%);">- hiteof = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- igroup[n] = (unsigned char) c;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (n > 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[0]= dtable[igroup[0] >> 2];</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[1]= dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[2]= dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[3]= dtable[igroup[2] & 0x3F];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (n < 3) {</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[3] = '=';</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (n < 2)</span><br><span style="color: hsl(0, 100%, 40%);">- ogroup[2] = '=';</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < 4; i++)</span><br><span style="color: hsl(0, 100%, 40%);">- ochar(&bio, ogroup[i], so);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- fclose(fi);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (fputs(ENDL, so) == EOF) {</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, const char *fromfolder, char *cidnum, char *cidname, char *dur, char *date, const char *category, const char *flag)</span><br><span> {</span><br><span> char callerid[256];</span><br><span>@@ -5509,7 +5354,7 @@</span><br><span> fprintf(p, "Content-Disposition: attachment; filename=\"%s\"" ENDL ENDL, filename);</span><br><span> else</span><br><span> fprintf(p, "Content-Disposition: attachment; filename=\"%s.%s\"" ENDL ENDL, greeting_attachment, format);</span><br><span style="color: hsl(0, 100%, 40%);">- base_encode(fname, p);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_base64_encode_file_path(fname, p, ENDL);</span><br><span> if (last)</span><br><span> fprintf(p, ENDL ENDL "--%s--" ENDL "." ENDL, bound);</span><br><span> </span><br><span>@@ -5562,7 +5407,7 @@</span><br><span> ast_debug(3, "Attaching file '%s', format '%s', uservm is '%d', global is %u\n", attach, format, attach_user_voicemail, ast_test_flag((&globalflags), VM_ATTACH));</span><br><span> /* Make a temporary file instead of piping directly to sendmail, in case the mail</span><br><span> command hangs */</span><br><span style="color: hsl(0, 100%, 40%);">- if ((p = vm_mkftemp(tmp)) == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((p = ast_file_mkftemp(tmp, VOICEMAIL_FILE_MODE & ~my_umask)) == NULL) {</span><br><span> ast_log(AST_LOG_WARNING, "Unable to launch '%s' (can't create temporary file)\n", mailcmd);</span><br><span> return -1;</span><br><span> } else {</span><br><span>@@ -5601,7 +5446,7 @@</span><br><span> strip_control_and_high(cidname, enc_cidname, sizeof(enc_cidname));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if ((p = vm_mkftemp(tmp)) == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((p = ast_file_mkftemp(tmp, VOICEMAIL_FILE_MODE & ~my_umask)) == NULL) {</span><br><span> ast_log(AST_LOG_WARNING, "Unable to launch '%s' (can't create temporary file)\n", mailcmd);</span><br><span> ast_free(str1);</span><br><span> ast_free(str2);</span><br><span>diff --git a/include/asterisk/file.h b/include/asterisk/file.h</span><br><span>index 7e54426..04fc5bb 100644</span><br><span>--- a/include/asterisk/file.h</span><br><span>+++ b/include/asterisk/file.h</span><br><span>@@ -138,6 +138,15 @@</span><br><span> int ast_filecopy(const char *oldname, const char *newname, const char *fmt);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief same as mkstemp, but return a FILE</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param template The template for the unique file name to generate. Modified in place to return the file name.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param mode The mode for file permissions</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return FILE handle to the temporary file on success or NULL if creation failed</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+FILE *ast_file_mkftemp(char *template, mode_t mode);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Callback called for each file found when reading directories</span><br><span> * \param dir_name the name of the directory</span><br><span> * \param filename the name of the file</span><br><span>diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h</span><br><span>index 08120bf..024b6c7 100644</span><br><span>--- a/include/asterisk/utils.h</span><br><span>+++ b/include/asterisk/utils.h</span><br><span>@@ -336,6 +336,26 @@</span><br><span> */</span><br><span> char *ast_base64url_encode_string(const char *src);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Performs a base 64 encode algorithm on the contents of a File</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param inputfile A FILE handle to the input file to be encoded. Must be readable. This handle is not automatically closed.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param outputfile A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param endl The line ending to use (e.g. either "\n" or "\r\n")</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return zero on success, -1 on error.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_base64_encode_file(FILE *inputfile, FILE *outputfile, const char *endl);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Performs a base 64 encode algorithm on the contents of a File</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param filename The path to the file to be encoded. Must be readable, file is opened in read mode.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param outputfile A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param endl The line ending to use (e.g. either "\n" or "\r\n")</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return zero on success, -1 on error.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_base64_encode_file_path(const char *filename, FILE *outputfile, const char *endl);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define AST_URI_ALPHANUM (1 << 0)</span><br><span> #define AST_URI_MARK (1 << 1)</span><br><span> #define AST_URI_UNRESERVED (AST_URI_ALPHANUM | AST_URI_MARK)</span><br><span>diff --git a/main/file.c b/main/file.c</span><br><span>index a16b6dd..89fcd14 100644</span><br><span>--- a/main/file.c</span><br><span>+++ b/main/file.c</span><br><span>@@ -184,6 +184,21 @@</span><br><span> return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+FILE *ast_file_mkftemp(char *template, mode_t mode)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ FILE *p = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ int pfd = mkstemp(template);</span><br><span style="color: hsl(120, 100%, 40%);">+ chmod(template, mode);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pfd > -1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ p = fdopen(pfd, "w+");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!p) {</span><br><span style="color: hsl(120, 100%, 40%);">+ close(pfd);</span><br><span style="color: hsl(120, 100%, 40%);">+ pfd = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return p;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_stopstream(struct ast_channel *tmp)</span><br><span> {</span><br><span> ast_channel_lock(tmp);</span><br><span>diff --git a/main/utils.c b/main/utils.c</span><br><span>index f4a026d..dc94c99 100644</span><br><span>--- a/main/utils.c</span><br><span>+++ b/main/utils.c</span><br><span>@@ -570,6 +570,150 @@</span><br><span> b2a_url[(int)'_'] = 63;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define BASELINELEN 72 /*!< Line length for Base 64 encoded messages */</span><br><span style="color: hsl(120, 100%, 40%);">+#define BASEMAXINLINE 256 /*!< Buffer size for Base 64 attachment encoding */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Structure used for base64 encoding */</span><br><span style="color: hsl(120, 100%, 40%);">+struct baseio {</span><br><span style="color: hsl(120, 100%, 40%);">+ int iocp;</span><br><span style="color: hsl(120, 100%, 40%);">+ int iolen;</span><br><span style="color: hsl(120, 100%, 40%);">+ int linelength;</span><br><span style="color: hsl(120, 100%, 40%);">+ int ateof;</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned char iobuf[BASEMAXINLINE];</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief utility used by inchar(), for base_encode()</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int inbuf(struct baseio *bio, FILE *fi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int l;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (bio->ateof) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((l = fread(bio->iobuf, 1, BASEMAXINLINE, fi)) != BASEMAXINLINE) {</span><br><span style="color: hsl(120, 100%, 40%);">+ bio->ateof = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (l == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Assume EOF */</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ bio->iolen = l;</span><br><span style="color: hsl(120, 100%, 40%);">+ bio->iocp = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief utility used by base_encode()</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int inchar(struct baseio *bio, FILE *fi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (bio->iocp >= bio->iolen) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!inbuf(bio, fi)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return EOF;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return bio->iobuf[bio->iocp++];</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief utility used by base_encode()</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int ochar(struct baseio *bio, int c, FILE *so, const char *endl)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (bio->linelength >= BASELINELEN) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (fputs(endl, so) == EOF) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ bio->linelength = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (putc(((unsigned char) c), so) == EOF) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ bio->linelength++;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_base64_encode_file(FILE *inputfile, FILE *outputfile, const char *endl)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const unsigned char dtable[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',</span><br><span style="color: hsl(120, 100%, 40%);">+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',</span><br><span style="color: hsl(120, 100%, 40%);">+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',</span><br><span style="color: hsl(120, 100%, 40%);">+ '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};</span><br><span style="color: hsl(120, 100%, 40%);">+ int i, hiteof = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct baseio bio;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ memset(&bio, 0, sizeof(bio));</span><br><span style="color: hsl(120, 100%, 40%);">+ bio.iocp = BASEMAXINLINE;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ while (!hiteof){</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned char igroup[3], ogroup[4];</span><br><span style="color: hsl(120, 100%, 40%);">+ int c, n;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ memset(igroup, 0, sizeof(igroup));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (n = 0; n < 3; n++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((c = inchar(&bio, inputfile)) == EOF) {</span><br><span style="color: hsl(120, 100%, 40%);">+ hiteof = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ igroup[n] = (unsigned char) c;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (n > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ogroup[0]= dtable[igroup[0] >> 2];</span><br><span style="color: hsl(120, 100%, 40%);">+ ogroup[1]= dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];</span><br><span style="color: hsl(120, 100%, 40%);">+ ogroup[2]= dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];</span><br><span style="color: hsl(120, 100%, 40%);">+ ogroup[3]= dtable[igroup[2] & 0x3F];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (n < 3) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ogroup[3] = '=';</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (n < 2) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ogroup[2] = '=';</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < 4; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ochar(&bio, ogroup[i], outputfile, endl);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (fputs(endl, outputfile) == EOF) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_base64_encode_file_path(const char *filename, FILE *outputfile, const char *endl)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ FILE *fi;</span><br><span style="color: hsl(120, 100%, 40%);">+ int res;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(fi = fopen(filename, "rb"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_WARNING, "Failed to open file: %s: %s\n", filename, strerror(errno));</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_base64_encode_file(fi, outputfile, endl);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ fclose(fi);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> const struct ast_flags ast_uri_http = {AST_URI_UNRESERVED};</span><br><span> const struct ast_flags ast_uri_http_legacy = {AST_URI_LEGACY_SPACE | AST_URI_UNRESERVED};</span><br><span> const struct ast_flags ast_uri_sip_user = {AST_URI_UNRESERVED | AST_URI_SIP_USER_UNRESERVED};</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17564">change 17564</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17564"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I1de0ed3483623e9599711129edc817c45ad237ee </div>
<div style="display:none"> Gerrit-Change-Number: 17564 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>