int CHttpMessage::EncodeMessage(CMemblock* apoBuffer) { char* lpcStart = apoBuffer->GetWrite(); int liRet = 0; this->SaveMBWrite(apoBuffer); if (lpcStart == NULL) return HTTP_ERROR_INVAL; liRet = EncodeStartLine(apoBuffer); if (liRet <0) goto ENCODE_FAILED; liRet = EncodeHeader(apoBuffer); if (liRet <0) goto ENCODE_FAILED; liRet = EncodeBody(apoBuffer); if (liRet <0) goto ENCODE_FAILED; return apoBuffer->GetWrite() - lpcStart; ENCODE_FAILED: this->RestoreMBWrite(apoBuffer); return liRet; }
bool CxImageTIF::Encode(CxFile * hFile, bool bAppend) { try{ if (hFile==NULL) throw CXIMAGE_ERR_NOFILE; if (pDib==NULL) throw CXIMAGE_ERR_NOIMAGE; // <RJ> replaced "w+b" with "a", to append an image directly on an existing file if (m_tif2==NULL) m_tif2=_TIFFOpenEx(hFile, "a"); if (m_tif2==NULL) throw "initialization fail"; if (bAppend || m_pages) m_multipage=true; m_pages++; if (!EncodeBody(m_tif2,m_multipage,m_pages,m_pages)) throw "Error saving TIFF file"; if (bAppend) { if (!TIFFWriteDirectory(m_tif2)) throw "Error saving TIFF directory"; } } catch (char *message) { strncpy(info.szLastError,message,255); if (m_tif2){ TIFFClose(m_tif2); m_tif2=NULL; m_multipage=false; m_pages=0; } return false; } if (!bAppend){ TIFFClose(m_tif2); m_tif2=NULL; m_multipage=false; m_pages=0; } return true; }
bool CoImageTIF::Encode(FILE* pFile, bool bAppend) { if (EncodeSafeCheck(pFile)) return false; XFileDisk hFile(pFile); try { if (&hFile==NULL) throw CVLIB_IMG_ERR_NOFILE; // if (GetPalette() == NULL) throw CVLIB_IMG_ERR_NOIMAGE; // <RJ> replaced "w+b" with "a", to append an image directly on an existing file if (m_tif2==NULL) m_tif2 =(void*)_TIFFOpenEx(&hFile, "a"); if (m_tif2==NULL) throw "initialization fail"; if (bAppend || m_pages) m_multipage=true; m_pages++; if (!EncodeBody(m_tif2,m_multipage,m_pages,m_pages)) throw "Error saving TIFF file"; if (bAppend) { if (!TIFFWriteDirectory((TIFF*)m_tif2)) throw "Error saving TIFF directory"; } } catch (char *message) { strncpy(m_Info.szLastError,message,255); if (m_tif2) { TIFFClose((TIFF*)m_tif2); m_tif2=NULL; m_multipage=false; m_pages=0; } return false; } if (!bAppend) { TIFFClose((TIFF*)m_tif2); m_tif2=NULL; m_multipage=false; m_pages=0; } return true; }
int CPacketBase::EncodeBody(CBuffer *pBuffer) { ASSERT( IsCommandId( CommandId ) ); DWORD nLength = pBuffer->m_nLength; ASSERT( m_pXML != NULL ); EncodeBody( m_pXML ); CString strXML = m_pXML->ToString( FALSE, TRUE ); CString strValue; strValue.Format( "%s %i\r\n", CommandId, strXML.GetLength() ); pBuffer->Print( (LPCTSTR)strValue ); pBuffer->Print( (LPCTSTR)strXML ); pBuffer->Print( "\r\n" ); return pBuffer->m_nLength - nLength; }
void do_plusemail(dbref executor, dbref cause, dbref enactor, int eval, int key, int nargs, UTF8 *arg1, UTF8 *arg2, const UTF8 *cargs[], int ncargs) { UNUSED_PARAMETER(cause); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); UNUSED_PARAMETER(key); UNUSED_PARAMETER(nargs); UNUSED_PARAMETER(cargs); UNUSED_PARAMETER(ncargs); UTF8 inputline[LBUF_SIZE]; if ('\0' == mudconf.mail_server[0]) { notify(executor, T("@email: Not configured")); return; } if (!arg1 || !*arg1) { notify(executor, T("@email: I don\xE2\x80\x99t know who you want to e-mail!")); return; } if (!arg2 || !*arg2) { notify(executor, T("@email: Not sending an empty e-mail!")); return; } UTF8 *addy = alloc_lbuf("mod_email_do_email.headers"); UTF8 *bp = addy; safe_str(arg1, addy, &bp); *bp = '\0'; UTF8 *subject = (UTF8 *)strchr((char *)addy, '/'); if (subject) { *subject = '\0'; subject++; } else { subject = mudconf.mail_subject; } UTF8 *pMailServer = ConvertCRLFtoSpace(mudconf.mail_server); SOCKET mailsock = INVALID_SOCKET; int result = mod_email_sock_open(pMailServer, 25, &mailsock); if (-1 == result) { notify(executor, tprintf(T("@email: Unable to resolve hostname %s!"), pMailServer)); free_lbuf(addy); return; } else if (-2 == result) { // Periodically, we get a failed connect, for reasons which elude me. // In almost every case, an immediate retry works. Therefore, we give // it one more shot, before we give up. // result = mod_email_sock_open(pMailServer, 25, &mailsock); if (0 != result) { notify(executor, T("@email: Unable to connect to mailserver, aborting!")); free_lbuf(addy); return; } } UTF8 *body = alloc_lbuf("mod_email_do_email.body"); UTF8 *bodyptr = body; mux_exec(arg2, LBUF_SIZE-1, body, &bodyptr, executor, executor, executor, EV_TOP | EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, NULL, 0); *bodyptr = '\0'; do { result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1); } while ( 0 == result || ( 3 < result && '-' == inputline[3])); if (-1 == result) { mod_email_sock_close(mailsock); notify(executor, T("@email: Connection to mailserver lost.")); free_lbuf(body); free_lbuf(addy); return; } if ('2' != inputline[0]) { mod_email_sock_close(mailsock); notify(executor, tprintf(T("@email: Invalid mailserver greeting (%s)"), inputline)); } mod_email_sock_printf(mailsock, T("EHLO %s\r\n"), ConvertCRLFtoSpace(mudconf.mail_ehlo)); do { result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1); } while ( 0 == result || ( 3 < result && '-' == inputline[3])); if (-1 == result) { mod_email_sock_close(mailsock); notify(executor, T("@email: Connection to mailserver lost.")); free_lbuf(body); free_lbuf(addy); return; } if ('2' != inputline[0]) { notify(executor, tprintf(T("@email: Error response on EHLO (%s)"), inputline)); } mod_email_sock_printf(mailsock, T("MAIL FROM:<%s>\r\n"), ConvertCRLFtoSpace(mudconf.mail_sendaddr)); do { result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1); } while ( 0 == result || ( 3 < result && '-' == inputline[3])); if (-1 == result) { mod_email_sock_close(mailsock); notify(executor, T("@email: Connection to mailserver lost.")); free_lbuf(body); free_lbuf(addy); return; } if ('2' != inputline[0]) { notify(executor, tprintf(T("@email: Error response on MAIL FROM (%s)"), inputline)); } mod_email_sock_printf(mailsock, T("RCPT TO:<%s>\r\n"), ConvertCRLFtoSpace(addy)); do { result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1); } while ( 0 == result || ( 3 < result && '-' == inputline[3])); if (-1 == result) { mod_email_sock_close(mailsock); notify(executor, T("@email: Connection to mailserver lost.")); free_lbuf(body); free_lbuf(addy); return; } if ('2' != inputline[0]) { notify(executor, tprintf(T("@email: Error response on RCPT TO (%s)"), inputline)); free_lbuf(body); free_lbuf(addy); return; } mod_email_sock_printf(mailsock, T("DATA\r\n")); do { result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1); } while ( 0 == result || ( 3 < result && '-' == inputline[3])); if (-1 == result) { mod_email_sock_close(mailsock); notify(executor, T("@email: Connection to mailserver lost.")); free_lbuf(body); free_lbuf(addy); return; } if ('3' != inputline[0]) { notify(executor, tprintf(T("@email: Error response on DATA (%s)"), inputline)); free_lbuf(body); free_lbuf(addy); return; } UTF8 *pSendName = StringClone(ConvertCRLFtoSpace(mudconf.mail_sendname)); mod_email_sock_printf(mailsock, T("From: %s <%s>\r\n"), pSendName, ConvertCRLFtoSpace(mudconf.mail_sendaddr)); MEMFREE(pSendName); mod_email_sock_printf(mailsock, T("To: %s\r\n"), ConvertCRLFtoSpace(addy)); mod_email_sock_printf(mailsock, T("X-Mailer: TinyMUX %s\r\n"), mudstate.short_ver); mod_email_sock_printf(mailsock, T("Subject: %s\r\n\r\n"), ConvertCRLFtoSpace(subject)); // The body is encoded to include the CRLF.CRLF at the end. // mod_email_sock_printf(mailsock, T("%s"), EncodeBody(body)); do { result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1); // Remove trailing CR and LF characters. // while ( 0 < result && ( '\n' == inputline[result-1] || '\r' == inputline[result-1])) { result--; inputline[result] = '\0'; } } while ( 0 == result || ( 3 < result && '-' == inputline[3])); if (-1 == result) { mod_email_sock_close(mailsock); notify(executor, T("@email: Connection to mailserver lost.")); free_lbuf(body); free_lbuf(addy); return; } if ('2' != inputline[0]) { notify(executor, tprintf(T("@email: Message rejected (%s)"), inputline)); } else { notify(executor, tprintf(T("@email: Mail sent to %s (%s)"), ConvertCRLFtoSpace(addy), &inputline[4])); } mod_email_sock_printf(mailsock, T("QUIT\n")); mod_email_sock_close(mailsock); free_lbuf(body); free_lbuf(addy); }