[asterisk-dev] [Code Review]: Prevent manager show commands cutting off the command name in favor of other, less important information.

David Lee reviewboard at asterisk.org
Tue Oct 9 12:13:53 CDT 2012



> On Oct. 4, 2012, 11:37 a.m., David Lee wrote:
> > /trunk/main/manager.c, line 1818
> > <https://reviewboard.asterisk.org/r/2143/diff/2/?file=31722#file31722line1818>
> >
> >     I hate magic numbers. Shouldn't we define a MAX_LINE_LENGTH constant, or something like that? And 85 seems rather arbitrary. A more typical value would be more like 80, 100 or 120.
> 
> jrose wrote:
>     I explained the choice of 85 in the description, and yeah, it's definitely a little arbitrary (because it already was arbitrary). I'm reluctant to add a MAX_LINE_LENGTH definition since I would think it would have been in cli.h a long time ago if there weren't some compelling reason against it.
>     
>     It would be nicer if there was a way to get the width of the terminal, but I don't know for sure if that can be done reliably without relying on libraries like ncurses, which is probably unacceptable.
> 
> Matt Jordan wrote:
>     You can #define the maximum display length in manager.c.  It doesn't have to be in a header file.  The point of not having magic numbers is that no one has to guess what the intent of the number is, not that its globally defined for consumption by every unit that prints to a terminal (although that consistency would be a nice thing to have).
> 
> Tilghman Lesher wrote:
>     Both curses and ncurses define the integer variable COLS, and curses is part of the POSIX specification SUSv2 (1997), which we've previously said is a reasonable requirement to compile Asterisk.
>     
>     Once you've included <curses.h> or <ncurses.h>, you can simply reference the integer COLS (it's an int variable).  The variable is additionally updated when the process receives a SIGWINCH, so you should continue to use the variable in calculations, rather than attempting to cache it from startup.
>     
>     Source:  http://pubs.opengroup.org/onlinepubs/7908799/xcurses/curses.h.html
> 
> jrose wrote:
>     Thanks Tilghman, that sounds like the way to go then.
> 
> jrose wrote:
>     I've started checking on including curses, and some of the variables in term.h have conflicts with stuff from curses unfortunately. Also after talking with Matt, we might not be so keen on requiring curses for compilation.  It's something worth looking into later, but for now it would require more sweeping changes across Asterisk and should probably be included as part of a larger effort to get our CLI commands to follow have a method of checking terminal width while printing output. I'm planning to file an issue for that shortly.
>     
>     It's still necessary to fix the name problem here in the meantime, so I'll follow Matt's advice of using a #define within manager.c.
>     
>     One thing I'm not particularly fond of right now is that if the synopsis exceeds the allowable space it just cuts off abruptly without any indication that the synopsis isn't complete. I've thought a little about copying the synopsis string into a buffer to do handle this, but without a standard way to indicate that text is trunctated, I don't really know what to do about that. It's probably not worth bothering with at this time.
> 
> Tilghman Lesher wrote:
>     I just copied the following 6 lines from main/editline/term.c into main/manager.c:
>     
>     #ifdef HAVE_CURSES_H
>     #include <curses.h>
>     #endif
>     #ifdef HAVE_NCURSES_H
>     #include <ncurses.h>
>     #endif
>     
>     Compiled fine, no conflicts.  It's worth noting that we already do this check in configure.ac and we already use the capability, if available.
> 
> jrose wrote:
>     Oh, I see now. I made the mistake of putting my inclusion of curses before term.h and it caused the color definitions in terminal to conflict.
>     
>     Alright, I'll finish this up. I'll still go ahead and file an issue to apply this concept in a more sweeping way to CLI output though.

>jrose said:
> It's probably not worth bothering with at this time.

Agreed.


- David


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/2143/#review7219
-----------------------------------------------------------


On Oct. 9, 2012, 11:06 a.m., jrose wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/2143/
> -----------------------------------------------------------
> 
> (Updated Oct. 9, 2012, 11:06 a.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> First, this patch cuts out information about the required authorization level.  There is really no need for it here and this information is freely avaialble with the 'manager show command [command]' information.
> 
> Second, the size field for the name is now picked based on the size of the largest command name. Any remaining space (out of 85, based on the sum of all previous fields, though I could add 2 since I removed some spaces as well and still be length neutral) will be given to the description.
> 
> 
> This addresses bug ASTERISK-20396.
>     https://issues.asterisk.org/jira/browse/ASTERISK-20396
> 
> 
> Diffs
> -----
> 
>   /trunk/CHANGES 374334 
>   /trunk/main/manager.c 374334 
> 
> Diff: https://reviewboard.asterisk.org/r/2143/diff
> 
> 
> Testing
> -------
> 
> I used the command. It did what I thought it would. Seems pretty simplish.
> 
> Old output:
>   Action           Privilege        Synopsis                                               
>   ------           ---------        --------                                               
>   [...]           
>   StopMixMonitor   <none>           Stop recording a call through MixMonitor, and free the 
>   MixMonitor       <none>           Record a call and mix the audio during the recording.  
>   MixMonitorMute   <none>           Mute / unMute a Mixmonitor recording.                  
>   ConfbridgeSetSi  call,all         Set a conference user as the single video source distri
>   [...]
> 
> New output:
> 
> *CLI> manager show commands
>   Action                       Synopsis                                                  
>   ------                       --------                                                  
>   [...]
>   StopMixMonitor               Stop recording a call through MixMonitor, and free the rec
>   MixMonitor                   Record a call and mix the audio during the recording.  Use
>   MixMonitorMute               Mute / unMute a Mixmonitor recording.                     
>   ConfbridgeSetSingleVideoSrc  Set a conference user as the single video source distribut
>   [...]
> 
> 
> Thanks,
> 
> jrose
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20121009/a05098ab/attachment-0001.htm>


More information about the asterisk-dev mailing list