I want to read sip.conf from asterisk server path, modify the file from a C++ application.
eg., ofstream("/usr/local/data/etc/asterisk,sip.conf,XXX) … Like this.
May I know is it possible ? Any other ways are highly appreciated
Thanks in Advance
Related to read and modify a file with C++ I assume is possible, because I have done it with Python and PHP so don’t see the reason why it can’t be done with C++. If I want to modify programmatically Asterisk configuration, I prefer to use Real-time architecture. Also be aware chan_sip is community supported now
Could you please provide me an example for #exec - modify the sip.conf from the path /usr/local/data/etc/asterisk/ ? The exampe provided in the link #exec /opt/bin/build-extra-contexts.sh --foo=“bar”
not understandable
The first thing is to understand that this is not intended to modify the configuration file that contains the #exec. It is to execute some script or program, capture the output (STDOUT) from the script/program, and include it in place of the ‘#exec’ line when the configuration file is reloaded.
For example, if you wanted to create a custom endpoint based on the host name and the current date (a contrived, useless example), you could add to pjsip.conf:
#exec add-this-host-as-endpoint.sh
Where add-this-host-as-endpoint.sh could be something like:
#!/bin/bash
# add this host as a custom endpoint
# define variables
custom_hostname=${HOSTNAME%%.*}-$(date +%F)
# output the endpoint definition
(
printf '[%s]\n' ${custom_hostname}
printf '\t type\t\t\t\t= endpoint\n'
printf '\tallow\t\t\t\t= !all,ulaw\n'
printf '\taors\t\t\t\t= %s\n' ${custom_hostname}
printf '\tcontext\t\t\t\t= start\n'
printf '\toutbound_auth\t\t\t= %s\n' ${custom_hostname}
)
# (end of add-this-host-as-endpoint.sh)
The owner, group, and permissions were the bits I was interested in, but based on your answers to 3 & 4 it may be moot.
I’m confused. Are you trying to modify a file on a Linux host from a Windows host? Is there a shared filesystem between the 2 hosts?
If you are going to execute your program as root, is there still a problem? If you are going to execute your program as another user, it’s a matter of owner/group/permissions that you need to work out.