Re: Submitting a patch to Kannel: best practices?

David McCann <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi Nikos--

Thank you for the promt reply!  I completely agree that this makes more
sense as a bearerbox, admin command.  I initially added it as such, but then
realized that in fact, all the translations logic sat within the smsbox
process, rather than the bearerbox.  Adding it directly as an smsbox command
removes any need for any communication between the bearerbox and the smsbox.

But I agree it still feels like a hack, in terms of where a user would
expect to send a command such as "refresh list."  If you could point me to a
pattern in the code where the bearerbox communicates with the smsbox in a
similar fashion, it'd be a huge help and I'd be happy to re-submit my patch
with it working in that manner.  The current diff is still attached to the
feature request, but I've attached it here as well (currently in two
patches, src and doc) just for review, as we discuss this alternate
approach.

In regards to your comment about bearerbox handling this on the fly through
its admin HTTP interface...I'm not quite sure I follow?  I know this
service-level refreshing functionality doesn't currently exist, are you just
referring to similar functionality that exists in bearerbox?  Forgive my
confusion.

Thanks again,
--dm


On Fri, Dec 17, 2010 at 1:07 PM, Nikos Balkanas <[email protected]> wrote:

> Hi,
>
> Usually people just post the patch to the devel list with subject: Patch:
> <filename>. Patch is attached as a diff of the file(s) from latest svn
> sources, followed by a brief description in the body.
>
> Wrt to your proposed solution, I am not very much in favor. In bearerbox
> this is handle on the fly through its admin HTTP interface. I think a
> similar approach would be best for smsbox.
>
> BR,
> Nikos
>
> On Fri, Dec 17, 2010 at 8:10 AM, David McCann <[email protected]>wrote:
>
>> Greetings all!
>>
>> I've been a kannel user for years, but within the past week I've just
>> started to work directly with the code.  I had a particular need which I
>> couldn't find a good workaround for:
>>
>> My current deployment with kannel uses whitelisting to dispatch messages
>> to various running web applications (at the sms-service group level),
>> however users do update their contact information from time to time, meaning
>> the whitelist needs to updated, preferrably without the smsbox having to be
>> restarted entirely.
>>
>> I've added a new command to the list of available commands for SMSBox,
>> namely /cgi-bin/refreshlist, and (maybe a little overzealously) created an
>> issue: https://redmine.kannel.org/issues/584
>>
>> And submitted my patch there.
>>
>> Given that I'm pretty new to this community, I'm wondering if anyone can
>> advise me on the best/most convenient way to submit a patch for
>> incorporation into the code?
>>
>> Thanks in advance,
>> David McCann
>> T4D, UNICEF Uganda
>>
>>
>
kannel-docs.patch (text/x-patch, 3.8 KB)
diff -r gateway-1.4.3-patch/doc/userguide/userguide.xml gateway-1.4.3-docpatch/doc/userguide/userguide.xml
5310a5311,5317
> 	 <row><entry><literal>refresh-list-url (o)</literal></entry>
>      <entry>url</entry>
>      <entry valign="bottom">
> 	     URL locating the refreshlist service. Defaults to <literal>
>         /cgi-bin/refreshlist</literal>.
>      </entry></row>
> 
5698c5705
<         Optional name to identify the service in logs. If unset,
---
>         Optional name to identify the service in logs (and for refreshing whitelists and blacklists of services). If unset,
7622a7630,7714
> <sect2>
> <title>Using the HTTP interface to Refresh sms-service whitelists and blacklists</title>
> 
> 	<para>After you have configured Kannel to allow the refreshlist
> 	service, you can refresh service whitelists and blacklists via HTTP, 
>         e.g., using a WWW browser. The URL looks something like this:
> 	
> <programlisting>
> http://smsbox.host.name:13013/cgi-bin/refreshlist?
> username=foo&amp;password=bar&amp;name=myservice
> </programlisting>
> 
>         Thus, technically,
> 	you make an HTTP GET request. This means that all the information
> 	is stuffed into the URL. If you want to use this often via a
> 	browser, you probably want to make an HTML form for this.</para>
> 
>   <para>
>      Kannel will answer to sendsms request with following codes and
>      body texts:</para>
>   
>  <table frame="none">
>   <title>SMS Refresh list reply codes</title>
>       <tgroup cols="3"><thead><row>
>              <entry>Status</entry>
>              <entry>Body</entry>
>              <entry>Meaning</entry>
>              </row></thead>
>   <tbody>
>    <row><entry><literal>200</literal></entry>
>    <entry><literal>0: Successful refresh</literal></entry>
>    <entry valign="bottom">
> 	The service name was valid and a successful refresh of the 
>         corresponding white list or black list occurred.
>    </entry></row>
>    <row><entry><literal>4xx</literal></entry>
>    <entry>(varies)</entry>
>    <entry valign="bottom">
> 	The service name was not provided, or the user authentication failed.
>    </entry></row>
>    <row><entry><literal>503</literal></entry>
>    <entry><literal>Temporal failure, try again later.</literal></entry>
>    <entry valign="bottom">
>         There was temporal failure in retrieving the white list or black list
>         from the configured url for the sms-service.  Could indicate the application serving the list
>         is down or had its own internal failure.
>    </entry></row>
> 
>   </tbody>
>   </tgroup>
>  </table>
> 
> 
>  <table frame="none">
>   <title>Refresh List (refreshlist) CGI Variables</title>
>   <tgroup cols="3">
>   <tbody>
>    <row><entry><literal>username</literal> (or <literal>user</literal>)</entry>
>    <entry><literal>string</literal></entry>
>    <entry valign="bottom">
>         Username or account name. Must be <literal>username</literal> of the one
>         'sendsms-user' group in the Kannel configuration,
>         or results in 'Authorization failed' reply.
>    </entry></row>
> 
>    <row><entry><literal>password</literal> (or <literal>pass</literal>)</entry>
>    <entry><literal>string</literal></entry>
>    <entry valign="bottom">
>        Password associated with given <literal>username</literal>. Must match
>  corresponding field in the 'sendsms-user' group of
> the Kannel configuration, or 'Authorization failed' is returned.
>    </entry></row>
> 
>    <row><entry><literal>name</literal></entry>
>    <entry><literal>string</literal></entry>
>    <entry valign="bottom">
>         The name of the service for which lists should be refreshed, as specified in the
>         <literal>sms-service</literal> block by the configuration option <literal>name</literal>.
>    </entry></row>
> 
>   </tbody>
>   </tgroup>
>  </table>
> 
> </sect2>
7624a7717,7718
> 
>
kannel.patch (text/x-patch, 4 KB)
diff -r gateway-1.4.3/config.log gateway-1.4.3-patch/config.log
1212a1213
> config.status:1040: gw-config.h is unchanged
diff -r gateway-1.4.3/config.status gateway-1.4.3-patch/config.status
361c361
< ac_pwd='/home/david/Projects/Kannel/gateway-1.4.3'
---
> ac_pwd='/home/david/Projects/Kannel/gateway-1.4.3-patch'
diff -r gateway-1.4.3/gw/smsbox.c gateway-1.4.3-patch/gw/smsbox.c
108a109
> static Octstr *refreshlist_url = NULL;
2467a2469,2500
> static Octstr *smsbox_refresh_service(List *args, Octstr *client_ip, int *status,
>                                       HTTPClient *client)
> {
>     URLTranslation *t;
>     Octstr *name;
> 
>     /* check the username and password */
>     t = authorise_user(args, client_ip);
>     if (t == NULL) {
> 	*status = HTTP_FORBIDDEN;
> 	return octstr_create("Authorization failed for sendsms");
>     }
>     
>     name = http_cgi_variable(args, "name");
>     if (name == NULL) {
> 	error(0, "%s got insufficient headers (<name> is NULL)",
> 	      octstr_get_cstr(sendsms_url));
> 	*status = HTTP_BAD_REQUEST;
> 	return octstr_create("Missing service name, rejected");
>     }
> 
>     if (urltrans_refresh_service_lists(translations, name) == -1) {
>         error(0, "An error occurred while trying to refresh list for %s",
>               octstr_get_cstr(name));
> 	*status = HTTP_INTERNAL_SERVER_ERROR;
>         return octstr_create("Refreshing service list failed");
>     }
>     else {
>         *status = HTTP_OK;
>         return octstr_create("Lists for service successfully refreshed");
>     }
> }
3204a3238,3251
>     /* refresh service-level white and black lists */
>     else if (octstr_compare(url, refreshlist_url) == 0)
>     {
> 	/* 
> 	 * decide if this is a GET or POST request,
>          * currently only GET requests are supported
> 	 */
> 	if (body == NULL)
> 	    answer = smsbox_refresh_service(args, ip, &status, client);
> 	else {
> 	    answer = octstr_create("Only GET request for refresh list are supported.");
>             status = HTTP_BAD_REQUEST;
>         }
>     }
3449a3497,3498
>     if ((refreshlist_url = cfg_get(grp, octstr_imm("refresh-list-url"))) == NULL)
>         refreshlist_url = octstr_imm("/cgi-bin/refreshlist");
3640a3690
>     octstr_destroy(refreshlist_url);
diff -r gateway-1.4.3/gw/urltrans.c gateway-1.4.3-patch/gw/urltrans.c
76c76
< /***********************************************************************
---
> /***************************************nu********************************
116a117,119
>     Octstr *white_list_url; /* url to retreive the white list from */
>                             /* stored so that it can be refreshed on-demand */
>     Octstr *black_list_url; /* url to retreive the black list from */
249a253,273
> int urltrans_refresh_service_lists(URLTranslationList *trans, Octstr *name) {
>     List *list;
>     URLTranslation *ot;
>     int retval = -1;
> 
>     list = dict_get(trans->names, name);
>     while (list && (ot = gwlist_extract_first(list)) != NULL) {
>       if (ot->type != TRANSTYPE_SENDSMS) {
>         if (ot->white_list_url != NULL) {
>             ot->white_list = numhash_create(octstr_get_cstr(ot->white_list_url));
>             retval = 0;
>         }
>         if (ot->black_list_url != NULL) {
>             ot->black_list = numhash_create(octstr_get_cstr(ot->black_list_url));
>             retval = 0;
>         }
>       }
>     }
>     return retval;
> }
> 
1104a1129
>         ot->white_list_url = octstr_duplicate(os);
1116a1142
>         ot->black_list_url = octstr_duplicate(os);
1189a1216,1217
> 	octstr_destroy(ot->white_list_url);
> 	octstr_destroy(ot->black_list_url);
diff -r gateway-1.4.3/gw/urltrans.h gateway-1.4.3-patch/gw/urltrans.h
174a175,180
> /* Refresh the white list and black lists for a particular sms service,
>  * if specified in the config file by urls.
>  * returns 0 if everything goes according to plan, -1 otherwise
>  */
> int urltrans_refresh_service_lists(URLTranslationList *trans, Octstr *name);
> 
diff -r gateway-1.4.3/gwlib/cfg.def gateway-1.4.3-patch/gwlib/cfg.def
258a259
>     OCTSTR(refresh-list-url)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.