Browse code

dialog: customizable list of fields for dlg.briefing rpc command

- it can take an optional parameter to specify what fields to be added
to response
- hash entry and id are added by default
- if the parameter is not give, then it also adds from-uri, to-uri,
call-id, from-tag and to-tag

Daniel-Constantin Mierla authored on 09/04/2020 07:29:24
Showing 1 changed files
... ...
@@ -3064,9 +3064,17 @@ static const char *rpc_dlg_briefing_doc[2] = {
3064 3064
  */
3065 3065
 static void rpc_dlg_briefing(rpc_t *rpc, void *c)
3066 3066
 {
3067
-	dlg_cell_t *dlg;
3068
-	unsigned int i;
3069
-	void *h;
3067
+	dlg_cell_t *dlg = NULL;
3068
+	unsigned int i = 0;
3069
+	int n = 0;
3070
+	str fmt = STR_NULL;
3071
+	void *h = NULL;
3072
+
3073
+	n = rpc->scan(c, "S", &fmt);
3074
+	if (n < 1) {
3075
+		fmt.s = "ftcFT";
3076
+		fmt.len = 5;
3077
+	}
3070 3078
 
3071 3079
 	for( i=0 ; i<d_table->size ; i++ ) {
3072 3080
 		dlg_lock( d_table, &(d_table->entries[i]) );
... ...
@@ -3075,22 +3083,81 @@ static void rpc_dlg_briefing(rpc_t *rpc, void *c)
3075 3083
 				rpc->fault(c, 500, "Failed to create the structure");
3076 3084
 				return;
3077 3085
 			}
3078
-			if(rpc->struct_add(h, "ddSSSSSdddd",
3086
+			if(rpc->struct_add(h, "dd",
3079 3087
 					"h_entry", dlg->h_entry,
3080
-					"h_id", dlg->h_id,
3081
-					"from_uri", &dlg->from_uri,
3082
-					"to_uri", &dlg->to_uri,
3083
-					"call-id", &dlg->callid,
3084
-					"from_tag", &dlg->tag[DLG_CALLER_LEG],
3085
-					"to_tag", &dlg->tag[DLG_CALLER_LEG],
3086
-					"init_ts", dlg->init_ts,
3087
-					"start_ts", dlg->start_ts,
3088
-					"end_ts", dlg->end_ts,
3089
-					"state", dlg->state) < 0) {
3088
+					"h_id", dlg->h_id) < 0) {
3090 3089
 				rpc->fault(c, 500, "Failed to add fields");
3091 3090
 				return;
3092 3091
 
3093 3092
 			}
3093
+			for(n=0; n<fmt.len; n++) {
3094
+				switch(fmt.s[n]) {
3095
+					case 'f':
3096
+						if(rpc->struct_add(h, "S",
3097
+									"from_uri", &dlg->from_uri) < 0) {
3098
+							rpc->fault(c, 500, "Failed to add fields");
3099
+							return;
3100
+						}
3101
+					break;
3102
+					case 't':
3103
+						if(rpc->struct_add(h, "S",
3104
+									"to_uri", &dlg->to_uri) < 0) {
3105
+							rpc->fault(c, 500, "Failed to add fields");
3106
+							return;
3107
+						}
3108
+					break;
3109
+					case 'c':
3110
+						if(rpc->struct_add(h, "S",
3111
+									"call-id", &dlg->callid) < 0) {
3112
+							rpc->fault(c, 500, "Failed to add fields");
3113
+							return;
3114
+						}
3115
+					break;
3116
+					case 'F':
3117
+						if(rpc->struct_add(h, "S",
3118
+									"from_tag", &dlg->tag[DLG_CALLER_LEG]) < 0) {
3119
+							rpc->fault(c, 500, "Failed to add fields");
3120
+							return;
3121
+						}
3122
+					break;
3123
+					case 'T':
3124
+						if(rpc->struct_add(h, "S",
3125
+									"to_tag", &dlg->tag[DLG_CALLER_LEG]) < 0) {
3126
+							rpc->fault(c, 500, "Failed to add fields");
3127
+							return;
3128
+						}
3129
+					break;
3130
+					case 'I':
3131
+						if(rpc->struct_add(h, "d",
3132
+									"init_ts", dlg->init_ts) < 0) {
3133
+							rpc->fault(c, 500, "Failed to add fields");
3134
+							return;
3135
+						}
3136
+					break;
3137
+					case 'S':
3138
+						if(rpc->struct_add(h, "d",
3139
+									"start_ts", dlg->start_ts) < 0) {
3140
+							rpc->fault(c, 500, "Failed to add fields");
3141
+							return;
3142
+						}
3143
+					break;
3144
+					case 'E':
3145
+						if(rpc->struct_add(h, "d",
3146
+									"end_ts", dlg->end_ts) < 0) {
3147
+							rpc->fault(c, 500, "Failed to add fields");
3148
+							return;
3149
+						}
3150
+					break;
3151
+					case 's':
3152
+						if(rpc->struct_add(h, "d",
3153
+									"state", dlg->state) < 0) {
3154
+							rpc->fault(c, 500, "Failed to add fields");
3155
+							return;
3156
+						}
3157
+					break;
3158
+				}
3159
+			}
3160
+
3094 3161
 		}
3095 3162
 		dlg_unlock( d_table, &(d_table->entries[i]) );
3096 3163
 	}