changed voicemail's temporary file handling. It now uses AmAudio's tmpfile support.

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@13 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Raphael Coeffic 21 years ago
parent a020d00735
commit a325bf8c54

@ -276,7 +276,7 @@ void AnswerMachineDialog::onSessionStart(const AmSipRequest& req)
msg_filename = "/tmp/" + getLocalTag() + "."
+ AnswerMachineFactory::RecFileExt;
if(a_msg.open(msg_filename,AmAudioFile::Write))
if(a_msg.open(msg_filename,AmAudioFile::Write,true))
throw string("AnswerMachine: couldn't open ") +
msg_filename + string(" for writing");
@ -307,13 +307,16 @@ void AnswerMachineDialog::sendMailNotification()
}
else {
try {
// avoid tmp file to be closed
// ~AmMail will do that...
a_msg.setCloseOnDestroy(false);
AmMail* mail = new AmMail(tmpl->getEmail(email_dict));
mail->attachements.push_back(Attachement(msg_filename,
mail->attachements.push_back(Attachement(a_msg.getfp(),
"message."
+ AnswerMachineFactory::RecFileExt,
a_msg.getMimeType()));
mail->clean_up = clean_up_mail;
//mail->clean_up = clean_up_mail;
AmMailDeamon::instance()->sendQueued(mail);
}
catch(const string& err){
@ -324,10 +327,10 @@ void AnswerMachineDialog::sendMailNotification()
void AnswerMachineDialog::clean_up_mail(AmMail* mail)
{
for( Attachements::const_iterator att_it = mail->attachements.begin();
att_it != mail->attachements.end(); ++att_it )
// for( Attachements::const_iterator att_it = mail->attachements.begin();
// att_it != mail->attachements.end(); ++att_it )
unlink(att_it->fullname.c_str());
// unlink(att_it->fullname.c_str());
}
void AnswerMachineDialog::request2dict(const AmSipRequest& req)

@ -392,6 +392,7 @@ int AmAudioFile::open(const string& filename, OpenMode mode, bool is_tmp)
fmt.reset(f_fmt);
open_mode = mode;
this->close_on_exit = close_on_exit;
if(!is_tmp){
fp = fopen(filename.c_str(),mode == AmAudioFile::Read ? "r" : "w+");
@ -529,7 +530,8 @@ int AmAudioFile::fpopen(const string& filename, OpenMode mode, FILE* n_fp)
AmAudioFile::AmAudioFile()
: AmAudio(), data_size(0),
fp(0), begin(0), loop(false),
on_close_done(false)
on_close_done(false),
close_on_exit(true)
{
}
@ -583,7 +585,8 @@ void AmAudioFile::close()
if(fp){
on_close();
fclose(fp);
if(close_on_exit)
fclose(fp);
fp = 0;
}
}

@ -347,6 +347,7 @@ protected:
int data_size;
bool on_close_done;
bool close_on_exit;
/** @see AmAudio::read */
int read(unsigned int user_ts, unsigned int size);
@ -378,7 +379,8 @@ public:
* @return 0 if everything's OK
* @see OpenMode
*/
int open(const string& filename, OpenMode mode, bool is_tmp=false);
int open(const string& filename, OpenMode mode,
bool is_tmp=false);
int fpopen(const string& filename, OpenMode mode, FILE* n_fp);
@ -405,6 +407,10 @@ public:
* @return MIME type corresponding to the audio file.
*/
string getMimeType();
void setCloseOnDestroy(bool cod){
close_on_exit = cod;
}
};
#endif

@ -44,6 +44,15 @@ AmMail::AmMail(const string& _from, const string& _subject,
{
}
AmMail::~AmMail()
{
for(Attachements::iterator it = attachements.begin();
it != attachements.end(); it++){
fclose(it->fp);
}
};
AmMailDeamon* AmMailDeamon::_instance=0;
AmMailDeamon* AmMailDeamon::instance()
@ -64,17 +73,17 @@ int AmMailDeamon::sendQueued(AmMail* mail)
return -1;
}
FILE* tst_fp;
for( Attachements::const_iterator att_it = mail->attachements.begin();
att_it != mail->attachements.end(); ++att_it ){
// FILE* tst_fp;
// for( Attachements::const_iterator att_it = mail->attachements.begin();
// att_it != mail->attachements.end(); ++att_it ){
if(!(tst_fp = fopen(att_it->fullname.c_str(),"r"))){
ERROR("%s\n",strerror(errno));
return -1;
}
else
fclose(tst_fp);
}
// if(!(tst_fp = fopen(att_it->fullname.c_str(),"r"))){
// ERROR("%s\n",strerror(errno));
// return -1;
// }
// else
// fclose(tst_fp);
// }
event_fifo_mut.lock();
event_fifo.push(mail);

@ -43,15 +43,19 @@ using std::queue;
struct Attachement
{
/** Local file name */
string fullname;
//string fullname;
FILE* fp;
/** Proposed remote file name */
string filename;
/** Declared content type */
string content_type;
Attachement(const string& _full, const string& _file="", const string& _ct="")
: fullname(_full), filename(_file), content_type(_ct) {}
// Attachement(const string& _full, const string& _file="", const string& _ct="")
// : fullname(_full), filename(_file), content_type(_ct) {}
Attachement(FILE* _fp, const string& _file="", const string& _ct="")
: fp(_fp), filename(_file), content_type(_ct) {}
};
typedef vector<Attachement> Attachements;
@ -88,6 +92,8 @@ public:
AmMail(const string& _from, const string& _subject,
const string& _to, const string& _body = "");
~AmMail();
};
/**

@ -223,7 +223,7 @@ bool AmSmtpClient::send_body(const vector<string>& hdrs, const AmMail& mail)
}
static void base64_encode(unsigned char* in, unsigned char* out, unsigned int in_size);
static int base64_encode_file(const char* filename, int out);
static int base64_encode_file(FILE* in, int out);
bool AmSmtpClient::send_data(const vector<string>& hdrs, const AmMail& mail)
{
@ -276,7 +276,7 @@ bool AmSmtpClient::send_data(const vector<string>& hdrs, const AmMail& mail)
}
SEND_LINE(""); // EoH
base64_encode_file(att_it->fullname.c_str(),sd);
base64_encode_file(att_it->fp,sd);
SEND_LINE(""); // base64_encode_file() doesn't generate any EoL
}
@ -332,7 +332,7 @@ static void base64_encode(unsigned char* in, unsigned char* out, unsigned int in
out[i] = '=';
}
static int base64_encode_file(const char* filename, int out_fd)
static int base64_encode_file(FILE* in, int out_fd)
{
unsigned char ibuf[B64_INPUT_BUFFER_SIZE];
unsigned char obuf[B64_OUTPUT_BUFFER_SIZE]={' '};
@ -345,11 +345,11 @@ static int base64_encode_file(const char* filename, int out_fd)
return -1;
}
FILE* in = fopen(filename,"rb");
if(!in){
ERROR("%s\n",strerror(errno));
return -1;
}
// FILE* in = fopen(filename,"rb");
// if(!in){
// ERROR("%s\n",strerror(errno));
// return -1;
// }
int bytes_written=0;
while((s = fread(ibuf,1,B64_INPUT_BUFFER_SIZE,in))){

Loading…
Cancel
Save