@@ -732,6 +732,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons
732732 struct ng_buffer * * ngbufp )
733733{
734734 str cmd = STR_NULL ;
735+ const struct ng_command_def * cmd_def ;
735736 const char * errstr , * resultstr ;
736737 GString * log_str ;
737738 int64_t cmd_start , cmd_stop , cmd_process_time = {0 };
@@ -817,144 +818,32 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons
817818 // start command timer
818819 cmd_start = now_us ();
819820
820- switch (__csh_lookup (& cmd )) {
821- case CSH_LOOKUP ("ping" ):
822- resultstr = "pong" ;
823- command_ctx .opmode = OP_PING ;
824- break ;
825- case CSH_LOOKUP ("offer" ):
826- command_ctx .opmode = OP_OFFER ;
827- errstr = call_offer_ng (& command_ctx , addr );
828- break ;
829- case CSH_LOOKUP ("answer" ):
830- command_ctx .opmode = OP_ANSWER ;
831- errstr = call_answer_ng (& command_ctx );
832- break ;
833- case CSH_LOOKUP ("delete" ):
834- command_ctx .opmode = OP_DELETE ;
835- errstr = call_delete_ng (& command_ctx );
836- break ;
837- case CSH_LOOKUP ("query" ):
838- command_ctx .opmode = OP_QUERY ;
839- errstr = call_query_ng (& command_ctx );
840- break ;
841- case CSH_LOOKUP ("list" ):
842- command_ctx .opmode = OP_LIST ;
843- errstr = call_list_ng (& command_ctx );
844- break ;
845- case CSH_LOOKUP ("start recording" ):
846- command_ctx .opmode = OP_START_RECORDING ;
847- errstr = call_start_recording_ng (& command_ctx );
848- break ;
849- case CSH_LOOKUP ("stop recording" ):
850- command_ctx .opmode = OP_STOP_RECORDING ;
851- errstr = call_stop_recording_ng (& command_ctx );
852- break ;
853- case CSH_LOOKUP ("pause recording" ):
854- command_ctx .opmode = OP_PAUSE_RECORDING ;
855- errstr = call_pause_recording_ng (& command_ctx );
856- break ;
857- case CSH_LOOKUP ("start forwarding" ):
858- command_ctx .opmode = OP_START_FORWARDING ;
859- errstr = call_start_forwarding_ng (& command_ctx );
860- break ;
861- case CSH_LOOKUP ("stop forwarding" ):
862- command_ctx .opmode = OP_STOP_FORWARDING ;
863- errstr = call_stop_forwarding_ng (& command_ctx );
864- break ;
865- case CSH_LOOKUP ("block DTMF" ):
866- command_ctx .opmode = OP_BLOCK_DTMF ;
867- errstr = call_block_dtmf_ng (& command_ctx );
868- break ;
869- case CSH_LOOKUP ("unblock DTMF" ):
870- command_ctx .opmode = OP_UNBLOCK_DTMF ;
871- errstr = call_unblock_dtmf_ng (& command_ctx );
872- break ;
873- case CSH_LOOKUP ("block media" ):
874- command_ctx .opmode = OP_BLOCK_MEDIA ;
875- errstr = call_block_media_ng (& command_ctx );
876- break ;
877- case CSH_LOOKUP ("unblock media" ):
878- command_ctx .opmode = OP_UNBLOCK_MEDIA ;
879- errstr = call_unblock_media_ng (& command_ctx );
880- break ;
881- case CSH_LOOKUP ("silence media" ):
882- command_ctx .opmode = OP_SILENCE_MEDIA ;
883- errstr = call_silence_media_ng (& command_ctx );
884- break ;
885- case CSH_LOOKUP ("unsilence media" ):
886- command_ctx .opmode = OP_UNSILENCE_MEDIA ;
887- errstr = call_unsilence_media_ng (& command_ctx );
888- break ;
889- case CSH_LOOKUP ("play media" ):
890- command_ctx .opmode = OP_PLAY_MEDIA ;
891- errstr = call_play_media_ng (& command_ctx );
892- break ;
893- case CSH_LOOKUP ("stop media" ):
894- command_ctx .opmode = OP_STOP_MEDIA ;
895- errstr = call_stop_media_ng (& command_ctx );
896- break ;
897- case CSH_LOOKUP ("play DTMF" ):
898- command_ctx .opmode = OP_PLAY_DTMF ;
899- errstr = call_play_dtmf_ng (& command_ctx );
900- break ;
901- case CSH_LOOKUP ("statistics" ):
902- command_ctx .opmode = OP_STATISTICS ;
903- errstr = statistics_ng (& command_ctx );
904- break ;
905- case CSH_LOOKUP ("publish" ):
906- command_ctx .opmode = OP_PUBLISH ;
907- errstr = call_publish_ng (& command_ctx , addr );
908- break ;
909- case CSH_LOOKUP ("subscribe request" ):
910- command_ctx .opmode = OP_SUBSCRIBE_REQ ;
911- errstr = call_subscribe_request_ng (& command_ctx );
912- break ;
913- case CSH_LOOKUP ("subscribe answer" ):
914- command_ctx .opmode = OP_SUBSCRIBE_ANS ;
915- errstr = call_subscribe_answer_ng (& command_ctx );
916- break ;
917- case CSH_LOOKUP ("unsubscribe" ):
918- command_ctx .opmode = OP_UNSUBSCRIBE ;
919- errstr = call_unsubscribe_ng (& command_ctx );
920- break ;
921- case CSH_LOOKUP ("inject start" ):
922- command_ctx .opmode = OP_INJECT_START ;
923- errstr = call_inject_start_ng (& command_ctx );
924- break ;
925- case CSH_LOOKUP ("inject stop" ):
926- command_ctx .opmode = OP_INJECT_STOP ;
927- errstr = call_inject_stop_ng (& command_ctx );
928- break ;
929- case CSH_LOOKUP ("connect" ):
930- command_ctx .opmode = OP_CONNECT ;
931- errstr = call_connect_ng (& command_ctx );
932- break ;
933- case CSH_LOOKUP ("cli" ):
934- case CSH_LOOKUP ("CLI" ):
935- command_ctx .opmode = OP_CLI ;
936- errstr = cli_ng (& command_ctx );
937- break ;
938- case CSH_LOOKUP ("transform" ):
939- command_ctx .opmode = OP_TRANSFORM ;
940- errstr = call_transform_ng (& command_ctx );
941- break ;
942- case CSH_LOOKUP ("create" ):
943- command_ctx .opmode = OP_CREATE ;
944- errstr = call_create_ng (& command_ctx );
945- break ;
946- case CSH_LOOKUP ("create answer" ):
947- command_ctx .opmode = OP_CREATE_ANSWER ;
948- errstr = call_create_answer_ng (& command_ctx );
949- break ;
950- case CSH_LOOKUP ("mesh" ):
951- command_ctx .opmode = OP_MESH ;
952- errstr = call_mesh_ng (& command_ctx );
953- break ;
954- default :
955- errstr = "Unrecognized command" ;
821+ command_ctx .opmode = OP_OTHER ;
822+ cmd_def = ng_command_find (& cmd );
823+
824+ /* undefined command */
825+ if (!cmd_def ) {
826+ errstr = "Unrecognized command" ;
827+ goto err_send ;
956828 }
957829
830+ /* No handler found */
831+ if (!cmd_def -> handler && !cmd_def -> addr_handler ) {
832+ errstr = "No command handler" ;
833+ goto err_send ;
834+ }
835+
836+ command_ctx .opmode = cmd_def -> opmode ;
837+ /* ping has special response string */
838+ if (cmd_def -> opmode == OP_PING )
839+ resultstr = "pong" ;
840+
841+ /* properly select the handler to be used (single-/double-parameter) */
842+ if (cmd_def -> addr_handler )
843+ errstr = cmd_def -> addr_handler (& command_ctx , addr );
844+ else
845+ errstr = cmd_def -> handler (& command_ctx );
846+
958847 CH (homer_fill_values , hctx , & callid , command_ctx .opmode );
959848 CH (homer_trace_msg_in , hctx , data );
960849
0 commit comments