[BACK]Return to server-msg.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/Attic/server-msg.c between version 1.10 and 1.11

version 1.10, 2009/08/08 21:52:43 version 1.11, 2009/08/11 17:18:35
Line 37 
Line 37 
 int  int
 server_msg_dispatch(struct client *c)  server_msg_dispatch(struct client *c)
 {  {
         struct hdr               hdr;          struct imsg              imsg;
         struct msg_command_data  commanddata;          struct msg_command_data  commanddata;
         struct msg_identify_data identifydata;          struct msg_identify_data identifydata;
         struct msg_resize_data   resizedata;          struct msg_resize_data   resizedata;
         struct msg_unlock_data   unlockdata;          struct msg_unlock_data   unlockdata;
         struct msg_environ_data  environdata;          struct msg_environ_data  environdata;
           ssize_t                  n, datalen;
   
           if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
                   return (-1);
   
         for (;;) {          for (;;) {
                 if (BUFFER_USED(c->in) < sizeof hdr)                  if ((n = imsg_get(&c->ibuf, &imsg)) == -1)
                           return (-1);
                   if (n == 0)
                         return (0);                          return (0);
                 memcpy(&hdr, BUFFER_OUT(c->in), sizeof hdr);                  datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
                 if (BUFFER_USED(c->in) < (sizeof hdr) + hdr.size)  
                         return (0);  
                 buffer_remove(c->in, sizeof hdr);  
   
                 switch (hdr.type) {                  if (imsg.hdr.peerid != PROTOCOL_VERSION) {
                           server_write_client(c, MSG_VERSION, NULL, 0);
                           c->flags |= CLIENT_BAD;
                           imsg_free(&imsg);
                           continue;
                   }
   
                   log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd);
                   switch (imsg.hdr.type) {
                 case MSG_COMMAND:                  case MSG_COMMAND:
                         if (hdr.size != sizeof commanddata)                          if (datalen != sizeof commanddata)
                                 fatalx("bad MSG_COMMAND size");                                  fatalx("bad MSG_COMMAND size");
                         buffer_read(c->in, &commanddata, sizeof commanddata);                          memcpy(&commanddata, imsg.data, sizeof commanddata);
   
                         server_msg_command(c, &commanddata);                          server_msg_command(c, &commanddata);
                         break;                          break;
                 case MSG_IDENTIFY:                  case MSG_IDENTIFY:
                         if (hdr.size != sizeof identifydata)                          if (datalen != sizeof identifydata)
                                 fatalx("bad MSG_IDENTIFY size");                                  fatalx("bad MSG_IDENTIFY size");
                         buffer_read(c->in, &identifydata, sizeof identifydata);                          memcpy(&identifydata, imsg.data, sizeof identifydata);
   
                         server_msg_identify(c, &identifydata);                          server_msg_identify(c, &identifydata);
                         break;                          break;
                 case MSG_RESIZE:                  case MSG_RESIZE:
                         if (hdr.size != sizeof resizedata)                          if (datalen != sizeof resizedata)
                                 fatalx("bad MSG_RESIZE size");                                  fatalx("bad MSG_RESIZE size");
                         buffer_read(c->in, &resizedata, sizeof resizedata);                          memcpy(&resizedata, imsg.data, sizeof resizedata);
   
                         server_msg_resize(c, &resizedata);                          server_msg_resize(c, &resizedata);
                         break;                          break;
                 case MSG_EXITING:                  case MSG_EXITING:
                         if (hdr.size != 0)                          if (datalen != 0)
                                 fatalx("bad MSG_EXITING size");                                  fatalx("bad MSG_EXITING size");
   
                         c->session = NULL;                          c->session = NULL;
Line 83 
Line 94 
                         server_write_client(c, MSG_EXITED, NULL, 0);                          server_write_client(c, MSG_EXITED, NULL, 0);
                         break;                          break;
                 case MSG_UNLOCK:                  case MSG_UNLOCK:
                         if (hdr.size != sizeof unlockdata)                          if (datalen != sizeof unlockdata)
                                 fatalx("bad MSG_UNLOCK size");                                  fatalx("bad MSG_UNLOCK size");
                         buffer_read(c->in, &unlockdata, sizeof unlockdata);                          memcpy(&unlockdata, imsg.data, sizeof unlockdata);
   
                         unlockdata.pass[(sizeof unlockdata.pass) - 1] = '\0';                          unlockdata.pass[(sizeof unlockdata.pass) - 1] = '\0';
                         if (server_unlock(unlockdata.pass) != 0)                          if (server_unlock(unlockdata.pass) != 0)
Line 94 
Line 105 
                         server_write_client(c, MSG_EXIT, NULL, 0);                          server_write_client(c, MSG_EXIT, NULL, 0);
                         break;                          break;
                 case MSG_WAKEUP:                  case MSG_WAKEUP:
                         if (hdr.size != 0)                          if (datalen != 0)
                                 fatalx("bad MSG_WAKEUP size");                                  fatalx("bad MSG_WAKEUP size");
   
                         c->flags &= ~CLIENT_SUSPENDED;                          c->flags &= ~CLIENT_SUSPENDED;
Line 102 
Line 113 
                         server_redraw_client(c);                          server_redraw_client(c);
                         break;                          break;
                 case MSG_ENVIRON:                  case MSG_ENVIRON:
                         if (hdr.size != sizeof environdata)                          if (datalen != sizeof environdata)
                                 fatalx("bad MSG_ENVIRON size");                                  fatalx("bad MSG_ENVIRON size");
                         buffer_read(c->in, &environdata, sizeof environdata);                          memcpy(&environdata, imsg.data, sizeof environdata);
   
                         environdata.var[(sizeof environdata.var) - 1] = '\0';                          environdata.var[(sizeof environdata.var) - 1] = '\0';
                         if (strchr(environdata.var, '=') != NULL)                          if (strchr(environdata.var, '=') != NULL)
Line 113 
Line 124 
                 default:                  default:
                         fatalx("unexpected message");                          fatalx("unexpected message");
                 }                  }
   
                   imsg_free(&imsg);
         }          }
 }  }
   
Line 224 
Line 237 
 void  void
 server_msg_identify(struct client *c, struct msg_identify_data *data)  server_msg_identify(struct client *c, struct msg_identify_data *data)
 {  {
         if (data->version != PROTOCOL_VERSION) {  
                 server_write_error(c, "protocol version mismatch");  
                 return;  
         }  
   
         c->tty.sx = data->sx;          c->tty.sx = data->sx;
         c->tty.sy = data->sy;          c->tty.sy = data->sy;
   

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11