int h323_set_alias(struct oh323_alias *alias) { char *p; char *num; PString h323id(alias->name); PString e164(alias->e164); char *prefix; if (!h323_end_point_exist()) { cout << "ERROR: [h323_set_alias] No Endpoint, this is bad!" << endl; return 1; } cout << "== Adding alias \"" << h323id << "\" to endpoint" << endl; endPoint->AddAliasName(h323id); endPoint->RemoveAliasName(localProcess->GetUserName()); if (!e164.IsEmpty()) { cout << "== Adding E.164 \"" << e164 << "\" to endpoint" << endl; endPoint->AddAliasName(e164); } if (strlen(alias->prefix)) { p = prefix = strdup(alias->prefix); while((num = strsep(&p, ",")) != (char *)NULL) { cout << "== Adding Prefix \"" << num << "\" to endpoint" << endl; endPoint->SupportedPrefixes += PString(num); endPoint->SetGateway(); } if (prefix) free(prefix); } return 0; }
/** Start the H.323 listener */ int h323_start_listener(int listenPort, struct sockaddr_in bindaddr) { if (!h323_end_point_exist()) { cout << "ERROR: [h323_start_listener] No Endpoint, this is bad!" << endl; return 1; } PIPSocket::Address interfaceAddress(bindaddr.sin_addr); if (!listenPort) { listenPort = 1720; } /** H.323 listener */ H323ListenerTCP *tcpListener; tcpListener = new H323ListenerTCP(*endPoint, interfaceAddress, (WORD)listenPort); if (!endPoint->StartListener(tcpListener)) { cout << "ERROR: Could not open H.323 listener port on " << ((H323ListenerTCP *) tcpListener)->GetListenerPort() << endl; delete tcpListener; return 1; } cout << " == H.323 listener started" << endl; return 0; };
void h323_gk_urq(void) { if (!h323_end_point_exist()) { cout << " ERROR: [h323_gk_urq] No Endpoint, this is bad" << endl; return; } endPoint->RemoveGatekeeper(); }
/** Send a DTMF tone over the H323Connection with the * specified token. */ void h323_send_tone(const char *call_token, char tone) { if (!h323_end_point_exist()) { cout << "ERROR: [h323_send_tone] No Endpoint, this is bad!" << endl; return; } PString token = PString(call_token); endPoint->SendUserTone(token, tone); }
int h323_clear_call(const char *call_token) { if (!h323_end_point_exist()) { return 1; } endPoint->ClearCall(PString(call_token)); return 0; };
/** Make a call to the remote endpoint. */ int h323_make_call(char *dest, call_details_t *cd, call_options_t *call_options) { int res; PString token; PString host(dest); if (!h323_end_point_exist()) { return 1; } res = endPoint->MakeCall(host, token, &cd->call_reference, call_options); memcpy((char *)(cd->call_token), (const unsigned char *)token, token.GetLength()); return res; };
/** Establish Gatekeeper communiations, if so configured, * register aliases for the H.323 endpoint to respond to. */ int h323_set_gk(int gatekeeper_discover, char *gatekeeper, char *secret) { PString gkName = PString(gatekeeper); PString pass = PString(secret); H323TransportUDP *rasChannel; if (!h323_end_point_exist()) { cout << "ERROR: [h323_set_gk] No Endpoint, this is bad!" << endl; return 1; } if (!gatekeeper) { cout << "Error: Gatekeeper cannot be NULL" << endl; return 1; } if (strlen(secret)) { endPoint->SetGatekeeperPassword(pass); } if (gatekeeper_discover) { /* discover the gk using multicast */ if (endPoint->DiscoverGatekeeper(new H323TransportUDP(*endPoint))) { cout << " == Using " << (endPoint->GetGatekeeper())->GetName() << " as our Gatekeeper." << endl; } else { cout << " *** Could not find a gatekeeper." << endl; return 1; } } else { rasChannel = new H323TransportUDP(*endPoint); if (!rasChannel) { cout << " *** No RAS Channel, this is bad" << endl; return 1; } if (endPoint->SetGatekeeper(gkName, rasChannel)) { cout << " == Using " << (endPoint->GetGatekeeper())->GetName() << " as our Gatekeeper." << endl; } else { cout << " *** Error registering with gatekeeper \"" << gkName << "\". " << endl; /* XXX Maybe we should fire a new thread to attempt to re-register later and not kill asterisk here? */ return 1; } } return 0; }
/** Make a call to the remote endpoint. */ int h323_make_call(char *host, call_details_t *cd, call_options_t call_options) { int res; PString token; PString dest(host); if (!h323_end_point_exist()) { return 1; } noFastStart = call_options.noFastStart; noH245Tunneling = call_options.noH245Tunneling; res = endPoint->MakeCall(dest, token, &cd->call_reference, call_options.port, call_options.callerid, call_options.callername); memcpy((char *)(cd->call_token), (const unsigned char *)token, token.GetLength()); return res; };
int h323_clear_call(const char *call_token, int cause) { H225_ReleaseCompleteReason dummy; H323Connection::CallEndReason r = H323Connection::EndedByLocalUser; MyH323Connection *connection; const PString currentToken(call_token); if (!h323_end_point_exist()) { return 1; } if (cause) { r = H323TranslateToCallEndReason((Q931::CauseValues)(cause), dummy); } connection = (MyH323Connection *)endPoint->FindConnectionWithLock(currentToken); if (connection) { connection->SetCause(cause); connection->SetCallEndReason(r); connection->Unlock(); } endPoint->ClearCall(currentToken, r); return 0; };
/** * Add capability to the capability table of the end point. */ int h323_set_capabilities(const char *token, int cap, int dtmfMode, struct ast_codec_pref *prefs) { MyH323Connection *conn; if (!h323_end_point_exist()) { cout << " ERROR: [h323_set_capablities] No Endpoint, this is bad" << endl; return 1; } if (!token || !*token) { cout << " ERROR: [h323_set_capabilities] Invalid call token specified." << endl; return 1; } PString myToken(token); conn = (MyH323Connection *)endPoint->FindConnectionWithLock(myToken); if (!conn) { cout << " ERROR: [h323_set_capabilities] Unable to find connection " << token << endl; return 1; } conn->SetCapabilities(cap, dtmfMode, prefs); conn->Unlock(); return 0; }
/** * Add capability to the capability table of the end point. */ int h323_set_capability(int cap, int dtmfMode) { H323Capabilities oldcaps; PStringArray codecs; int g711Frames = 30; int gsmFrames = 4; if (!h323_end_point_exist()) { cout << " ERROR: [h323_set_capablity] No Endpoint, this is bad" << endl; return 1; } /* clean up old capabilities list before changing */ oldcaps = endPoint->GetCapabilities(); for (PINDEX i=0; i< oldcaps.GetSize(); i++) { codecs.AppendString(oldcaps[i].GetFormatName()); } endPoint->RemoveCapabilities(codecs); mode = dtmfMode; if (dtmfMode == H323_DTMF_INBAND) { endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsTone); } else { endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsInlineRFC2833); } if (cap & AST_FORMAT_SPEEX) { /* Not real sure if Asterisk acutally supports all of the various different bit rates so add them all and figure it out later*/ endPoint->SetCapability(0, 0, new SpeexNarrow2AudioCapability()); endPoint->SetCapability(0, 0, new SpeexNarrow3AudioCapability()); endPoint->SetCapability(0, 0, new SpeexNarrow4AudioCapability()); endPoint->SetCapability(0, 0, new SpeexNarrow5AudioCapability()); endPoint->SetCapability(0, 0, new SpeexNarrow6AudioCapability()); } if (cap & AST_FORMAT_G729A) { AST_G729ACapability *g729aCap; AST_G729Capability *g729Cap; endPoint->SetCapability(0, 0, g729aCap = new AST_G729ACapability); endPoint->SetCapability(0, 0, g729Cap = new AST_G729Capability); } if (cap & AST_FORMAT_G723_1) { H323_G7231Capability *g7231Cap; endPoint->SetCapability(0, 0, g7231Cap = new H323_G7231Capability); } if (cap & AST_FORMAT_GSM) { H323_GSM0610Capability *gsmCap; endPoint->SetCapability(0, 0, gsmCap = new H323_GSM0610Capability); gsmCap->SetTxFramesInPacket(gsmFrames); } if (cap & AST_FORMAT_ULAW) { H323_G711Capability *g711uCap; endPoint->SetCapability(0, 0, g711uCap = new H323_G711Capability(H323_G711Capability::muLaw)); g711uCap->SetTxFramesInPacket(g711Frames); } if (cap & AST_FORMAT_ALAW) { H323_G711Capability *g711aCap; endPoint->SetCapability(0, 0, g711aCap = new H323_G711Capability(H323_G711Capability::ALaw)); g711aCap->SetTxFramesInPacket(g711Frames); } if (h323debug) { cout << "Allowed Codecs:\n\t" << setprecision(2) << endPoint->GetCapabilities() << endl; } return 0; }