int chdir_for_file(char const *dir, bool is_filename) { char *redir; if (is_filename) { redir = tempstr_printf("%s", dir); char *last_slash = redir; for (char *c = redir; *c; c++) if (*c == '/') last_slash = c; *last_slash = '\0'; } else { redir = (char *)dir; } SLOG(LOG_DEBUG, "chdir into '%s'", redir); if (redir[0] == '\0') return 0; if (0 != chdir(redir)) { SLOG(LOG_ERR, "Cannot chdir(%s): %s", redir, strerror(errno)); return -1; } return 0; }
static int opt_iface(char const *opt) { return ext_eval(tempstr_printf("(open-iface \"%s\")", opt)); }
static int opt_plugin(char const *opt) { return ext_eval(tempstr_printf("(load-plugin \"%s\")", opt)); }
static int opt_logfile(char const *opt) { return ext_eval(tempstr_printf("(set-log-file \"%s\")", opt)); }
static int opt_config(char const *opt) { some_conffile_loaded = true; return ext_eval(tempstr_printf("(load \"%s\")", opt)); }
static char const *capfile_path(struct capfile *capfile) { if (! capfile->rotation) return capfile->path; return tempstr_printf("%s.%u", capfile->path, (capfile->file_num++)%capfile->rotation); }
static char const *query_reply_2_str(struct sql_proto_info const *info) { return tempstr_printf(", nb_rows=%d, nb_fields=%d", info->set_values & SQL_NB_ROWS ? (int)info->u.query.nb_rows : -1, info->set_values & SQL_NB_FIELDS ? (int)info->u.query.nb_fields : -1); }
static char const *tds_header_2_str(struct tds_header *header) { return tempstr_printf("Type: %s, Status: %d, Length: %zu, Channel %"PRIu16", Pkt number %"PRIu8", Window %"PRIu8"", tds_packet_type_2_str(header->type), header->status, header->len, header->channel, header->pkt_number, header->window); }
static char const *skinny_msgid_2_str(enum skinny_msgid id) { switch (id) { case SKINNY_STATION_KEEPALIVE: return "Keepalive"; case SKINNY_STATION_REGISTER: return "Register"; case SKINNY_STATION_IP_PORT: return "Ip port"; case SKINNY_STATION_KEY_PAD_BUTTON: return "Key pad button"; case SKINNY_STATION_ENBLOC_CALL: return "Enbloc call"; case SKINNY_STATION_STIMULUS: return "Stimulus"; case SKINNY_STATION_OFF_HOOK: return "Off hook"; case SKINNY_STATION_ON_HOOK: return "On hook"; case SKINNY_STATION_HOOK_FLASH: return "Hook flash"; case SKINNY_STATION_FORWARD_STATUS_REQ: return "Forward status request"; case SKINNY_STATION_SPEED_DIAL_STATUS_REQ: return "Speed dial status request"; case SKINNY_STATION_LINE_STATUS_REQ: return "Line status request"; case SKINNY_STATION_CONFIGURATION_STATUS_REQ: return "Configuration status request"; case SKINNY_STATION_TIME_DATE_REQ: return "Time date request"; case SKINNY_STATION_BUTTON_TEMPLATE_REQ: return "Button template request"; case SKINNY_STATION_VERSION_REQ: return "Version request"; case SKINNY_STATION_CAPABILITIES_RESP: return "Capabilities response"; case SKINNY_STATION_MEDIA_PORT_LIST: return "Media port list"; case SKINNY_STATION_SERVER_REQ: return "Server request"; case SKINNY_STATION_ALARM: return "Alarm"; case SKINNY_STATION_MULTICAST_MEDIA_RECEPT_ACK: return "Multicast media reception ack"; case SKINNY_STATION_OFF_HOOK_WITH_CALLING_PARTY_NUMBER: return "Off hook with calling party number"; case SKINNY_STATION_OPEN_RECV_CHANNEL_ACK: return "Open receive channel ack"; case SKINNY_STATION_CONNECTION_STATISTICS_RESP: return "Connection statistics response"; case SKINNY_STATION_SOFT_KEY_TEMPLATE_REQ: return "Soft key template request"; case SKINNY_STATION_SOFT_KEY_SET_REQ: return "Soft key set request"; case SKINNY_STATION_SOFT_KEY_EVENT: return "Soft key event"; case SKINNY_STATION_UNREGISTER: return "Unregister"; case SKINNY_STATION_REGISTER_TOKEN_REQ: return "Register token request"; case SKINNY_STATION_MEDIA_TRANSMIT_FAILURE: return "Media transmit failure"; case SKINNY_STATION_HEADSET_STATUS: return "Headset status"; case SKINNY_STATION_MEDIA_RESOURCE_NOTIF: return "Media resource notif"; case SKINNY_STATION_REGISTER_AVAILABLE_LINES: return "Register available lines"; case SKINNY_STATION_DEVICE_TO_USER_DATA: return "Device to user data"; case SKINNY_STATION_DEVICE_TO_USER_DATA_RESP: return "Device to user data response"; case SKINNY_STATION_UPDATE_CAPABILITIES: return "Update capabilities"; case SKINNY_STATION_OPEN_MULTIMEDIA_RECV_CHANNEL_ACK: return "Open multimedia receive channel ack"; case SKINNY_STATION_CLEAR_CONFERENCE: return "Clear conference"; case SKINNY_STATION_SERVICE_URLSTAT_REQ: return "Service urlstat request"; case SKINNY_STATION_FEATURE_STAT_REQ: return "Feature stat request"; case SKINNY_STATION_CREATE_CONFERENCE_RES: return "Create conference res"; case SKINNY_STATION_DELETE_CONFERENCE_RES: return "Delete conference res"; case SKINNY_STATION_MODIFY_CONFERENCE_RES: return "Modify conference res"; case SKINNY_STATION_ADD_PARTICIPANT_RES: return "Add participant res"; case SKINNY_STATION_AUDIT_CONFERENCE_RES: return "Audit conference res"; case SKINNY_STATION_AUDIT_PARTICIPANT_RES: return "Audit participant res"; case SKINNY_STATION_DEVICE_TO_USER_DATA_VERSION1: return "Device to user data version1"; case SKINNY_STATION_DEVICE_TO_USER_DATA_RESP_VERSION1: return "Device to user data response version1"; case SKINNY_STATION_DIALED_PHONE_BOOK: return "Dialed phone book"; case SKINNY_MGR_KEEPALIVE: return "Keepalive"; case SKINNY_MGR_START_TONE: return "Start tone"; case SKINNY_MGR_STOP_TONE: return "Stop tone"; case SKINNY_MGR_SET_RINGER: return "Set ringer"; case SKINNY_MGR_SET_LAMP: return "Set lamp"; case SKINNY_MGR_SET_HOOK_FLASH_DETECT: return "Set hook flash detect"; case SKINNY_MGR_SET_SPEAKER_MODE: return "Set speaker mode"; case SKINNY_MGR_SET_MICROPHONE_MODE: return "Set microphone mode"; case SKINNY_MGR_START_MEDIA_TRANSMIT: return "Start media transmission"; case SKINNY_MGR_STOP_MEDIA_TRANSMIT: return "Stop media transmission"; case SKINNY_MGR_START_MEDIA_RECEPTION: return "Start media reception"; case SKINNY_MGR_STOP_MEDIA_RECEPTION: return "Stop media reception"; case SKINNY_MGR_CALL_INFORMATION: return "Call information"; case SKINNY_MGR_REGISTER_REJECT: return "Register reject"; case SKINNY_MGR_RESET: return "Reset"; case SKINNY_MGR_KEEPALIVE_ACK: return "Keepalive ack"; case SKINNY_MGR_FORWARD_STATUS: return "Forward status"; case SKINNY_MGR_SPEED_DIAL_STATUS: return "Speed dial status"; case SKINNY_MGR_LINE_STATUS: return "Line status"; case SKINNY_MGR_CONFIGURATION_STATUS: return "Configuration status"; case SKINNY_MGR_DEFINE_TIME_N_DATE: return "Define time & date"; case SKINNY_MGR_START_SESSION_TRANSMIT: return "Start session transmission"; case SKINNY_MGR_STOP_SESSION_TRANSMIT: return "Stop session transmission"; case SKINNY_MGR_BUTTON_TEMPLATE: return "Button template"; case SKINNY_MGR_VERSION: return "Version"; case SKINNY_MGR_DISPLAY_TEXT: return "Display text"; case SKINNY_MGR_CLEAR_DISPLAY: return "Clear display"; case SKINNY_MGR_CAPABILITIES_REQ: return "Capabilities request"; case SKINNY_MGR_ENUNCIATOR_COMMAND: return "Enunciator command"; case SKINNY_MGR_SERVER_RESP: return "Server respond"; case SKINNY_MGR_START_MULTICAST_MEDIA_RECEPT: return "Start multicast media reception"; case SKINNY_MGR_START_MULTICAST_MEDIA_TRANSMIT: return "Start multicast media transmission"; case SKINNY_MGR_STOP_MULTICAST_MEDIA_RECEPT: return "Stop multicast media reception"; case SKINNY_MGR_STOP_MULTICAST_MEDIA_TRANSMIT: return "Stop multicast media transmission"; case SKINNY_MGR_OPEN_RECV_CHANNEL: return "Open receive channel"; case SKINNY_MGR_CLOSE_RECV_CHANNEL: return "Close receive channel"; case SKINNY_MGR_CONNECTION_STATISTICS_REQ: return "Connection statistics request"; case SKINNY_MGR_SOFT_KEY_TEMPLATE_RESP: return "Soft key template respond"; case SKINNY_MGR_SOFT_KEY_SET_RESP: return "Soft key set respond"; case SKINNY_MGR_SELECT_SOFT_KEYS: return "Select soft keys"; case SKINNY_MGR_CALL_STATE: return "Call state"; case SKINNY_MGR_DISPLAY_PROMPT: return "Display prompt"; case SKINNY_MGR_CLEAR_PROMPT: return "Clear prompt"; case SKINNY_MGR_DISPLAY_NOTIFY: return "Display notify"; case SKINNY_MGR_CLEAR_NOTIFY: return "Clear notify"; case SKINNY_MGR_ACTIVATE_CALL_PLANE: return "Activate call plane"; case SKINNY_MGR_DEACTIVATE_CALL_PLANE: return "Deactivate call plane"; case SKINNY_MGR_UNREGISTER_ACK: return "Unregister ack"; case SKINNY_MGR_BACK_SPACE_REQ: return "Back space request"; case SKINNY_MGR_REGISTER_TOKEN_ACK: return "Register token ack"; case SKINNY_MGR_REGISTER_TOKEN_REJECT: return "Register token reject"; case SKINNY_MGR_START_MEDIA_FAILURE_DETECTION: return "Start media failure detection"; case SKINNY_MGR_DIALED_NUMBER: return "Dialed number"; case SKINNY_MGR_USER_TO_DEVICE_DATA: return "User to device data"; case SKINNY_MGR_FEATURE_STAT: return "Feature stat"; case SKINNY_MGR_DISPLAY_PRI_NOTIFY: return "Display pri notify"; case SKINNY_MGR_CLEAR_PRI_NOTIFY: return "Clear pri notify"; case SKINNY_MGR_START_ANNOUNCE: return "Start announce"; case SKINNY_MGR_STOP_ANNOUNCE: return "Stop announce"; case SKINNY_MGR_ANNOUNCE_FINISH: return "Announce finish"; case SKINNY_MGR_NOTIFY_DTMF_TONE: return "Notify dtmf tone"; case SKINNY_MGR_SEND_DTMF_TONE: return "Send dtmf tone"; case SKINNY_MGR_SUBSCRIBE_DTMF_PAYLOAD_REQ: return "Subscribe dtmf payload request"; case SKINNY_MGR_SUBSCRIBE_DTMF_PAYLOAD_RES: return "Subscribe dtmf payload res"; case SKINNY_MGR_SUBSCRIBE_DTMF_PAYLOAD_ERR: return "Subscribe dtmf payload err"; case SKINNY_MGR_UNSUBSCRIBE_DTMF_PAYLOAD_REQ: return "Unsubscribe dtmf payload request"; case SKINNY_MGR_UNSUBSCRIBE_DTMF_PAYLOAD_RES: return "Unsubscribe dtmf payload res"; case SKINNY_MGR_UNSUBSCRIBE_DTMF_PAYLOAD_ERR: return "Unsubscribe dtmf payload err"; case SKINNY_MGR_SERVICE_URLSTAT: return "Service urlstat"; case SKINNY_MGR_CALL_SELECT_STAT: return "Call select stat"; case SKINNY_MGR_OPEN_MULTIMEDIA_CHANNEL: return "Open multimedia channel"; case SKINNY_MGR_START_MULTIMEDIA_TRANSMIT: return "Start multimedia transmit"; case SKINNY_MGR_STOP_MULTIMEDIA_TRANSMIT: return "Stop multimedia transmit"; case SKINNY_MGR_MISCELLANEOUS_COMMAND: return "Miscellaneous command"; case SKINNY_MGR_FLOW_CONTROL_COMMAND: return "Flow control command"; case SKINNY_MGR_CLOSE_MULTIMEDIA_RECV_CHANNEL: return "Close multimedia receive channel"; case SKINNY_MGR_CREATE_CONFERENCE_REQ: return "Create conference request"; case SKINNY_MGR_DELETE_CONFERENCE_REQ: return "Delete conference request"; case SKINNY_MGR_MODIFY_CONFERENCE_REQ: return "Modify conference request"; case SKINNY_MGR_ADD_PARTICIPANT_REQ: return "Add participant request"; case SKINNY_MGR_DROP_PARTICIPANT_REQ: return "Drop participant request"; case SKINNY_MGR_AUDIT_CONFERENCE_REQ: return "Audit conference request"; case SKINNY_MGR_AUDIT_PARTICIPANT_REQ: return "Audit participant request"; case SKINNY_MGR_USER_TO_DEVICE_DATA_VERSION1: return "User to device data version1"; case SKINNY_MGR_CALL_INFO: return "Call info"; case SKINNY_MGR_DIALED_PHONE_BOOK_ACK: return "Dialed phone book ack"; case SKINNY_MGR_XMLALARM: return "Xmlalarm"; } return tempstr_printf("Unknown msgid 0x%X", id); }
static char const *smp_header_2_str(struct smp_header *header) { return tempstr_printf("Flags: %s Sid: %"PRIu16", Length: %"PRIu32", Seqnum: %"PRIu32", Window: %"PRIu32, smp_flags_2_str(header->flags), header->sid, header->length, header->seq_num, header->window); }
char const *rpc_info_2_str(struct proto_info const *info_) { struct rpc_proto_info const *info = DOWNCAST(info_, info, rpc_proto_info); return tempstr_printf("type: %s, %s", msg_type_2_str(info->msg_type), info->msg_type == RPC_CALL ? call_msg_2_str(&info->u.call_msg) : reply_msg_2_str(&info->u.reply_msg) ); }
static char const *reply_msg_2_str(struct reply_msg const *reply_msg) { return tempstr_printf("reply status : %s", reply_status_2_str(reply_msg->reply_status)); }
static char const *call_msg_2_str(struct call_msg const *call_msg) { return tempstr_printf("rpc version: %"PRIu32", program: %"PRIu32", program version: %"PRIu32", procedure: %"PRIu32, call_msg->rpc_version, call_msg->program, call_msg->program_version, call_msg->procedure); }
static char const *version_info_2_str(struct sql_proto_info const *info) { if (! (info->set_values & SQL_VERSION)) return ""; return tempstr_printf(", version=%u.%u", info->version_maj, info->version_min); }
static int opt_read(char const *opt) { return ext_eval(tempstr_printf("(open-pcap \"%s\")", opt)); }
static char const *mutex_name(struct mutex const *mutex) { return tempstr_printf("%s@%p", mutex->name, mutex); }
static char const *mgcp_resp_2_str(struct mgcp_resp const *resp) { char *str = tempstr_printf("code=%u, txid=%"PRI_MGCP_TXID, resp->code, resp->txid); return str; }
static char const *mgcp_query_2_str(struct mgcp_query const *query) { return tempstr_printf("command=%s, txid=%"PRI_MGCP_TXID", endpoint=%s", mgcp_command_2_str(query->command), query->txid, query->endpoint); }
// FIXME: a unsigned_if_set_2_str(info, set_mask, field_name, field_value) to replace various -1 for unset ints. static char const *startup_reply_2_str(struct sql_proto_info const *info) { return tempstr_printf(", %s", info->set_values & SQL_SSL_REQUEST ? sql_ssl_2_str(info->u.startup.ssl_request) : "No SSL"); }