siproc

A primitive SIP client that spawns processes for each call
git clone git://xatko.vsos.ethz.ch/siproc.git
Log | Files | Refs

commit 0880d8d2213242094b3fb244452a5b5708316c92
parent 82a61e33349e4784854331dd8707cd9beeba74bd
Author: Dominik Schmidt <dominik@schm1dt.ch>
Date:   Sat, 10 Aug 2019 22:42:36 +0200

Implement outgoing calls.

If the main thread reads "CALL <URI>" on its stdin, it starts the
same program, but sets the environment variable SIPROC_OUTGOING to
"y", otherwise it is "n".

Diffstat:
src/siproc.cpp | 32+++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/siproc.cpp b/src/siproc.cpp @@ -154,7 +154,7 @@ class MyCall: public Call{ child = -1; } - void fork_on(char **args); + void fork_on(char **args, bool outgoing); virtual void onCallState(OnCallStateParam &prm){ CallInfo ci = getInfo(); @@ -164,6 +164,9 @@ class MyCall: public Call{ delete this; return; } + else if(ci.state == PJSIP_INV_STATE_CONFIRMED){ + command("CONNECTED\n"); + } } bool onPlayerFinished(char *path, MyAudioMediaPlayer* who){ @@ -344,11 +347,11 @@ class MyAccount: public Account{ virtual void onIncomingCall(OnIncomingCallParam &iprm){ MyCall *call = new MyCall(*this, iprm.callId); - call->fork_on(args); + call->fork_on(args, false); } }; -void MyCall::fork_on(char **args){ +void MyCall::fork_on(char **args, bool outgoing){ PJ_LOG(4, ("MyCall", "Setting up Fork")); int pipes_stdin[2], pipes_stdout[2]; @@ -378,6 +381,7 @@ void MyCall::fork_on(char **args){ setenv("SIPROC_REMOTE_ID", ci.callIdString.c_str(), 1); setenv("SIPROC_REMOTE_URI", ci.remoteUri.c_str(), 1); setenv("SIPROC_REMOTE_CONTACT", ci.remoteContact.c_str(), 1); + setenv("SIPROC_OUTGOING", (outgoing) ? "y" : "n", 1); if(execv(args[0], args) < 0){ perror("exec"); } @@ -469,12 +473,30 @@ int main(int argc, char **argv){ if(ptr == &line_length){ ssize_t bytes = getline(&line, &line_length, stdin); if(bytes > 0){ - line[--bytes] = '\0'; printf("Got line with length %lu:\n", bytes); fwrite(line, 1, bytes, stdout); - if(strncmp(line, "QUIT", line_length) == 0){ + line[--bytes] = '\0'; + size_t cmdlen=line_length; + char *args = strstr(line, " "); + if(args){ + line_length -= args-line; + *args++ = '\0'; + } + + if(strncmp(line, "QUIT", cmdlen) == 0){ break; } + else if(strncmp(line, "CALL", cmdlen) == 0){ + printf("Making call\n"); + MyCall *mc = new MyCall(*acc); + CallOpParam prm(true); + try{ + mc->makeCall(std::string(line+5), prm); + mc->fork_on(acc->args, true); + } + catch(Error& err) { + } + } } } else{