Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions smqueue/smqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ void SMq::process_timeout()
// not to reference qmsg (I don't know a C++ way
// to set it to NULL or delete it or something).
temp.pop_front();
//update stable storage
save_queue_to_file(savefile);
}
break;

Expand Down Expand Up @@ -1427,7 +1429,7 @@ SMq::originate_sm(const char *from, const char *to, const char *msgtext,

errcode = response->validate_short_msg(this, false);
if (errcode == 0) {
insert_new_message (*smpl, firststate); // originate_sm
insert_new_message (*smpl, firststate, true); // originate_sm
}
else {
LOG(DEBUG) << "Short message validate failed, error " << errcode;
Expand Down Expand Up @@ -1734,7 +1736,7 @@ SMq::register_handset(short_msg_p_list::iterator qmsg)

// Pop new SIP REGISTER out of the smpl queue-of-one and
// into the real queue, where it will very soon be delivered.
insert_new_message (*smpl, REQUEST_MSG_DELIVERY); // In register_handset
insert_new_message (*smpl, REQUEST_MSG_DELIVERY, true); // In register_handset
// We can't reference response, or *smpl, any more...

delete smpl;
Expand Down Expand Up @@ -2465,7 +2467,7 @@ void SMq::main_loop(int msTMO)

// **********************************************************************
// ****************** Insert a message in the queue *********************
insert_new_message(*smpl); // Reader thread main_loop
insert_new_message(*smpl, true); // Reader thread main_loop
errcode = 202;
// It's OK to reference "smp" here, whether it's in the
// smpl list, or has been moved into the main time_sorted_list.
Expand Down Expand Up @@ -2516,6 +2518,9 @@ SMq::save_queue_to_file(std::string qfile)
unsigned howmany = 0;
LOG(DEBUG) << "save_queue_to_file:" << qfile;

//if it crashes during message write we can lose stuff. Better
//than nothing for now --kurtis
//overwrites by default
ofile.open(qfile.c_str(), ios::out | ios::binary | ios::trunc);
if (!ofile.is_open())
return false;
Expand Down Expand Up @@ -2630,7 +2635,7 @@ SMq::read_queue_from_file(std::string qfile)
<< " direction=" << (smp->ms_to_sc?"MS->SC":"SC->MS")
<< " need_repack=" << (smp->need_repack?"true":"false");
// Fixed error where invalid messages were getting put in the queue
insert_new_message (*smpl, mystate, mytime); // In read_queue_from_file
insert_new_message (*smpl, mystate, mytime, false); // In read_queue_from_file
} else {
LOG(DEBUG) << "Read bad SMS "
<< smp->parsed->status_code
Expand Down
35 changes: 12 additions & 23 deletions smqueue/smqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -1108,38 +1108,27 @@ class SMq {
// them to the real list. Note that this moves the message's list
// entry itself off the original list (which can then be discarded).
// Push_front only does a copy so use splice ??
void insert_new_message(short_msg_p_list &smp) {

// This version lets the state and timeout be set.
void insert_new_message(short_msg_p_list &smp, enum sm_state s, time_t t, bool save) {
if (save){
save_queue_to_file(savefile);
}
lockSortedList();
time_sorted_list.splice (time_sorted_list.begin(), smp);
time_sorted_list.begin()->set_state (INITIAL_STATE); // Note set state can move the entries in the queue
// time_sorted_list.begin()->timeout = 0; // it is already
// Low timeout will cause this msg to be at front of queue.
time_sorted_list.begin()->set_state (s, t);
unlockSortedList();
debug_dump(); //svgfix
ProcessReceivedMsg();
}

// This version lets the initial state be set.
void insert_new_message(short_msg_p_list &smp, enum sm_state s) {
LOG(DEBUG) << "Insert message into queue 2";
lockSortedList();
time_sorted_list.splice (time_sorted_list.begin(), smp);
time_sorted_list.begin()->set_state (s);
// time_sorted_list.begin()->timeout = 0; // it is already
// Low timeout will cause this msg to be at front of queue.
unlockSortedList();
debug_dump(); //svgfix
ProcessReceivedMsg();
void insert_new_message(short_msg_p_list &smp, enum sm_state s, bool save) {
insert_new_message(smp,s,0,save);
}
// This version lets the state and timeout be set.
void insert_new_message(short_msg_p_list &smp, enum sm_state s, time_t t) {
LOG(DEBUG) << "Insert message into queue 3";
lockSortedList();
time_sorted_list.splice (time_sorted_list.begin(), smp);
time_sorted_list.begin()->set_state (s, t);
unlockSortedList();
debug_dump(); //svgfix
ProcessReceivedMsg();

void insert_new_message(short_msg_p_list &smp, bool save) {
insert_new_message(smp,INITIAL_STATE,save);
}

/* Debug dump of the queue and the SMq class in general. */
Expand Down