Skip to content

Instantly share code, notes, and snippets.

@valinurovam
Created October 26, 2012 13:17
Show Gist options
  • Save valinurovam/3958759 to your computer and use it in GitHub Desktop.
Save valinurovam/3958759 to your computer and use it in GitHub Desktop.
handle_submit_sm(Pid, Pdu, _From, St) ->
[{_, PartnerID, IP}] = ets:lookup(?SESSIONS, Pid),
lager:info("Method: submit_sm PartnerID: ~p PDU: ~p IP: ~p", [PartnerID, Pdu, IP]),
try
PDUArgs = smpp_tools:get_message_details(Pdu, PartnerID),
LastInsertID = save_pdu_to_db(PDUArgs),
DestinationAddr = proplists:get_value(destination_addr, PDUArgs, undefined),
SourceAddr = proplists:get_value(source_addr, PDUArgs, undefined),
UdhRef = proplists:get_value(udh_ref, PDUArgs, undefined),
UdhTotal = proplists:get_value(udh_total, PDUArgs, undefined),
Key = {PartnerID, SourceAddr, DestinationAddr, UdhRef, UdhTotal},
Value = [
{pdu_id, LastInsertID},
{ip, IP} |
PDUArgs
],
smpp_queue_server:queue_add_item({Key,Value}),
MsgId = integer_to_list(LastInsertID),
Params = [{message_id, MsgId}],
{reply, {ok, Params}, St#st{msg_id = St#st.msg_id + 1,
success = St#st.success + 1}}
catch
Error:Reason ->
lager:error("Error: ~p Reason: ~p ~n", [Error, Reason]),
case Reason of
{smpp_partner_error, Status} -> ok;
_ -> Status = ?ESME_RSYSERR
end,
{reply, {error, Status}, St#st{failure = St#st.failure + 1}}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment