modules/pc/pc_commands.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. command_show
  2. command_set
  3. command_stop
  4. command_purify
  5. command_quit
  6. show_const
  7. show_consts
  8. show_props
  9. show_threads
  10. show_whois
  11. show_access
  12. show_acl
  13. set_acl
  14. set_nodeny
  15. set_updates
  16. set_err
  17. show_err
  18. show_macros
  19. set_macro
  20. stop_query

   1 #include "mysql_driver.h"
   2 #include "access_control.h"
   3 #include "thread.h"
   4 #include "constants.h"
   5 #include "properties.h"
   6 #include "protocol_config.h"
   7 #include "ta.h"
   8 #include "pc_commands.h"
   9 
  10 extern void purify_new_inuse(void);
  11 /*
  12  * Command functions
  13  */
  14 
  15 int command_show(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  16   return command_execute(show, "show ", input, output, condat);
  17 } /* command_show() */
  18 
  19 int command_set(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  20   return command_execute(set, "set ", input, output,condat);
  21 } /* command_set() */
  22 
  23 int command_stop(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  24   return command_execute(stop, "stop ", input, output, condat);
  25 }
  26 
  27 
  28 int command_purify(char *input, GString *output, sk_conn_st *condat)
     /* [<][>][^][v][top][bottom][index][help] */
  29 {
  30 #if 0
  31   purify_new_inuse();
  32 #else 
  33   g_string_append(output, "NOP");
  34 #endif
  35   
  36   return 0;
  37 }
  38 
  39 
  40 
  41 int command_quit(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  42     /* Administrator wishes to quit. */
  43   return PC_RET_QUIT;
  44 } /* command_quit() */
  45 
  46 int show_const(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  47   /* Administrator wishes to show constants. */
  48   char *result, *name, *cursor;
  49   int res = 0;
  50   
  51   if( strlen(input) > 0 ) {
  52     cursor = input;
  53     name = (char *)strsep(&cursor, " ");
  54 
  55     if( (result = CO_const_to_string(name)) != NULL ) {
  56       g_string_append(output, result);
  57       wr_free(result);
  58     }
  59     else {
  60       g_string_append(output,  "unknown constant");
  61       res = PC_RET_ERR;
  62     }
  63   }
  64   else {
  65     g_string_append(output,  "name required");
  66     res = PC_RET_ERR;
  67   }
  68  
  69   return res;
  70 
  71 } /* show_const() */
  72 
  73 int show_consts(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  74   /* Administrator wishes to show constants. */
  75   char *s =  CO_to_string();
  76   g_string_append(output, s);
  77   free(s);
  78   return 0;
  79 } /* show_consts() */
  80 
  81 int show_props(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  82   /* Administrator wishes to show properties. */
  83   char *s =  PR_to_string();
  84   g_string_append(output, s);
  85   free(s);  
  86   return 0;
  87 } /* show_props() */
  88 
  89 int show_threads(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  90   /* Administrator wishes to show thread information. */
  91   char *s = TA_tostring();
  92   g_string_append(output, s);
  93   free(s);  
  94   return 0;
  95 } /* show_thread() */
  96 
  97 int show_whois(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
  98   /* Administrator wishes to show whois query information. */
  99   PW_interact(condat->sock);
 100   return 0;
 101 } /* show_whois() */
 102 
 103 int show_access(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
 104   /* Administrator wishes to show whois query information. */
 105   
 106   char line[128];
 107   int cnt = 0;
 108   er_ret_t err; 
 109 
 110   if( act_runtime->top_ptr != NULL ) {
 111     char *header = AC_to_string_header();
 112     
 113     /* print header */
 114     SK_cd_puts(condat,header);
 115     wr_free(header);
 116 
 117     cnt = rx_walk_tree(act_runtime->top_ptr, AC_rxwalkhook_print, 
 118                        RX_WALK_SKPGLU,  /* print no glue nodes */
 119                        255, 0, 0, condat, &err);
 120   }
 121   
 122   g_string_sprintfa(output, "Found %d nodes\n", cnt);
 123 
 124   return 0;
 125 } /* show_access() */
 126 
 127 
 128 int show_acl(char *input, GString *output, sk_conn_st *condat) 
     /* [<][>][^][v][top][bottom][index][help] */
 129 {
 130   /* Administrator wishes to show access control list. */  
 131   char line[128];
 132   int cnt = 0;
 133   er_ret_t err; 
 134 
 135   if( act_acl->top_ptr != NULL ) {
 136     char *header = AC_acl_to_string_header();
 137     
 138     /* print header */
 139     SK_cd_puts(condat,header);
 140     wr_free(header);
 141 
 142     cnt = rx_walk_tree(act_acl->top_ptr, AC_rxwalkhook_print_acl, 
 143                        RX_WALK_SKPGLU,  /* print no glue nodes */
 144                        255, 0, 0, condat, &err);
 145   }
 146 
 147   g_string_sprintfa(output, "Found %d nodes\n", cnt);
 148 
 149   return 0;
 150 } /* show_acl() */
 151 
 152 
 153 int set_acl(char *input, GString *output, sk_conn_st *condat)
     /* [<][>][^][v][top][bottom][index][help] */
 154 {
 155   int res = 0;
 156   
 157   /* first 8 characters ("set acl ") are already skipped */
 158   if( ! NOERR( AC_asc_acl_command_set( input, "Manual"))) {
 159     g_string_append(output, "Error!\n");
 160     res = PC_RET_ERR;
 161   }
 162   return res;
 163 }
 164 
 165 int set_nodeny(char *input, GString *output, sk_conn_st *condat) {
     /* [<][>][^][v][top][bottom][index][help] */
 166   /* reset the deny counter in the access tree to 0 (after reenabling) */
 167   /* first 11 characters ("set nodeny ")  are already skipped */
 168 
 169   if( ! NOERR( AC_asc_set_nodeny(input) )) {
 170     g_string_append(output, "Error\n");
 171     return PC_RET_ERR;
 172   }
 173   else {
 174     return 0;
 175   }
 176   
 177 } /* set_nodeny() */
 178 
 179 int set_updates(char *input, GString *output, sk_conn_st *condat) 
     /* [<][>][^][v][top][bottom][index][help] */
 180 {
 181   char argstr[17];
 182   int pause=0, resume=0;
 183   int res = 0;
 184  
 185   if( sscanf(input, "%16s", argstr) == 1) {
 186     pause = (strcmp(argstr,"pause") == 0);
 187     resume = (strcmp(argstr,"resume") == 0);
 188   }
 189   
 190   if( !pause && !resume ) {
 191     g_string_append(output,  "syntax error.");
 192     res = PC_RET_ERR;
 193   }
 194   else {
 195     /* all params ok. just set the property */
 196     char *value = pause ? "0" : "1";
 197     
 198     if (CO_set_const("UD.do_update", value) == 0) {
 199       g_string_append(output, "Constant successfully set\n");
 200     }
 201     else {
 202       g_string_append(output, "Could not set\n");
 203       res = PC_RET_ERR;
 204     }
 205   }
 206   return res;
 207 }
 208 
 209 
 210 int set_err(char *input, GString *output, sk_conn_st *condat) 
     /* [<][>][^][v][top][bottom][index][help] */
 211 {
 212   char *erret = NULL;
 213   int res;
 214 
 215   res = ER_macro_spec(input, &erret);
 216   g_string_append(output, erret);
 217   free(erret);
 218 
 219   return res;
 220 }
 221 
 222 int show_err(char *input, GString *output, sk_conn_st *condat) 
     /* [<][>][^][v][top][bottom][index][help] */
 223 {
 224   char *erret = NULL;
 225 
 226   er_print_paths(&erret);
 227   g_string_append(output, erret);
 228   free(erret);
 229 
 230   return 0;
 231 }
 232 
 233 int show_macros(char *input, GString *output, sk_conn_st *condat)
     /* [<][>][^][v][top][bottom][index][help] */
 234 {
 235   ER_macro_list(condat);
 236   return 0;
 237 }
 238 
 239 int set_macro(char *input, GString *output, sk_conn_st *condat)
     /* [<][>][^][v][top][bottom][index][help] */
 240 {
 241   char *name, *body;
 242   
 243   if( strlen(input) > 0 ) {
 244     body = input;
 245     name = (char *)strsep(&body, " "); 
 246     
 247     ER_make_macro( name, body );
 248   }
 249 
 250   return 0;
 251 }
 252 
 253 
 254 int stop_query(char *input, GString *output, sk_conn_st *condat) 
     /* [<][>][^][v][top][bottom][index][help] */
 255 {
 256   int fd, thr;
 257   /* assume the command is like "stop query 11 17". 
 258      This is to limit ambiguities (a new thread on the same socket, 
 259      for example).
 260 . */
 261   
 262   if( sscanf(input, "%d %d", &fd, &thr)<2 ) {
 263     
 264     g_string_append(output,"error!!");
 265     return PC_RET_ERR;
 266   }
 267   else {
 268     TA_trigger("whois", fd, thr);
 269     return 0;
 270   }
 271 }

/* [<][>][^][v][top][bottom][index][help] */