MayamaTakeshi / sip-lab

A node module that helps to write SIP functional tests
3 stars 2 forks source link

Implement processing of parameters as JSON string #16

Closed MayamaTakeshi closed 1 year ago

MayamaTakeshi commented 1 year ago

Rationale:

Some new commands like start_fax will require a multitude of options. Also, the way we set SIP headers in messages is not very good (single parameter as a string with headers separated with ‘\n’) So let’s use JSON to send parameters to the underlying pj controlling code.

This will simplify updating the interface with javascript: basically at javascript side each method should require only the entity id (call_id, account_id, transport_id etc) and an object with parameters. So we would not need to update those interfaces anymore and all non-object-creation methods would be like this:

  call.start_play_wav(call_id, params)
  call.start_fax(call_id, params)
  call.reivinte(call_id, params)
  account.register(acc_id, params)

We would stringify the params object and pass it as a string parameter to the methods. Then at the c side we would just need to parse the string using some library like rapidjson. Obs: note that we could use NAPI to interface passing the object data. However, we might eventually need to reuse the core c code in another project/language and so it is better have the processing of JSON at the core.

JSON libraries to check: https://rapidjson.org/ https://github.com/Tencent/rapidjson/blob/master/example/simplereader/simplereader.cpp

https://zserge.com/jsmn/

https://gitee.com/xuzd/cJSON

https://github.com/skeeto/pdjson

https://jansson.readthedocs.io/