source: variable.c @ a4ae221

release-1.10release-1.9
Last change on this file since a4ae221 was f271129, checked in by Jason Gross <jgross@mit.edu>, 13 years ago
Fix up headers The additions to owl.h and some of the removals were done by Alejandro Sedeño <asedeno@mit.edu> in commit 77a0258b3919468fc9d7f7602588ac427ab36e6c. Notes: * I think owl.c lost the need for sys/time.h when we punted select() in favor of glib's main loop. * We don't actually need to include things like stdarg.h, stdio.h, glib/gstdio.h, glib-object.h. I think they get indirectly included via owl.h and/or glib.h. They're left in (or added in to) the files that use functions/types from them. * I'm not entirely sure what sys/socket.h is doing in message.c. It is there from the initial commit. I suspect it might have had something to do with the call to getnameinfo. message.c compiles without it, but http://pubs.opengroup.org/onlinepubs/009695399/functions/getnameinfo.html suggests that we're supposed to include it? *shrugs* I'm leaving it in, for now. (Rather, I'll leave one copy of the #include in.)
  • Property mode set to 100644
File size: 41.8 KB
RevLine 
[7d4fbcd]1#include "owl.h"
[f271129]2#include <stdio.h>
[7d4fbcd]3
[aa2f33b3]4#define OWLVAR_BOOL(name,default,summary,description) \
[9efc154]5        { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, "on,off", g_strdup(summary), g_strdup(description), NULL, \
[c1d9441]6        NULL, NULL, NULL, NULL, NULL, NULL }
[7d4fbcd]7
[aa2f33b3]8#define OWLVAR_BOOL_FULL(name,default,summary,description,validate,set,get) \
[9efc154]9        { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, "on,off", g_strdup(summary), g_strdup(description), NULL, \
[c1d9441]10        validate, set, NULL, get, NULL, NULL }
[7d4fbcd]11
[aa2f33b3]12#define OWLVAR_INT(name,default,summary,description) \
[9efc154]13        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, "<int>", g_strdup(summary), g_strdup(description), NULL, \
[7d4fbcd]14        NULL, NULL, NULL, NULL, NULL, NULL }
15
[aa2f33b3]16#define OWLVAR_INT_FULL(name,default,summary,description,validset,validate,set,get) \
[9efc154]17        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \
[7d4fbcd]18        validate, set, NULL, get, NULL, NULL }
19
[aa2f33b3]20#define OWLVAR_PATH(name,default,summary,description) \
[9efc154]21        { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, "<path>", g_strdup(summary), g_strdup(description),  NULL, \
[7d4fbcd]22        NULL, NULL, NULL, NULL, NULL, NULL }
23
[aa2f33b3]24#define OWLVAR_STRING(name,default,summary,description) \
[9efc154]25        { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, "<string>", g_strdup(summary), g_strdup(description), NULL, \
[7d4fbcd]26        NULL, NULL, NULL, NULL, NULL, NULL }
27
[f203cad]28#define OWLVAR_STRING_FULL(name,default,validset,summary,description,validate,set,get) \
[9efc154]29        { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, validset, g_strdup(summary), g_strdup(description), NULL, \
[c01e477]30        validate, set, NULL, get, NULL, NULL }
31
[7d4fbcd]32/* enums are really integers, but where validset is a comma-separated
33 * list of strings which can be specified.  The tokens, starting at 0,
34 * correspond to the values that may be specified. */
[aa2f33b3]35#define OWLVAR_ENUM(name,default,summary,description,validset) \
[9efc154]36        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \
[7d4fbcd]37        owl_variable_enum_validate, \
38        NULL, owl_variable_enum_set_fromstring, \
39        NULL, owl_variable_enum_get_tostring, \
40        NULL }
41
[aa2f33b3]42#define OWLVAR_ENUM_FULL(name,default,summary,description,validset,validate, set, get) \
[9efc154]43        { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \
[217a43e]44        validate, \
45        set, owl_variable_enum_set_fromstring, \
46        get, owl_variable_enum_get_tostring, \
47        NULL }
48
[9e86f6f]49int owl_variable_add_defaults(owl_vardict *vd)
50{
51  owl_variable variables_to_init[] = {
[7d4fbcd]52
[5d365f6]53  OWLVAR_STRING( "personalbell" /* %OwlVarStub */, "off",
[213a3eb]54                 "ring the terminal bell when personal messages are received",
[5d365f6]55                 "Can be set to 'on', 'off', or the name of a filter which\n"
56                 "messages need to match in order to ring the bell"),
[7d4fbcd]57
58  OWLVAR_BOOL( "bell" /* %OwlVarStub */, 1,
[aa2f33b3]59               "enable / disable the terminal bell", "" ),
[7d4fbcd]60
61  OWLVAR_BOOL_FULL( "debug" /* %OwlVarStub */, OWL_DEBUG,
62                    "whether debugging is enabled",
[aa2f33b3]63                    "If set to 'on', debugging messages are logged to the\n"
64                    "file specified by the debugfile variable.\n",
[7d4fbcd]65                    NULL, owl_variable_debug_set, NULL),
66
67  OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1,
[a16d7e5]68               "send a login message when BarnOwl starts", "" ),
[7d4fbcd]69
70  OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1,
[a16d7e5]71               "send a logout message when BarnOwl exits", "" ),
[7d4fbcd]72
73  OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0,
[aa2f33b3]74               "display received pings", "" ),
[7d4fbcd]75
76  OWLVAR_BOOL( "txping" /* %OwlVarStub */, 1,
[aa2f33b3]77               "send pings", "" ),
[7d4fbcd]78
[73624b4]79  OWLVAR_BOOL( "sepbar_disable" /* %OwlVarStub */, 0,
[451db9e]80               "disable printing information in the separator bar", "" ),
[73624b4]81
[f9c43ae]82  OWLVAR_BOOL( "smartstrip" /* %OwlVarStub */, 1,
83               "strip kerberos instance for reply", ""),
84
[7e3e00a]85  OWLVAR_BOOL( "newlinestrip" /* %OwlVarStub */, 1,
86               "strip leading and trailing newlines", ""),
87
[7d4fbcd]88  OWLVAR_BOOL( "displayoutgoing" /* %OwlVarStub */, 1,
[aa2f33b3]89               "display outgoing messages", "" ),
[7d4fbcd]90
91  OWLVAR_BOOL( "loginsubs" /* %OwlVarStub */, 1,
[aa2f33b3]92               "load logins from .anyone on startup", "" ),
[7d4fbcd]93
94  OWLVAR_BOOL( "logging" /* %OwlVarStub */, 0,
[aa2f33b3]95               "turn personal logging on or off", 
96               "If this is set to on, personal messages are\n"
97               "logged in the directory specified\n"
98               "by the 'logpath' variable.  The filename in that\n"
99               "directory is derived from the sender of the message.\n" ),
[7d4fbcd]100
101  OWLVAR_BOOL( "classlogging" /* %OwlVarStub */, 0,
[aa2f33b3]102               "turn class logging on or off",
103               "If this is set to on, class messages are\n"
104               "logged in the directory specified\n"
105               "by the 'classlogpath' variable.\n" 
106               "The filename in that directory is derived from\n"
107               "the name of the class to which the message was sent.\n" ),
[7d4fbcd]108
[12c35df]109  OWLVAR_ENUM( "loggingdirection" /* %OwlVarStub */, OWL_LOGGING_DIRECTION_BOTH,
[d544237]110               "specifies which kind of messages should be logged",
[12c35df]111               "Can be one of 'both', 'in', or 'out'.  If 'in' is\n"
112               "selected, only incoming messages are logged, if 'out'\n"
113               "is selected only outgoing messages are logged.  If 'both'\n"
114               "is selected both incoming and outgoing messages are\n"
115               "logged.",
116               "both,in,out"),
117
[e1c4636]118  OWLVAR_BOOL( "colorztext" /* %OwlVarStub */, 1,
[aa2f33b3]119               "allow @color() in zephyrs to change color",
120               "Note that only messages received after this variable\n"
121               "is set will be affected." ),
[e1c4636]122
[c15bbfb]123  OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1,
124               "Use 'nice' line drawing on the terminal.",
125               "If turned off, dashes, pipes and pluses will be used\n"
126               "to draw lines on the screen.  Useful when the terminal\n"
127               "is causing problems" ),
128
[d309eb3]129  OWLVAR_BOOL( "zcrypt" /* %OwlVarStub */, 1,
130               "Do automatic zcrypt processing",
131               "" ),
132
[4357be8]133  OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0,
134                    "Enable zephyr pseudo logins",
[a16d7e5]135                    "When this is enabled, BarnOwl will periodically check the zephyr\n"
[4357be8]136                    "location of users in your .anyone file.  If a user is present\n"
137                    "but sent no login message, or a user is not present that sent no\n"
[d544237]138                    "logout message, a pseudo login or logout message will be created\n",
[4357be8]139                    NULL, owl_variable_pseudologins_set, NULL),
[5a95b69]140
[280ddc6]141  OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0,
142               "Enable printing of login notifications",
[a16d7e5]143               "When this is enabled, BarnOwl will print login and logout notifications\n"
144               "for AIM, zephyr, or other protocols.  If disabled BarnOwl will not print\n"
[3038d13]145               "login or logout notifications.\n"),
[280ddc6]146
[15b34fd]147  OWLVAR_STRING( "logfilter" /* %OwlVarStub */, "",
148                 "name of a filter controlling which messages to log",
149
150                 "If non empty, any messages matching the given filter will be logged.\n"
[d544237]151                 "This is a completely separate mechanism from the other logging\n"
[15b34fd]152                 "variables like logging, classlogging, loglogins, loggingdirection,\n"
153                 "etc.  If you want this variable to control all logging, make sure\n"
154                 "all other logging variables are in their default state.\n"),
155
[e22f27c]156  OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0,
157               "Enable logging of login notifications",
[a16d7e5]158               "When this is enabled, BarnOwl will log login and logout notifications\n"
[30d0cf7]159               "for AIM, zephyr, or other protocols.  If disabled BarnOwl will not print\n"
[e22f27c]160               "login or logout notifications.\n"),
161
[217a43e]162  OWLVAR_ENUM_FULL( "disable-ctrl-d" /* %OwlVarStub:lockout_ctrld */, 1,
[aa2f33b3]163                    "don't send zephyrs on C-d",
[40de7394]164                    "If set to 'on', C-d won't send a zephyr from the edit\n"
165                    "window.  If set to 'off', C-d will always send a zephyr\n"
[aa2f33b3]166                    "being composed in the edit window.  If set to 'middle',\n"
167                    "C-d will only ever send a zephyr if the cursor is at\n"
168                    "the end of the message being composed.\n\n"
169                    "Note that this works by changing the C-d keybinding\n"
170                    "in the editmulti keymap.\n",
171                    "off,middle,on",
[7d4fbcd]172                    NULL, owl_variable_disable_ctrl_d_set, NULL),
173
174  OWLVAR_PATH( "logpath" /* %OwlVarStub */, "~/zlog/people",
[aa2f33b3]175               "path for logging personal zephyrs", 
176               "Specifies a directory which must exist.\n"
177               "Files will be created in the directory for each sender.\n"),
[7d4fbcd]178
179  OWLVAR_PATH( "classlogpath" /* %OwlVarStub:classlogpath */, "~/zlog/class",
[aa2f33b3]180               "path for logging class zephyrs",
181               "Specifies a directory which must exist.\n"
182               "Files will be created in the directory for each class.\n"),
[7d4fbcd]183
184  OWLVAR_PATH( "debug_file" /* %OwlVarStub */, OWL_DEBUG_FILE,
[aa2f33b3]185               "path for logging debug messages when debugging is enabled",
[26ad412]186               "This file will be logged to if 'debug' is set to 'on'.\n"
187               "BarnOwl will append a dot and the current process's pid to the filename."),
[7d4fbcd]188 
[ced25d1]189  OWLVAR_PATH( "zsigproc" /* %OwlVarStub:zsigproc */, NULL,
[aa2f33b3]190               "name of a program to run that will generate zsigs",
191               "This program should produce a zsig on stdout when run.\n"
[81a96af]192               "Note that it is important that this program not block.\n\n"
193               "See the documentation for 'zsig' for more information about\n"
194               "how the outgoing zsig is chosen."
195               ),
[7d4fbcd]196
[700c712]197  OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL,
198               "name of a program to run when new messages are present",
[a16d7e5]199               "The named program will be run when BarnOwl receives new\n"
[700c712]200               "messages.  It will not be run again until the first\n"
201               "instance exits"),
202
[247cbc9]203  OWLVAR_STRING( "zsender" /* %OwlVarStub */, "",
204             "zephyr sender name",
205         "Allows you to customize the outgoing username in\n"
206         "zephyrs.  If this is unset, it will use your Kerberos\n"
207         "principal. Note that customizing the sender name will\n"
208         "cause your zephyrs to be sent unauthenticated."),
209
[de3f641]210  OWLVAR_STRING( "zsigfunc" /* %OwlVarStub */, "BarnOwl::default_zephyr_signature()",
211                 "zsig perl function",
212                 "Called every time you start a zephyrgram without an\n"
213                 "explicit zsig.  The default setting implements the policy\n"
[b120bd3]214                 "described in the documentation for the 'zsig' variable.\n"
215                 "See also BarnOwl::random_zephyr_signature().\n"),
[de3f641]216
[7d4fbcd]217  OWLVAR_STRING( "zsig" /* %OwlVarStub */, "",
[81a96af]218                 "zephyr signature",
219                 "The zsig to get on outgoing messages. If this variable is\n"
220                 "unset, 'zsigproc' will be run to generate a zsig. If that is\n"
221                 "also unset, the 'zwrite-signature' zephyr variable will be\n"
222                 "used instead.\n"),
[7d4fbcd]223
224  OWLVAR_STRING( "appendtosepbar" /* %OwlVarStub */, "",
[aa2f33b3]225                 "string to append to the end of the sepbar",
226                 "The sepbar is the bar separating the top and bottom\n"
[a16d7e5]227                 "of the BarnOwl screen.  Any string specified here will\n"
[aa2f33b3]228                 "be displayed on the right of the sepbar\n"),
[7d4fbcd]229
230  OWLVAR_BOOL( "zaway" /* %OwlVarStub */, 0,
[aa2f33b3]231               "turn zaway on or off", "" ),
[7d4fbcd]232
233  OWLVAR_STRING( "zaway_msg" /* %OwlVarStub */, 
234                 OWL_DEFAULT_ZAWAYMSG,
[aa2f33b3]235                 "zaway msg for responding to zephyrs when away", "" ),
[7d4fbcd]236
237  OWLVAR_STRING( "zaway_msg_default" /* %OwlVarStub */, 
238                 OWL_DEFAULT_ZAWAYMSG,
[aa2f33b3]239                 "default zaway message", "" ),
[7d4fbcd]240
[4b660cc]241  OWLVAR_BOOL_FULL( "aaway" /* %OwlVarStub */, 0,
242                    "Set AIM away status",
243                    "",
244                    NULL, owl_variable_aaway_set, NULL),
245
246  OWLVAR_STRING( "aaway_msg" /* %OwlVarStub */, 
247                 OWL_DEFAULT_AAWAYMSG,
248                 "AIM away msg for responding when away", "" ),
249
250  OWLVAR_STRING( "aaway_msg_default" /* %OwlVarStub */, 
251                 OWL_DEFAULT_AAWAYMSG,
252                 "default AIM away message", "" ),
253
[7d4fbcd]254  OWLVAR_STRING( "view_home" /* %OwlVarStub */, "all",
[aa2f33b3]255                 "home view to switch to after 'X' and 'V'", 
256                 "SEE ALSO: view, filter\n" ),
[7d4fbcd]257
[ecd5dc5]258  OWLVAR_STRING( "alert_filter" /* %OwlVarStub */, "none",
259                 "filter on which to trigger alert actions",
260                 "" ),
261
262  OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop",
[a16d7e5]263                 "BarnOwl command to execute for alert actions",
[ecd5dc5]264                 "" ),
265
[f203cad]266  OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "<string>", "tty name for zephyr location", "",
[c01e477]267                      NULL, owl_variable_tty_set, NULL),
[bd3f232]268
[bc14adc]269  OWLVAR_STRING( "default_style" /* %OwlVarStub */, "default",
[c3ab155]270                 "name of the default formatting style",
[f1e629d]271                 "This sets the default message formatting style.\n"
272                 "Styles may be created with the 'style' command.\n"
273                 "Some built-in styles include:\n"
[a16d7e5]274                 "   default  - the default BarnOwl formatting\n"
[f1e629d]275                 "   oneline  - one line per-message\n"
276                 "   perl     - legacy perl interface\n"
277                 "\nSEE ALSO: style, show styles, view -s <style>\n"
278                 ),
279
[c3ab155]280
[d36f2cb]281  OWLVAR_INT(    "edit:maxfillcols" /* %OwlVarStub:edit_maxfillcols */, 70,
[4d9e4254]282                 "maximum number of columns for M-q (edit:fill-paragraph) to fill text to",
283                 "This specifies the maximum number of columns for M-q to fill text\n"
284                 "to.  If set to 0, M-q will wrap to the width of the window, and\n"
285                 "values less than 0 disable M-q entirely.\n"),
[d36f2cb]286
[a4bbd80]287  OWLVAR_INT(    "edit:maxwrapcols" /* %OwlVarStub:edit_maxwrapcols */, 70,
[aa2f33b3]288                 "maximum number of columns for line-wrapping",
[4d9e4254]289                 "This specifies the maximum number of columns for\n"
290                 "auto-line-wrapping.  If set to 0, text will be wrapped at the\n"
291                 "window width. Values less than 0 disable automatic wrapping.\n"
292                 "\n"
293                 "As a courtesy to recipients, it is recommended that outgoing\n"
294                 "Zephyr messages be no wider than 70 columns.\n"),
[d36f2cb]295
[1db061d]296  OWLVAR_INT( "aim_ignorelogin_timer" /* %OwlVarStub */, 15,
[6a415e9]297              "number of seconds after AIM login to ignore login messages",
298              "This specifies the number of seconds to wait after an\n"
[d544237]299              "AIM login before allowing the receipt of AIM login notifications.\n"
[1db061d]300              "By default this is set to 15.  If you would like to view login\n"
301              "notifications of buddies as soon as you login, set it to 0 instead."),
[6a415e9]302
303             
[7d4fbcd]304  OWLVAR_INT_FULL( "typewinsize" /* %OwlVarStub:typwin_lines */, 
305                   OWL_TYPWIN_SIZE,
[aa2f33b3]306                  "number of lines in the typing window", 
307                   "This specifies the height of the window at the\n"
308                   "bottom of the screen where commands are entered\n"
309                   "and where messages are composed.\n",
310                   "int > 0",
[7d4fbcd]311                   owl_variable_int_validate_gt0,
312                   owl_variable_typewinsize_set,
313                   NULL /* use default for get */
314                   ),
315
[da466e0]316  OWLVAR_INT( "typewindelta" /* %OwlVarStub */, 0,
317                  "number of lines to add to the typing window when in use",
318                   "On small screens you may want the typing window to\n"
319                   "auto-hide when not entering a command or message.\n"
320                   "This variable is the number of lines to add to the\n"
321           "typing window when it is in use; you can then set\n"
322           "typewinsize to 1.\n\n"
323           "This works a lot better with a non-default scrollmode;\n"
324           "try :set scrollmode pagedcenter.\n"),
325
[aa2f33b3]326  OWLVAR_ENUM( "scrollmode" /* %OwlVarStub */, OWL_SCROLLMODE_NORMAL,
327               "how to scroll up and down",
328               "This controls how the screen is scrolled as the\n"
329               "cursor moves between messages being displayed.\n"
330               "The following modes are supported:\n\n"
[a16d7e5]331               "   normal      - This is the BarnOwl default.  Scrolling happens\n"
[aa2f33b3]332               "                 when it needs to, and an attempt is made to\n"
333               "                 keep the current message roughly near\n"
334               "                 the middle of the screen.\n"
335               "   top         - The current message will always be the\n"
336               "                 the top message displayed.\n"
337               "   neartop     - The current message will be one down\n"
338               "                 from the top message displayed,\n"
339               "                 where possible.\n"
340               "   center      - An attempt is made to keep the current\n"
341               "                 message near the center of the screen.\n"
342               "   paged       - The top message displayed only changes\n"
343               "                 when user moves the cursor to the top\n"
344               "                 or bottom of the screen.  When it moves,\n"
345               "                 the screen will be paged up or down and\n"
346               "                 the cursor will be near the top or\n"
347               "                 the bottom.\n"
348               "   pagedcenter - The top message displayed only changes\n"
349               "                 when user moves the cursor to the top\n"
350               "                 or bottom of the screen.  When it moves,\n"
351               "                 the screen will be paged up or down and\n"
352               "                 the cursor will be near the center.\n",
353               "normal,top,neartop,center,paged,pagedcenter" ),
354
[66e409c]355  OWLVAR_BOOL( "narrow-related" /* %OwlVarStub:narrow_related */, 1,
356               "Make smartnarrow use broader filters",
357               "Causes smartfiler to narrow to messages \"related\" to \n"
358               "the current message, as well as ones to the same place.\n\n"
359               "for Zephyr, this controls whether to narrow to e.g. class-help or\n"
360               "class-help.d alone, or to related-class-help, which includes\n"
361               "help, unhelp, help.d, etc.\n\nDefault is true (include unclasses, etc.).\n" ),
[ecd5dc5]362
[7d4fbcd]363  OWLVAR_BOOL( "_followlast" /* %OwlVarStub */, 0,
[aa2f33b3]364               "enable automatic following of the last zephyr",
365               "If the cursor is at the last message, it will\n"
366               "continue to follow the last message if this is set.\n"
367               "Note that this is currently risky as you might accidentally\n"
368               "delete a message right as it came in.\n" ),
[7d4fbcd]369
[f203cad]370  OWLVAR_STRING_FULL( "default_exposure" /* %OwlVarStub */, "",
371                      "none,opstaff,realm-visible,realm-announced,net-visible,net-announced",
372                      "controls the persistent value for exposure",
373                      "The default exposure level corresponds to the Zephyr exposure value\n"
374                      "in ~/.zephyr.vars.  Defaults to realm-visible if there is no value in\n"
375                      "~/.zephyr.vars.\n"
376                      "See the description of exposure for the values this can be.",
377                      NULL, owl_variable_default_exposure_set, owl_variable_default_exposure_get ),
378
379  OWLVAR_STRING_FULL( "exposure" /* %OwlVarStub */, "",
380                      "none,opstaff,realm-visible,realm-announced,net-visible,net-announced",
381                      "controls who can zlocate you",
382                      "The exposure level, defaulting to the value of default_exposure,\n"
383                      "can be one of the following (from least exposure to widest exposure,\n"
384                      "as listed in zctl(1)):\n"
385                      "\n"
386                      "   none            - This completely disables Zephyr for the user. \n"
387                      "                     The user is not registered with Zephyr.  No user\n"
388                      "                     location information is retained by Zephyr.  No\n"
389                      "                     login or logout announcements will be sent.  No\n"
390                      "                     subscriptions will be entered for the user, and\n"
391                      "                     no notices will be displayed by zwgc(1).\n"
392                      "   opstaff         - The user is registered with Zephyr.  No login or\n"
393                      "                     logout announcements will be sent, and location\n"
394                      "                     information will only be visible to Operations\n"
395                      "                     staff.  Default subscriptions and any additional\n"
396                      "                     personal subscriptions will be entered for the\n"
397                      "                     user.\n"
398                      "   realm-visible   - The user is registered with Zephyr.  User\n"
399                      "                     location information is retained by Zephyr and\n"
400                      "                     made available only to users within the user’s\n"
401                      "                     Kerberos realm.  No login or logout\n"
402                      "                     announcements will be sent.  This is the system\n"
403                      "                     default.  Default subscriptions and any\n"
404                      "                     additional personal subscriptions will be\n"
405                      "                     entered for the user.\n"
406                      "   realm-announced - The user is registered with Zephyr.  User\n"
407                      "                     location information is retained by Zephyr and\n"
408                      "                     made available only to users authenticated\n"
409                      "                     within the user’s Kerberos realm.  Login and\n"
410                      "                     logout announcements will be sent, but only to\n"
411                      "                     users within the user’s Kerberos realm who have\n"
412                      "                     explicitly requested such via subscriptions. \n"
413                      "                     Default subscriptions and any additional\n"
414                      "                     personal subscriptions will be entered for the\n"
415                      "                     user.\n"
416                      "   net-visible     - The user is registered with Zephyr.  User\n"
417                      "                     location information is retained by Zephyr and\n"
418                      "                     made available to any authenticated user who\n"
419                      "                     requests such.  Login and logout announcements\n"
420                      "                     will be sent only to users within the user’s\n"
421                      "                     Kerberos realm who have explicitly requested\n"
422                      "                     such via subscriptions.  Default subscriptions\n"
423                      "                     and any additional personal subscriptions will\n"
424                      "                     be entered for the user.\n"
425                      "   net-announced   - The user is registered with Zephyr.  User\n"
426                      "                     location information is retained by Zephyr and\n"
427                      "                     made available to any authenticated user who\n"
428                      "                     requests such.  Login and logout announcements\n"
429                      "                     will be sent to any user has requested such. \n"
430                      "                     Default subscriptions and any additional\n"
431                      "                     personal subscriptions will be entered for the\n"
432                      "                     user.\n",
433                      NULL, owl_variable_exposure_set, NULL /* use default for get */ ),
434
[7d4fbcd]435  /* This MUST be last... */
[aa2f33b3]436  { NULL, 0, NULL, 0, NULL, NULL, NULL, NULL,
437    NULL, NULL, NULL, NULL, NULL, NULL }
[7d4fbcd]438
[9e86f6f]439  };
440
[9efc154]441  int ret = owl_variable_dict_add_from_list(vd, variables_to_init);
442  owl_variable *var;
443  for (var = variables_to_init; var->name != NULL; var++)
444    owl_variable_cleanup(var);
445  return ret;
[9e86f6f]446}
[7d4fbcd]447
448/**************************************************************************/
449/*********************** SPECIFIC TO VARIABLES ****************************/
450/**************************************************************************/
451
452
453/* commonly useful */
454
[64735f0]455int owl_variable_int_validate_gt0(const owl_variable *v, const void *newval)
[4357be8]456{
[7d4fbcd]457  if (newval == NULL) return(0);
[defe4a3]458  else if (*(const int*)newval < 1) return(0);
[7d4fbcd]459  else return (1);
460}
461
[64735f0]462int owl_variable_int_validate_positive(const owl_variable *v, const void *newval)
[4357be8]463{
[7d4fbcd]464  if (newval == NULL) return(0);
[defe4a3]465  else if (*(const int*)newval < 0) return(0);
[7d4fbcd]466  else return (1);
467}
468
469/* typewinsize */
[e19eb97]470int owl_variable_typewinsize_set(owl_variable *v, const void *newval)
[4357be8]471{
[7d4fbcd]472  int rv;
473  rv = owl_variable_int_set_default(v, newval);
[f6fae8d]474  if (0 == rv) owl_mainpanel_layout_contents(&g.mainpanel);
[7d4fbcd]475  return(rv);
476}
477
478/* debug (cache value in g->debug) */
[e19eb97]479int owl_variable_debug_set(owl_variable *v, const void *newval)
[4357be8]480{
[defe4a3]481  if (newval && (*(const int*)newval == 1 || *(const int*)newval == 0)) {
482    g.debug = *(const int*)newval;
[7d4fbcd]483  }
484  return owl_variable_bool_set_default(v, newval);
[4b660cc]485}
486
487/* When 'aaway' is changed, need to notify the AIM server */
[e19eb97]488int owl_variable_aaway_set(owl_variable *v, const void *newval)
[4357be8]489{
[4b660cc]490  if (newval) {
[defe4a3]491    if (*(const int*)newval == 1) {
[4b660cc]492      owl_aim_set_awaymsg(owl_global_get_aaway_msg(&g));
[defe4a3]493    } else if (*(const int*)newval == 0) {
[4b660cc]494      owl_aim_set_awaymsg("");
495    }
496  }
497  return owl_variable_bool_set_default(v, newval);
[7d4fbcd]498}
499
[e19eb97]500int owl_variable_pseudologins_set(owl_variable *v, const void *newval)
[4357be8]501{
[72146c7]502  static guint timer = 0;
[4357be8]503  if (newval) {
[defe4a3]504    if (*(const int*)newval == 1) {
[4357be8]505      owl_function_zephyr_buddy_check(0);
[72146c7]506      if (timer == 0) {
507        timer = g_timeout_add_seconds(180, owl_zephyr_buddycheck_timer, NULL);
[3687413]508      }
509    } else {
[72146c7]510      if (timer != 0) {
511        g_source_remove(timer);
512        timer = 0;
[3687413]513      }
[4357be8]514    }
515  }
516  return owl_variable_bool_set_default(v, newval);
517}
518
[7d4fbcd]519/* note that changing the value of this will clobber
520 * any user setting of this */
[e19eb97]521int owl_variable_disable_ctrl_d_set(owl_variable *v, const void *newval)
[4357be8]522{
[217a43e]523  if (newval && !owl_context_is_startup(owl_global_get_context(&g))) {
[defe4a3]524    if (*(const int*)newval == 2) {
[7d4fbcd]525      owl_function_command_norv("bindkey editmulti C-d command edit:delete-next-char");
[defe4a3]526    } else if (*(const int*)newval == 1) {
[3b42640]527      owl_function_command_norv("bindkey editmulti C-d command edit:done-or-delete");
[7d4fbcd]528    } else {
[3b42640]529      owl_function_command_norv("bindkey editmulti C-d command edit:done");
[7d4fbcd]530    }
531  } 
[217a43e]532  return owl_variable_int_set_default(v, newval); 
[7d4fbcd]533}
534
[e19eb97]535int owl_variable_tty_set(owl_variable *v, const void *newval)
[4357be8]536{
[f54b07d]537  owl_zephyr_set_locationinfo(g_get_host_name(), newval);
[c01e477]538  return(owl_variable_string_set_default(v, newval));
539}
540
[f203cad]541int owl_variable_default_exposure_set(owl_variable *v, const void *newval)
542{
543  return owl_zephyr_set_default_exposure(newval);
544}
545
546const void *owl_variable_default_exposure_get(const owl_variable *v)
547{
548  return owl_zephyr_get_default_exposure();
549}
550
551int owl_variable_exposure_set(owl_variable *v, const void *newval)
552{
553  int ret = owl_zephyr_set_exposure(newval);
554  if (ret != 0)
555    return ret;
556  return owl_variable_string_set_default(v, owl_zephyr_normalize_exposure(newval));
557}
[7d4fbcd]558
559/**************************************************************************/
560/****************************** GENERAL ***********************************/
561/**************************************************************************/
562
563int owl_variable_dict_setup(owl_vardict *vd) {
[4c7c21f]564  owl_dict_create(vd);
[9e86f6f]565  return owl_variable_add_defaults(vd);
566}
567
568int owl_variable_dict_add_from_list(owl_vardict *vd, owl_variable *variables_to_init)
569{
570  owl_variable *var, *cur;
[d536e72]571  for (var = variables_to_init; var->name != NULL; var++) {
[96828e4]572    cur = g_new(owl_variable, 1);
[66a8cd6]573    *cur = *var;
[7d7326c]574    /* strdup all the strings so we can delete them consistently. */
[d4927a7]575    cur->name = g_strdup(var->name);
576    cur->summary = g_strdup(var->summary);
577    cur->description = g_strdup(var->description);
[7d4fbcd]578    switch (cur->type) {
579    case OWL_VARIABLE_OTHER:
580      cur->set_fn(cur, cur->pval_default);
581      break;
582    case OWL_VARIABLE_STRING:
583      if (!cur->validate_fn) 
584        cur->validate_fn = owl_variable_string_validate_default;
585      if (!cur->set_fn) 
586        cur->set_fn = owl_variable_string_set_default;
587      if (!cur->set_fromstring_fn) 
588        cur->set_fromstring_fn = owl_variable_string_set_fromstring_default;
589      if (!cur->get_fn) 
590        cur->get_fn = owl_variable_get_default;
591      if (!cur->get_tostring_fn) 
592        cur->get_tostring_fn = owl_variable_string_get_tostring_default;     
[bbd74a9]593      if (!cur->delete_fn)
594        cur->delete_fn = owl_variable_delete_default;
[ea68035]595      cur->pval_default = g_strdup(var->pval_default);
[7d4fbcd]596      cur->set_fn(cur, cur->pval_default);
597      break;
598    case OWL_VARIABLE_BOOL:
599      if (!cur->validate_fn) 
600        cur->validate_fn = owl_variable_bool_validate_default;
601      if (!cur->set_fn) 
602        cur->set_fn = owl_variable_bool_set_default;
603      if (!cur->set_fromstring_fn) 
604        cur->set_fromstring_fn = owl_variable_bool_set_fromstring_default;
605      if (!cur->get_fn) 
606        cur->get_fn = owl_variable_get_default;
607      if (!cur->get_tostring_fn) 
608        cur->get_tostring_fn = owl_variable_bool_get_tostring_default;     
[bbd74a9]609      if (!cur->delete_fn)
610        cur->delete_fn = owl_variable_delete_default;
[96828e4]611      cur->val = g_new(int, 1);
[7d4fbcd]612      cur->set_fn(cur, &cur->ival_default);
613      break;
614    case OWL_VARIABLE_INT:
615      if (!cur->validate_fn) 
616        cur->validate_fn = owl_variable_int_validate_default;
617      if (!cur->set_fn) 
618        cur->set_fn = owl_variable_int_set_default;
619      if (!cur->set_fromstring_fn) 
620        cur->set_fromstring_fn = owl_variable_int_set_fromstring_default;
621      if (!cur->get_fn) 
622        cur->get_fn = owl_variable_get_default;
623      if (!cur->get_tostring_fn) 
624        cur->get_tostring_fn = owl_variable_int_get_tostring_default;     
[bbd74a9]625      if (!cur->delete_fn)
626        cur->delete_fn = owl_variable_delete_default;
[96828e4]627      cur->val = g_new(int, 1);
[7d4fbcd]628      cur->set_fn(cur, &cur->ival_default);
629      break;
630    default:
631      fprintf(stderr, "owl_variable_setup: invalid variable type\n");
632      return(-2);
633    }
[4d86e06]634    owl_dict_insert_element(vd, cur->name, cur, NULL);
[7d4fbcd]635  }
636  return 0;
637}
638
[a695a68]639void owl_variable_dict_add_variable(owl_vardict * vardict,
640                                    owl_variable * var) {
[3b0edaa]641  owl_dict_insert_element(vardict, var->name, var, (void (*)(void *))owl_variable_delete);
[a695a68]642}
643
[6829afc]644CALLER_OWN owl_variable *owl_variable_newvar(const char *name, const char *summary, const char *description)
[d427f08]645{
[96828e4]646  owl_variable * var = g_new0(owl_variable, 1);
[d4927a7]647  var->name = g_strdup(name);
648  var->summary = g_strdup(summary);
649  var->description = g_strdup(description);
[a695a68]650  return var;
651}
652
[e19eb97]653void owl_variable_update(owl_variable *var, const char *summary, const char *desc) {
[3b8a563]654  g_free(var->summary);
[d4927a7]655  var->summary = g_strdup(summary);
[3b8a563]656  g_free(var->description);
[d4927a7]657  var->description = g_strdup(desc);
[d536e72]658}
659
[bc1d648]660void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval)
661{
662  owl_variable *old = owl_variable_get_var(vd, name);
[ca54fd6]663  if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING) {
[d536e72]664    owl_variable_update(old, summ, desc);
[3b8a563]665    g_free(old->pval_default);
[d4927a7]666    old->pval_default = g_strdup(initval);
[d536e72]667  } else {
668    owl_variable * var = owl_variable_newvar(name, summ, desc);
669    var->type = OWL_VARIABLE_STRING;
[1dab38e]670    var->validsettings = "<string>";
[d4927a7]671    var->pval_default = g_strdup(initval);
[d536e72]672    var->set_fn = owl_variable_string_set_default;
673    var->set_fromstring_fn = owl_variable_string_set_fromstring_default;
674    var->get_fn = owl_variable_get_default;
675    var->get_tostring_fn = owl_variable_string_get_tostring_default;
[bbd74a9]676    var->delete_fn = owl_variable_delete_default;
[d536e72]677    var->set_fn(var, initval);
678    owl_variable_dict_add_variable(vd, var);
679  }
[a695a68]680}
681
[bc1d648]682void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval)
683{
684  owl_variable *old = owl_variable_get_var(vd, name);
[ca54fd6]685  if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) {
[d536e72]686    owl_variable_update(old, summ, desc);
687    old->ival_default = initval;
688  } else {
689    owl_variable * var = owl_variable_newvar(name, summ, desc);
690    var->type = OWL_VARIABLE_INT;
[1dab38e]691    var->validsettings = "<int>";
[d536e72]692    var->ival_default = initval;
693    var->validate_fn = owl_variable_int_validate_default;
694    var->set_fn = owl_variable_int_set_default;
695    var->set_fromstring_fn = owl_variable_int_set_fromstring_default;
696    var->get_fn = owl_variable_get_default;
697    var->get_tostring_fn = owl_variable_int_get_tostring_default;
[bbd74a9]698    var->delete_fn = owl_variable_delete_default;
[96828e4]699    var->val = g_new(int, 1);
[d536e72]700    var->set_fn(var, &initval);
701    owl_variable_dict_add_variable(vd, var);
702  }
[a695a68]703}
704
[6f7d4f6]705void owl_variable_dict_newvar_bool(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval)
[bc1d648]706{
707  owl_variable *old = owl_variable_get_var(vd, name);
[ca54fd6]708  if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL) {
[d536e72]709    owl_variable_update(old, summ, desc);
710    old->ival_default = initval;
711  } else {
712    owl_variable * var = owl_variable_newvar(name, summ, desc);
713    var->type = OWL_VARIABLE_BOOL;
[1dab38e]714    var->validsettings = "on,off";
[d536e72]715    var->ival_default = initval;
716    var->validate_fn = owl_variable_bool_validate_default;
717    var->set_fn = owl_variable_bool_set_default;
718    var->set_fromstring_fn = owl_variable_bool_set_fromstring_default;
719    var->get_fn = owl_variable_get_default;
720    var->get_tostring_fn = owl_variable_bool_get_tostring_default;
[bbd74a9]721    var->delete_fn = owl_variable_delete_default;
[96828e4]722    var->val = g_new(int, 1);
[d536e72]723    var->set_fn(var, &initval);
724    owl_variable_dict_add_variable(vd, var);
725  }
[a695a68]726}
727
[0fef6eb]728void owl_variable_dict_cleanup(owl_vardict *d)
729{
[bf7aa1d]730  owl_dict_cleanup(d, (void (*)(void *))owl_variable_delete);
[7d4fbcd]731}
732
[ce68f23]733CALLER_OWN GPtrArray *owl_variable_dict_get_names(const owl_vardict *d) {
734  return owl_dict_get_keys(d);
[7d4fbcd]735}
736
[9efc154]737void owl_variable_cleanup(owl_variable *v)
[3b0edaa]738{
[bbd74a9]739  if (v->delete_fn) v->delete_fn(v);
[ddbbcffa]740  g_free(v->name);
741  g_free(v->summary);
742  g_free(v->description);
[ea68035]743  if (v->type == OWL_VARIABLE_STRING)
744    g_free(v->pval_default);
[9efc154]745}
746
747void owl_variable_delete(owl_variable *v)
748{
749  owl_variable_cleanup(v);
[ddbbcffa]750  g_free(v);
[7d4fbcd]751}
752
753
[ca54fd6]754const char *owl_variable_get_name(const owl_variable *v)
755{
756  return v->name;
757}
758
[64735f0]759const char *owl_variable_get_description(const owl_variable *v) {
[aa2f33b3]760  return v->description;
761}
762
[64735f0]763const char *owl_variable_get_summary(const owl_variable *v) {
[aa2f33b3]764  return v->summary;
[7d4fbcd]765}
766
[64735f0]767const char *owl_variable_get_validsettings(const owl_variable *v) {
[fa981f3]768  return v->validsettings;
[7d4fbcd]769}
770
[ca54fd6]771int owl_variable_get_type(const owl_variable *v)
772{
773  return v->type;
774}
775
[7d4fbcd]776/* functions for getting and setting variable values */
777
778/* returns 0 on success, prints a status msg if msg is true */
[ca54fd6]779int owl_variable_set_fromstring(owl_variable *v, const char *value, int msg) {
[010a951]780  char *tostring;
[7d4fbcd]781  if (!v->set_fromstring_fn) {
[ca54fd6]782    if (msg) owl_function_error("Variable %s is read-only", owl_variable_get_name(v));
[486688f]783    return -1;   
[7d4fbcd]784  }
785  if (0 != v->set_fromstring_fn(v, value)) {
[ca54fd6]786    if (msg) owl_function_error("Unable to set %s (must be %s)", owl_variable_get_name(v),
787                                owl_variable_get_validsettings(v));
[7d4fbcd]788    return -1;
789  }
[fa981f3]790  if (msg) {
[779bd3d]791    tostring = v->get_tostring_fn(v, v->get_fn(v));
[ca749a9]792    if (tostring)
793      owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring);
794    else
795      owl_function_makemsg("%s = <null>", owl_variable_get_name(v));
[010a951]796    g_free(tostring);
[7d4fbcd]797  }   
798  return 0;
799}
800 
[ca54fd6]801int owl_variable_set_string(owl_variable *v, const char *newval)
802{
803  if (v->type != OWL_VARIABLE_STRING) return -1;
[ba6c8bd]804  return v->set_fn(v, newval);
[7d4fbcd]805}
806 
[ca54fd6]807int owl_variable_set_int(owl_variable *v, int newval)
808{
809  if (v->type != OWL_VARIABLE_INT && v->type != OWL_VARIABLE_BOOL) return -1;
[7d4fbcd]810  return v->set_fn(v, &newval);
811}
812 
[ca54fd6]813int owl_variable_set_bool_on(owl_variable *v)
814{
815  if (v->type != OWL_VARIABLE_BOOL) return -1;
816  return owl_variable_set_int(v, true);
[7d4fbcd]817}
818
[ca54fd6]819int owl_variable_set_bool_off(owl_variable *v)
820{
821  if (v->type != OWL_VARIABLE_BOOL) return -1;
822  return owl_variable_set_int(v, false);
[7d4fbcd]823}
824
[ca54fd6]825CALLER_OWN char *owl_variable_get_tostring(const owl_variable *v)
[d427f08]826{
[779bd3d]827  return v->get_tostring_fn(v, v->get_fn(v));
[7d4fbcd]828}
829
[ca54fd6]830CALLER_OWN char *owl_variable_get_default_tostring(const owl_variable *v)
[d427f08]831{
[7d4fbcd]832  if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) {
[010a951]833    return v->get_tostring_fn(v, &(v->ival_default));
[7d4fbcd]834  } else {
[010a951]835    return v->get_tostring_fn(v, v->pval_default);
[7d4fbcd]836  }
837}
838
[bc1d648]839owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name)
840{
[fa981f3]841  return owl_dict_find_element(d, name);
[d536e72]842}
843
844/* returns a reference */
[ca54fd6]845const void *owl_variable_get(const owl_variable *v)
[bc1d648]846{
[7d4fbcd]847  return v->get_fn(v);
848}
849
[ca54fd6]850const char *owl_variable_get_string(const owl_variable *v)
851{
852  if (owl_variable_get_type(v) != OWL_VARIABLE_STRING) {
853    owl_function_error("Variable '%s' is not a string.", owl_variable_get_name(v));
854    return NULL;
855  }
856  return owl_variable_get(v);
[7d4fbcd]857}
858
859/* returns a reference */
[ca54fd6]860const void *owl_variable_get_other(const owl_variable *v)
861{
862  if (owl_variable_get_type(v) != OWL_VARIABLE_OTHER) {
863    owl_function_error("Variable '%s' is not type other.", owl_variable_get_name(v));
864    return NULL;
865  }
866  return owl_variable_get(v);
[7d4fbcd]867}
868
[ca54fd6]869int owl_variable_get_int(const owl_variable *v)
870{
871  if (owl_variable_get_type(v) != OWL_VARIABLE_INT) {
872    owl_function_error("Variable '%s' is an int.", owl_variable_get_name(v));
873    return -1;
874  }
875  const int *pi = owl_variable_get(v);
[bc1d648]876  if (!pi) return -1;
877  return *pi;
[7d4fbcd]878}
879
[ca54fd6]880int owl_variable_get_bool(const owl_variable *v)
881{
882  if (owl_variable_get_type(v) != OWL_VARIABLE_BOOL) {
883    owl_function_error("Variable '%s' is a boolean.", owl_variable_get_name(v));
884    return -1;
885  }
886  const int *pi = owl_variable_get(v);
[bc1d648]887  if (!pi) return -1;
888  return *pi;
[7d4fbcd]889}
890
[ca54fd6]891void owl_variable_describe(const owl_variable *v, owl_fmtext *fm)
892{
[ca749a9]893  char *tostring = owl_variable_get_default_tostring(v);
894  char *default_buf;
895
896  if (tostring)
897    default_buf = g_strdup_printf("'%s'", tostring);
898  else
899    default_buf = g_strdup("<null>");
900  owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: %s)\n",
901                            owl_variable_get_name(v),
902                            owl_variable_get_summary(v), default_buf);
[010a951]903  g_free(default_buf);
[ca749a9]904  g_free(tostring);
[7d4fbcd]905}
906
[ca54fd6]907void owl_variable_get_help(const owl_variable *v, owl_fmtext *fm) {
[010a951]908  char *tostring;
[7d4fbcd]909
910  owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n");
911  owl_fmtext_append_normal(fm, OWL_TABSTR);
[ca54fd6]912  owl_fmtext_append_normal(fm, owl_variable_get_name(v));
[7d4fbcd]913  owl_fmtext_append_normal(fm, " - ");
[ca54fd6]914  owl_fmtext_append_normal(fm, owl_variable_get_summary(v));
[7d4fbcd]915  owl_fmtext_append_normal(fm, "\n\n");
916
917  owl_fmtext_append_normal(fm, "Current:        ");
[ca54fd6]918  tostring = owl_variable_get_tostring(v);
[ca749a9]919  owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>"));
[010a951]920  g_free(tostring);
[7d4fbcd]921  owl_fmtext_append_normal(fm, "\n\n");
922
923
[ca54fd6]924  tostring = owl_variable_get_default_tostring(v);
[7d4fbcd]925  owl_fmtext_append_normal(fm, "Default:        ");
[ca749a9]926  owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>"));
[7d4fbcd]927  owl_fmtext_append_normal(fm, "\n\n");
928
929  owl_fmtext_append_normal(fm, "Valid Settings: ");
930  owl_fmtext_append_normal(fm, owl_variable_get_validsettings(v));
931  owl_fmtext_append_normal(fm, "\n\n");
[aa2f33b3]932
933  if (v->description && *v->description) {
934    owl_fmtext_append_normal(fm, "Description:\n");
935    owl_fmtext_append_normal(fm, owl_variable_get_description(v));
936    owl_fmtext_append_normal(fm, "\n\n");
937  }
[010a951]938  g_free(tostring);
[7d4fbcd]939}
940
941
942
943
944/**************************************************************************/
945/*********************** GENERAL TYPE-SPECIFIC ****************************/
946/**************************************************************************/
947
948/* default common functions */
949
[64735f0]950const void *owl_variable_get_default(const owl_variable *v) {
[7d4fbcd]951  return v->val;
952}
953
[bbd74a9]954void owl_variable_delete_default(owl_variable *v)
955{
[3b8a563]956  g_free(v->val);
[7d4fbcd]957}
958
959/* default functions for booleans */
960
[64735f0]961int owl_variable_bool_validate_default(const owl_variable *v, const void *newval) {
[7d4fbcd]962  if (newval == NULL) return(0);
[defe4a3]963  else if (*(const int*)newval==1 || *(const int*)newval==0) return(1);
[7d4fbcd]964  else return (0);
965}
966
[e19eb97]967int owl_variable_bool_set_default(owl_variable *v, const void *newval) {
[7d4fbcd]968  if (v->validate_fn) {
969    if (!v->validate_fn(v, newval)) return(-1);
970  }
[defe4a3]971  *(int*)v->val = *(const int*)newval;
[7d4fbcd]972  return(0);
973}
974
[e19eb97]975int owl_variable_bool_set_fromstring_default(owl_variable *v, const char *newval) {
[7d4fbcd]976  int i;
977  if (!strcmp(newval, "on")) i=1;
978  else if (!strcmp(newval, "off")) i=0;
979  else return(-1);
980  return (v->set_fn(v, &i));
981}
982
[6829afc]983CALLER_OWN char *owl_variable_bool_get_tostring_default(const owl_variable *v, const void *val)
[d427f08]984{
[7d4fbcd]985  if (val == NULL) {
[ca749a9]986    return NULL;
[defe4a3]987  } else if (*(const int*)val == 0) {
[010a951]988    return g_strdup("off");
[defe4a3]989  } else if (*(const int*)val == 1) {
[010a951]990    return g_strdup("on");
[7d4fbcd]991  } else {
[010a951]992    return g_strdup("<invalid>");
[7d4fbcd]993  }
994}
995
996/* default functions for integers */
997
[64735f0]998int owl_variable_int_validate_default(const owl_variable *v, const void *newval) {
[7d4fbcd]999  if (newval == NULL) return(0);
1000  else return (1);
1001}
1002
[e19eb97]1003int owl_variable_int_set_default(owl_variable *v, const void *newval) {
[7d4fbcd]1004  if (v->validate_fn) {
1005    if (!v->validate_fn(v, newval)) return(-1);
1006  }
[defe4a3]1007  *(int*)v->val = *(const int*)newval;
[7d4fbcd]1008  return(0);
1009}
1010
[e19eb97]1011int owl_variable_int_set_fromstring_default(owl_variable *v, const char *newval) {
[7d4fbcd]1012  int i;
[99525be]1013  char *ep;
1014  i = strtol(newval, &ep, 10);
[7d4fbcd]1015  if (*ep || ep==newval) return(-1);
1016  return (v->set_fn(v, &i));
1017}
1018
[6829afc]1019CALLER_OWN char *owl_variable_int_get_tostring_default(const owl_variable *v, const void *val)
[d427f08]1020{
[7d4fbcd]1021  if (val == NULL) {
[ca749a9]1022    return NULL;
[7d4fbcd]1023  } else {
[010a951]1024    return g_strdup_printf("%d", *(const int*)val);
[7d4fbcd]1025  } 
1026}
1027
1028/* default functions for enums (a variant of integers) */
1029
[64735f0]1030int owl_variable_enum_validate(const owl_variable *v, const void *newval) { 
[7d4fbcd]1031  char **enums;
1032  int nenums, val;
1033  if (newval == NULL) return(0);
[d275eb2]1034  enums = g_strsplit_set(v->validsettings, ",", 0);
1035  nenums = g_strv_length(enums);
1036  g_strfreev(enums);
[defe4a3]1037  val = *(const int*)newval;
[7d4fbcd]1038  if (val < 0 || val >= nenums) {
1039    return(0);
1040  }
1041  return(1);
1042}
1043
[e19eb97]1044int owl_variable_enum_set_fromstring(owl_variable *v, const char *newval) {
[7d4fbcd]1045  char **enums;
[d275eb2]1046  int i, val=-1;
[7d4fbcd]1047  if (newval == NULL) return(-1);
[d275eb2]1048  enums = g_strsplit_set(v->validsettings, ",", 0);
1049  for (i = 0; enums[i] != NULL; i++) {
[7d4fbcd]1050    if (0==strcmp(newval, enums[i])) {
1051      val = i;
1052    }
1053  }
[d275eb2]1054  g_strfreev(enums);
[7d4fbcd]1055  if (val == -1) return(-1);
1056  return (v->set_fn(v, &val));
1057}
1058
[6829afc]1059CALLER_OWN char *owl_variable_enum_get_tostring(const owl_variable *v, const void *val)
[d427f08]1060{
[7d4fbcd]1061  char **enums;
1062  int nenums, i;
[010a951]1063  char *tostring;
[7d4fbcd]1064
1065  if (val == NULL) {
[ca749a9]1066    return NULL;
[7d4fbcd]1067  }
[d275eb2]1068  enums = g_strsplit_set(v->validsettings, ",", 0);
1069  nenums = g_strv_length(enums);
[defe4a3]1070  i = *(const int*)val;
[7d4fbcd]1071  if (i<0 || i>=nenums) {
[d275eb2]1072    g_strfreev(enums);
[010a951]1073    return g_strdup_printf("<invalid:%d>", i);
[7d4fbcd]1074  }
[010a951]1075  tostring = g_strdup(enums[i]);
[d275eb2]1076  g_strfreev(enums);
[010a951]1077  return tostring;
[7d4fbcd]1078}
1079
1080/* default functions for stringeans */
1081
[64735f0]1082int owl_variable_string_validate_default(const struct _owl_variable *v, const void *newval) {
[7d4fbcd]1083  if (newval == NULL) return(0);
1084  else return (1);
1085}
1086
[e19eb97]1087int owl_variable_string_set_default(owl_variable *v, const void *newval) {
[7d4fbcd]1088  if (v->validate_fn) {
1089    if (!v->validate_fn(v, newval)) return(-1);
1090  }
[3b8a563]1091  g_free(v->val);
[d4927a7]1092  v->val = g_strdup(newval);
[7d4fbcd]1093  return(0);
1094}
1095
[e19eb97]1096int owl_variable_string_set_fromstring_default(owl_variable *v, const char *newval) {
[7d4fbcd]1097  return (v->set_fn(v, newval));
1098}
1099
[6829afc]1100CALLER_OWN char *owl_variable_string_get_tostring_default(const owl_variable *v, const void *val)
[d427f08]1101{
[ca749a9]1102  return g_strdup((const char*)val);
[7d4fbcd]1103}
1104
Note: See TracBrowser for help on using the repository browser.