/[dynamips]/upstream/dynamips-0.2.6-RC1/hypervisor.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /upstream/dynamips-0.2.6-RC1/hypervisor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.5/hypervisor.c revision 1 by dpavlin, Sat Oct 6 16:01:44 2007 UTC upstream/dynamips-0.2.6-RC1/hypervisor.c revision 2 by dpavlin, Sat Oct 6 16:03:58 2007 UTC
# Line 58  static int cmd_version(hypervisor_conn_t Line 58  static int cmd_version(hypervisor_conn_t
58     return(0);     return(0);
59  }  }
60    
61    /* Parser test */
62    static int cmd_parser_test(hypervisor_conn_t *conn,int argc,char *argv[])
63    {
64       int i;
65    
66       for(i=0;i<argc;i++)
67          hypervisor_send_reply(conn,HSC_INFO_MSG,0,
68                                "arg %d (len %u): \"%s\"",
69                                i,strlen(argv[i]),argv[i]);
70    
71       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
72       return(0);
73    }
74    
75  /* Show hypervisor module list */  /* Show hypervisor module list */
76  static int cmd_mod_list(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_mod_list(hypervisor_conn_t *conn,int argc,char *argv[])
77  {  {
# Line 151  static int cmd_stop(hypervisor_conn_t *c Line 165  static int cmd_stop(hypervisor_conn_t *c
165  /* Hypervisor commands */  /* Hypervisor commands */
166  static hypervisor_cmd_t hypervisor_cmd_array[] = {  static hypervisor_cmd_t hypervisor_cmd_array[] = {
167     { "version", 0, 0, cmd_version, NULL },     { "version", 0, 0, cmd_version, NULL },
168       { "parser_test", 0, 10, cmd_parser_test, NULL },
169     { "module_list", 0, 0, cmd_mod_list, NULL },     { "module_list", 0, 0, cmd_mod_list, NULL },
170     { "cmd_list", 1, 1, cmd_modcmd_list, NULL },     { "cmd_list", 1, 1, cmd_modcmd_list, NULL },
171     { "working_dir", 1, 1, cmd_set_working_dir, NULL },     { "working_dir", 1, 1, cmd_set_working_dir, NULL },
# Line 325  static int hypervisor_exec_cmd(hyperviso Line 340  static int hypervisor_exec_cmd(hyperviso
340  static void *hypervisor_thread(void *arg)  static void *hypervisor_thread(void *arg)
341  {    {  
342     hypervisor_conn_t *conn = arg;     hypervisor_conn_t *conn = arg;
343     char buffer[4096],**tokens;     char buffer[512],**tokens;
344     parser_token_t *tok_list;     parser_context_t ctx;
345     int res,tok_count;     int res;
346        
347       tokens = NULL;
348       parser_context_init(&ctx);
349    
350     while(conn->active) {     while(conn->active) {
351        if (!m_fgets(buffer,sizeof(buffer),conn->in))        if (!fgets(buffer,sizeof(buffer),conn->in))
352           break;           break;
353        
354        if (!*buffer)        if (!*buffer)
355           continue;           continue;
356    
357        /* Tokenize command line */        /* Tokenize command line */
358        tokens = NULL;        res = parser_scan_buffer(&ctx,buffer,strlen(buffer));
       res = parser_tokenize(buffer,&tok_list,&tok_count);  
359    
360        if (res != 0) {        if (res != 0) {  
361           hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s",           tokens = NULL;
                                parser_strerror(res));  
          continue;  
       }  
362    
363        if (tok_count < 2) {           if (ctx.error != 0) {
364           hypervisor_send_reply(conn,HSC_ERR_PARSING,1,              hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s",
365                                 "At least a module and a command "                                    parser_strerror(&ctx));
366                                 "must be specified");              goto free_tokens;
367           goto free_tokens;           }
368        }  
369             if (ctx.tok_count < 2) {
370                hypervisor_send_reply(conn,HSC_ERR_PARSING,1,
371                                      "At least a module and a command "
372                                      "must be specified");
373                goto free_tokens;
374             }
375    
376        /* Map token list to an array */           /* Map token list to an array */
377        tokens = parser_map_array(tok_list,tok_count);           tokens = parser_map_array(&ctx);
378                
379        if (!tokens) {           if (!tokens) {
380           hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory");              hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory");
381           goto free_tokens;              goto free_tokens;
382        }           }
383    
384        /* Execute command */           /* Execute command */
385        m_log("hypervisor_exec","%s\n",buffer);           //m_log("hypervisor_exec","%s\n",buffer);
386        hypervisor_exec_cmd(conn,tokens[0],tokens[1],tok_count-2,&tokens[2]);           hypervisor_exec_cmd(conn,tokens[0],tokens[1],ctx.
387                                 tok_count-2,&tokens[2]);
388                
389     free_tokens:        free_tokens:
390        free(tokens);           free(tokens);
391        parser_free_tokens(tok_list);           tokens = NULL;
392             parser_context_free(&ctx);
393          }
394     }     }
395    
396       free(tokens);
397       parser_context_free(&ctx);
398     return NULL;     return NULL;
399  }  }
400    
# Line 518  int hypervisor_tcp_server(int tcp_port) Line 543  int hypervisor_tcp_server(int tcp_port)
543     hypervisor_atmsw_init();     hypervisor_atmsw_init();
544     hypervisor_ethsw_init();     hypervisor_ethsw_init();
545     hypervisor_vm_init();     hypervisor_vm_init();
546       hypervisor_vm_debug_init();
547     hypervisor_c7200_init();     hypervisor_c7200_init();
548     hypervisor_c3600_init();     hypervisor_c3600_init();
549    

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26