/** * Sample object setting the defaults document for subsequent calls * * @param properties [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param parameters [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param execute [IN] Specifies whether the object should be * executed (true) or simply validated (false) * @param result [OUT] See description in VXIobjectExecute() * or VXIobjectValidate() * * @result VXIobj_RESULT_SUCCESS on success */ static VXIobjResult ProcessComSpeechworksSetDefaultsObject (struct VXIobjectInterface *pThis, const VXIMap *properties, const VXIMap *parameters, VXIbool execute, VXIValue **result) { static const wchar_t func[] = L"ProcessComSpeechworksSetDefaults"; GET_VXIOBJECT (pThis, sbObject, log, rc); if((execute) && (result == NULL)) return VXIobj_RESULT_INVALID_ARGUMENT; if((! properties) || (! parameters)) return VXIobj_RESULT_INVALID_ARGUMENT; if(execute) { const VXIchar *defaults = NULL; const VXIValue *val = VXIMapGetProperty(parameters, L"defaults"); if (! val) { Error(log, 202, L"%s%s", L"parameter", L"defaults"); return VXIobj_RESULT_INVALID_PROP_VALUE; } else if (VXIValueGetType(val) != VALUE_STRING) { Error(log, 203, L"%s%s%s%d", L"parameter", L"defaults", L"type", VXIValueGetType(val)); return VXIobj_RESULT_INVALID_PROP_VALUE; } defaults = VXIStringCStr(reinterpret_cast<const VXIString *>(val)); if (! defaults[0]) { Error(log, 204, L"%s%s%s%s", L"parameter", L"defaults", L"value", defaults); return VXIobj_RESULT_INVALID_PROP_VALUE; } // Hack to set the defaults document VXIobjectAPI *objectAPI = (VXIobjectAPI *) pThis; if ( ! objectAPI ) { rc = VXIobj_RESULT_INVALID_ARGUMENT; return rc; } VXIplatform *plat = objectAPI->resources->platform; VXIMap *vxiProperties = VXIMapCreate(); VXIString * valstr = VXIStringCreate(defaults); VXIMapSetProperty(vxiProperties, VXI_PLATFORM_DEFAULTS, (VXIValue *) valstr); plat->VXIinterpreter->SetProperties(plat->VXIinterpreter, vxiProperties); // Create the result object VXIMap *resultObj = VXIMapCreate(); if(resultObj == NULL) { Error(log, 100, NULL); return VXIobj_RESULT_OUT_OF_MEMORY; } *result = reinterpret_cast<VXIValue *>(resultObj); // Set the result object's status field to 'success' VXIMapSetProperty(resultObj, L"status", reinterpret_cast<VXIValue *>(VXIStringCreate(L"success"))); } return VXIobj_RESULT_SUCCESS; }
/** * Sample object echoing back all parameters * * @param properties [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param parameters [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param execute [IN] Specifies whether the object should be * executed (true) or simply validated (false) * @param result [OUT] See description in VXIobjectExecute() * or VXIobjectValidate() * * @result VXIobj_RESULT_SUCCESS on success */ static VXIobjResult ProcessComSpeechworksEchoObject (struct VXIobjectInterface *pThis, const VXIMap *properties, const VXIMap *parameters, VXIbool execute, VXIValue **result) { static const wchar_t func[] = L"ProcessComSpeechworksEchoObject"; GET_VXIOBJECT (pThis, sbObject, log, rc); if((execute) && (result == NULL)) return VXIobj_RESULT_INVALID_ARGUMENT; if((! properties) || (! parameters)) return VXIobj_RESULT_INVALID_ARGUMENT; if(execute) { // Create the result object VXIMap *resultObj = VXIMapCreate(); if(resultObj == NULL) { Error(log, 100, NULL); return VXIobj_RESULT_OUT_OF_MEMORY; } *result = reinterpret_cast<VXIValue *>(resultObj); // Simply add the input properties and parameters to the result object VXIMapSetProperty(resultObj, L"attributes", VXIValueClone((VXIValue *)properties)); VXIMapSetProperty(resultObj, L"parameters", VXIValueClone((VXIValue *)parameters)); } return VXIobj_RESULT_SUCCESS; }
/** * Bridging Transfer. * */ static VXItelResult OSBtelTransferBridge(VXItelInterface * vxip, const VXIMap * prop, const VXIchar * transferDestination, const VXIMap * data, VXIMap **resp) { OSBtelImpl *impl = ToOSBtelImpl(vxip); Diag(impl, DIAG_TAG_SIGNALING, NULL, L"TransferBridge: %s", transferDestination); *resp = VXIMapCreate(); VXIchar* dest = 0; VXIchar* xaudio = 0; if (prop != NULL) { VXIString* vect =(VXIString*)VXIMapGetProperty(prop, L"Destination"); if (vect != NULL) dest = (VXIchar*) VXIStringCStr(vect); vect =(VXIString*)VXIMapGetProperty(prop, TEL_TRANSFER_AUDIO); if (vect != NULL) xaudio = (VXIchar*) VXIStringCStr(vect); } *resp = VXIMapCreate(); if (impl->callId && transferDestination) { vxistring dest = transferDestination; if (! dest.empty()) { char* str = 0; int len = dest.length() + 1; if (len > 0) { str = new char [len + 1]; wcstombs(str, transferDestination, len); str[len] = 0; } if (str) { UtlString from(str); HttpMessage::unescape( from ); if (impl->live == 1) { impl->pCallMgr->connect((char*)impl->callId, from.data()); impl->transferred = 0; int state = 0; int status = VXItel_TRANSFER_UNKNOWN; int duration = 0; OsTime startTime; OsTime endTime; OsDateTimeBase::getCurTime(startTime); VXItelResult ret; do { ret = setTransferState(impl, prop, transferDestination, resp, &state, &status); } while (state != PtEvent::CONNECTION_DISCONNECTED && state != PtEvent::CONNECTION_FAILED && ret != VXItel_RESULT_TIMEOUT); OsDateTimeBase::getCurTime(endTime); duration = (endTime.cvtToMsecs() - startTime.cvtToMsecs())/1000; VXIMapSetProperty(*resp, TEL_TRANSFER_STATUS, (VXIValue *) VXIIntegerCreate(status)); VXIMapSetProperty(*resp, TEL_TRANSFER_DURATION, (VXIValue *)VXIIntegerCreate(duration)); } else { Diag(impl, DIAG_TAG_SIGNALING, NULL, L"Exiting called, live=%d, cancel TransferBridge: %s", impl->live, transferDestination); } } } } return VXItel_RESULT_SUCCESS; }
/** * Blind Transfer. */ static VXItelResult OSBtelTransferBlind(VXItelInterface * vxip, const VXIMap * prop, const VXIchar * transferDestination, const VXIMap * data, VXIMap ** resp) { OSBtelImpl *impl = ToOSBtelImpl(vxip); Diag(impl, DIAG_TAG_SIGNALING, NULL, L"TransferBlind: %s", transferDestination); VXIchar* best = (VXIchar *) calloc(128, sizeof(VXIchar)); if (prop != NULL) { VXIString* vect =(VXIString*)VXIMapGetProperty(prop, L"Destination"); if (vect != NULL) best = (VXIchar*) VXIStringCStr(vect); } *resp = VXIMapCreate(); if (impl->callId && transferDestination) { vxistring dest = transferDestination; if (! dest.empty()) { char* str = 0; int len = dest.length() + 1; if (len > 0) { str = new char [len + 1]; wcstombs(str, transferDestination, len); str[len] = 0; } if (str) { UtlString from(str); HttpMessage::unescape( from ); OsSysLog::add(FAC_MEDIASERVER_VXI, PRI_DEBUG, "OSBtelTransferBlind from = '%s'", from.data()); if (impl->live == 1) { if (PT_SUCCESS == impl->pCallMgr->transfer_blind((char*)impl->callId, from.data(), // to url 0, // target call id 0, // target connect addr false // no remote hold first ) ) { impl->transferred = 0; int state = 0; int status = VXItel_TRANSFER_UNKNOWN; int duration = 0; OsTime startTime; OsTime endTime; OsDateTimeBase::getCurTime(startTime); setTransferState(impl, prop, transferDestination, resp, &state, &status); OsDateTimeBase::getCurTime(endTime); duration = (endTime.cvtToMsecs() - startTime.cvtToMsecs())/1000; VXIMapSetProperty(*resp, TEL_TRANSFER_STATUS, (VXIValue *) VXIIntegerCreate(status)); VXIMapSetProperty(*resp, TEL_TRANSFER_DURATION, (VXIValue *)VXIIntegerCreate(duration)); } } else { Diag(impl, DIAG_TAG_SIGNALING, NULL, L"Exiting called, live=%d, cancel TransferBlind: %s", impl->live, transferDestination); } } } } return VXItel_RESULT_SUCCESS; }
/** * Sample object to save a recording to a file * * @param properties [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param parameters [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param execute [IN] Specifies whether the object should be * executed (true) or simply validated (false) * @param result [OUT] See description in VXIobjectExecute() * or VXIobjectValidate() * * @result VXIobj_RESULT_SUCCESS on success */ static VXIobjResult ProcessComSpeechworksSaveRecordingObject (struct VXIobjectInterface *pThis, const VXIMap *properties, const VXIMap *parameters, VXIbool execute, VXIValue **result) { static const wchar_t func[] = L"ProcessComSpeechworksSaveRecordingObject"; GET_VXIOBJECT (pThis, sbObject, log, rc); if((execute) && (result == NULL)) return VXIobj_RESULT_INVALID_ARGUMENT; if((! properties) || (! parameters)) return VXIobj_RESULT_INVALID_ARGUMENT; // Get the recording, MIME type, size, and destination path const VXIbyte *recording = NULL; const VXIchar *type = NULL, *dest = NULL; VXIulong size = 0; const VXIValue *val = VXIMapGetProperty(parameters, L"recording"); if (! val) { Error(log, 202, L"%s%s", L"parameter", L"recording"); return VXIobj_RESULT_INVALID_PROP_VALUE; } else if (VXIValueGetType(val) != VALUE_CONTENT) { Error(log, 203, L"%s%s%s%d", L"parameter", L"recording", L"type", VXIValueGetType(val)); return VXIobj_RESULT_INVALID_PROP_VALUE; } if (VXIContentValue(reinterpret_cast<const VXIContent *>(val), &type, &recording, &size) != VXIvalue_RESULT_SUCCESS) { Error(log, 204, L"%s%s", L"parameter", L"recording"); return VXIobj_RESULT_INVALID_PROP_VALUE; } else if (size < 1) { Error(log, 204, L"%s%s%s%d", L"parameter", L"recording.size", L"value", L"size"); return VXIobj_RESULT_INVALID_PROP_VALUE; } val = VXIMapGetProperty(parameters, L"dest"); if (! val) { Error(log, 202, L"%s%s", L"parameter", L"dest"); return VXIobj_RESULT_INVALID_PROP_VALUE; } else if (VXIValueGetType(val) != VALUE_STRING) { Error(log, 203, L"%s%s%s%d", L"parameter", L"dest", L"type", VXIValueGetType(val)); return VXIobj_RESULT_INVALID_PROP_VALUE; } dest = VXIStringCStr(reinterpret_cast<const VXIString *>(val)); if (! dest[0]) { Error(log, 204, L"%s%s%s%s", L"parameter", L"dest", L"value", dest); return VXIobj_RESULT_INVALID_PROP_VALUE; } if(execute) { // Convert the destination to narrow characters, use an upside // down question mark for unsupported Unicode characters size_t len = wcslen(dest); char *ndest = new char [len + 1]; if (! ndest) { Error(log, 100, NULL); return VXIobj_RESULT_OUT_OF_MEMORY; } for (size_t i = 0; i <= len; i++) ndest[i] = (dest[i] & 0xff00 ? '\277' : static_cast<char>(dest[i])); // Open the destination and save the file size_t totWritten = 0; #ifdef VXIOBJECT_PERMIT_FILE_WRITES FILE *fp = fopen(ndest, "wb"); delete [] ndest; if (fp) { do { size_t w = fwrite(&recording[totWritten], 1, ((size_t) size) - totWritten, fp); totWritten += w; } while ((totWritten < (size_t) size) && (! ferror(fp))); fclose(fp); } else { Error(log, 205, L"%s%s%s%d", L"file", dest, L"errno", errno); } #else Error(log, 206, L"%s%s", L"file", dest); #endif // Create the result object VXIMap *resultObj = VXIMapCreate(); if(resultObj == NULL) { Error(log, 100, NULL); return VXIobj_RESULT_OUT_OF_MEMORY; } *result = reinterpret_cast<VXIValue *>(resultObj); // Set the result object's status field to 'success' or 'failure' if (totWritten == (size_t) size) VXIMapSetProperty(resultObj, L"status", reinterpret_cast<VXIValue *>(VXIStringCreate(L"success"))); else VXIMapSetProperty(resultObj, L"status", reinterpret_cast<VXIValue *>(VXIStringCreate(L"failure"))); } return VXIobj_RESULT_SUCCESS; }
/** * Sample diagnostic logging object * * @param properties [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param parameters [IN] See description in VXIobjectExecute() * or VXIobjectValidate() * @param execute [IN] Specifies whether the object should be * executed (true) or simply validated (false) * @param result [OUT] See description in VXIobjectExecute() * or VXIobjectValidate() * * @result VXIobj_RESULT_SUCCESS on success */ static VXIobjResult ProcessComSpeechworksDiagObject (struct VXIobjectInterface *pThis, const VXIMap *properties, const VXIMap *parameters, VXIbool execute, VXIValue **result) { static const wchar_t func[] = L"ProcessComSpeechworksDiagObject"; GET_VXIOBJECT (pThis, sbObject, log, rc); if((execute) && (result == NULL)) return VXIobj_RESULT_INVALID_ARGUMENT; if((! properties) || (! parameters)) return VXIobj_RESULT_INVALID_ARGUMENT; // Get the tag ID const VXIValue *val = VXIMapGetProperty(parameters, L"tag"); if(val == NULL) { Error(log, 202, L"%s%s", L"parameter", L"tag"); return VXIobj_RESULT_INVALID_PROP_VALUE; } VXIint tag; switch (VXIValueGetType(val)) { case VALUE_INTEGER: tag = VXIIntegerValue((VXIInteger *)val); break; case VALUE_STRING: { wchar_t *ptr; tag = ::wcstol(VXIStringCStr((VXIString *)val), &ptr, 10); } break; default: Error(log, 203, L"%s%s%s%d", L"parameter", L"tag", L"type", VXIValueGetType(val)); return VXIobj_RESULT_INVALID_PROP_VALUE; } // Get the message string val = VXIMapGetProperty(parameters, L"message"); if(val == NULL) { Error(log, 202, L"%s%s", L"parameter", L"message"); return VXIobj_RESULT_INVALID_PROP_VALUE; } // Check whether the message was sent in "data" or "ref" format. // If it is "ref", we need to retrieve it in the embedded map. const VXIchar *messageStr = NULL; switch (VXIValueGetType(val)) { case VALUE_MAP: { const VXIValue *val2 = VXIMapGetProperty((const VXIMap *)val, OBJECT_VALUE); if (VXIValueGetType(val2) == VALUE_STRING) messageStr = VXIStringCStr((VXIString *)val2); } break; case VALUE_STRING: messageStr = VXIStringCStr((VXIString *)val); break; default: Error(log, 203, L"%s%s%s%d", L"parameter", L"message", L"type", VXIValueGetType(val)); return VXIobj_RESULT_INVALID_PROP_VALUE; } if ((! messageStr) || (! messageStr[0])) { Error(log, 204, L"%s%s", L"parameter", L"message"); return VXIobj_RESULT_INVALID_PROP_VALUE; } if(execute) { // Print a diagnostic message using the retrieved arguments. // To see this message, you must enable client.log.diagTag.xxx // in your VXIclient configuration file, where 'xxx' is the // value of client.object.diagLogBase defined in the same file. VXIlogResult rc = Diag (log, tag, NULL, messageStr); // Create the result object VXIMap *resultObj = VXIMapCreate(); if(resultObj == NULL) { Error(log, 100, NULL); return VXIobj_RESULT_OUT_OF_MEMORY; } *result = reinterpret_cast<VXIValue *>(resultObj); // Set the result object's status field to 'success' or 'failure' if(rc == VXIlog_RESULT_SUCCESS) VXIMapSetProperty(resultObj, L"status", reinterpret_cast<VXIValue *>(VXIStringCreate(L"success"))); else VXIMapSetProperty(resultObj, L"status", reinterpret_cast<VXIValue *>(VXIStringCreate(L"failure"))); } return VXIobj_RESULT_SUCCESS; }