/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.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 /sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.c

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

revision 367 by matthewc, Wed Apr 16 13:04:15 2003 UTC revision 651 by astrand, Thu Apr 15 20:12:42 2004 UTC
# Line 26  Line 26 
26  #include <sys/stat.h>           /* stat */  #include <sys/stat.h>           /* stat */
27  #include <sys/time.h>           /* gettimeofday */  #include <sys/time.h>           /* gettimeofday */
28  #include <sys/times.h>          /* times */  #include <sys/times.h>          /* times */
29    #include <ctype.h>              /* toupper */
30  #include <errno.h>  #include <errno.h>
31  #include "rdesktop.h"  #include "rdesktop.h"
32    
# Line 40  Line 41 
41  #include "crypto/md5.h"  #include "crypto/md5.h"
42  #endif  #endif
43    
44  char title[32] = "";  char g_title[64] = "";
45  char username[16];  char g_username[64];
46  char hostname[16];  char hostname[16];
47  char keymapname[16];  char keymapname[16];
48  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int keylayout = 0x409;          /* Defaults to US keyboard layout */
49  int width = 800;                /* If width or height are reset to zero, the geometry will  
50                                     be fetched from _NET_WORKAREA */  int g_width = 800;              /* width is special: If 0, the
51  int height = 600;                                     geometry will be fetched from
52                                       _NET_WORKAREA. If negative,
53                                       absolute value specifies the
54                                       percent of the whole screen. */
55    int g_height = 600;
56  int tcp_port_rdp = TCP_PORT_RDP;  int tcp_port_rdp = TCP_PORT_RDP;
57  int server_bpp = 8;  int g_server_bpp = 8;
58  int win_button_size = 0;        /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
59  BOOL bitmap_compression = True;  BOOL g_bitmap_compression = True;
60  BOOL sendmotion = True;  BOOL g_sendmotion = True;
61  BOOL orders = True;  BOOL g_orders = True;
62  BOOL encryption = True;  BOOL g_encryption = True;
63  BOOL desktop_save = True;  BOOL packet_encryption = True;
64  BOOL fullscreen = False;  BOOL g_desktop_save = True;
65  BOOL grab_keyboard = True;  BOOL g_fullscreen = False;
66  BOOL hide_decorations = False;  BOOL g_grab_keyboard = True;
67  BOOL use_rdp5 = False;  BOOL g_hide_decorations = False;
68  extern BOOL owncolmap;  BOOL g_use_rdp5 = True;
69    BOOL g_console_session = False;
70    BOOL g_numlock_sync = False;
71    BOOL g_owncolmap = False;
72    BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
73    uint32 g_embed_wnd;
74    uint32 g_rdp5_performanceflags =
75            RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
76    
77    #ifdef WITH_RDPSND
78    BOOL g_rdpsnd = False;
79    #endif
80    
81    extern RDPDR_DEVICE g_rdpdr_device[];
82    extern uint32 g_num_devices;
83    extern char *g_rdpdr_clientname;
84    
85  #ifdef RDP2VNC  #ifdef RDP2VNC
86  extern int rfb_port;  extern int rfb_port;
# Line 80  usage(char *program) Line 100  usage(char *program)
100          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
101  #ifdef RDP2VNC  #ifdef RDP2VNC
102          fprintf(stderr, "   -V: vnc port\n");          fprintf(stderr, "   -V: vnc port\n");
103          fprintf(stderr, "   -E: defer time (ms)\n");          fprintf(stderr, "   -Q: defer time (ms)\n");
104  #endif  #endif
105          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
106          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
107          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
108          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
109          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
110          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
111          fprintf(stderr, "   -k: keyboard layout on terminal server (us,sv,gr,etc.)\n");          fprintf(stderr, "   -k: keyboard layout on server (en-us, de, sv, etc.)\n");
112          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
113          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
114          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
115            fprintf(stderr, "   -B: use BackingStore of X-server (if available)\n");
116          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
117            fprintf(stderr, "   -E: disable encryption from client to server\n");
118          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
119          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
120            fprintf(stderr, "   -D: hide window manager decorations\n");
121          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
122            fprintf(stderr, "   -S: caption button size (single application mode)\n");
123          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
124          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -N: enable numlock syncronization\n");
125          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -X: embed into another window with a given id.\n");
126          fprintf(stderr, "   -5: Use RDP5 (EXPERIMENTAL!)\n");          fprintf(stderr, "   -a: connection colour depth\n");
127            fprintf(stderr,
128                    "   -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n");
129            fprintf(stderr, "   -r: enable specified device redirection (this flag can be repeated)\n");
130            fprintf(stderr,
131                    "         '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
132            fprintf(stderr, "             or      COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
133            fprintf(stderr,
134                    "         '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n");
135            fprintf(stderr, "             or   A=/mnt/floppy,D=/mnt/cdrom'\n");
136            fprintf(stderr, "         '-r clientname=<client name>': Set the client name displayed\n");
137            fprintf(stderr, "             for redirected disks\n");
138            fprintf(stderr,
139                    "         '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
140            fprintf(stderr, "             or      LPT1=/dev/lp0,LPT2=/dev/lp1\n");
141            fprintf(stderr, "         '-r printer:mydeskjet': enable printer redirection\n");
142            fprintf(stderr,
143                    "             or      mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
144            fprintf(stderr, "         '-r sound:[local|off|remote]': enable sound redirection\n");
145            fprintf(stderr, "                     remote would leave sound on server\n");
146            fprintf(stderr, "   -0: attach to console\n");
147            fprintf(stderr, "   -4: use RDP version 4\n");
148            fprintf(stderr, "   -5: use RDP version 5 (default)\n");
149  }  }
150    
151  static BOOL  static BOOL
# Line 139  read_password(char *password, int size) Line 184  read_password(char *password, int size)
184          return ret;          return ret;
185  }  }
186    
187    static void
188    parse_server_and_port(char *server)
189    {
190            char *p;
191    #ifdef IPv6
192            int addr_colons;
193    #endif
194    
195    #ifdef IPv6
196            p = server;
197            addr_colons = 0;
198            while (*p)
199                    if (*p++ == ':')
200                            addr_colons++;
201            if (addr_colons >= 2)
202            {
203                    /* numeric IPv6 style address format - [1:2:3::4]:port */
204                    p = strchr(server, ']');
205                    if (*server == '[' && p != NULL)
206                    {
207                            if (*(p + 1) == ':' && *(p + 2) != '\0')
208                                    tcp_port_rdp = strtol(p + 2, NULL, 10);
209                            /* remove the port number and brackets from the address */
210                            *p = '\0';
211                            strncpy(server, server + 1, strlen(server));
212                    }
213            }
214            else
215            {
216                    /* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */
217                    p = strchr(server, ':');
218                    if (p != NULL)
219                    {
220                            tcp_port_rdp = strtol(p + 1, NULL, 10);
221                            *p = 0;
222                    }
223            }
224    #else /* no IPv6 support */
225            p = strchr(server, ':');
226            if (p != NULL)
227            {
228                    tcp_port_rdp = strtol(p + 1, NULL, 10);
229                    *p = 0;
230            }
231    #endif /* IPv6 */
232    
233    }
234    
235  /* Client program */  /* Client program */
236  int  int
237  main(int argc, char *argv[])  main(int argc, char *argv[])
# Line 146  main(int argc, char *argv[]) Line 239  main(int argc, char *argv[])
239          char server[64];          char server[64];
240          char fullhostname[64];          char fullhostname[64];
241          char domain[16];          char domain[16];
242          char password[16];          char password[64];
243          char shell[128];          char shell[128];
244          char directory[32];          char directory[32];
245          BOOL prompt_password;          BOOL prompt_password, rdp_retval = False;
246          struct passwd *pw;          struct passwd *pw;
247          uint32 flags;          uint32 flags;
248          char *p;          char *p;
249          int c;          int c;
250    
251          int username_option = 0;          int username_option = 0;
252    
253          flags = RDP_LOGON_NORMAL;          flags = RDP_LOGON_NORMAL;
254          prompt_password = False;          prompt_password = False;
255          domain[0] = password[0] = shell[0] = directory[0] = 0;          domain[0] = password[0] = shell[0] = directory[0] = 0;
256          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
257            g_embed_wnd = 0;
258    
259            g_num_devices = 0;
260    
261  #ifdef RDP2VNC  #ifdef RDP2VNC
262  #define VNCOPT "V:E:"  #define VNCOPT "V:Q:"
263  #else  #else
264  #define VNCOPT  #define VNCOPT
265  #endif  #endif
266    
267          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1)
268          {          {
269                  switch (c)                  switch (c)
270                  {                  {
# Line 178  main(int argc, char *argv[]) Line 275  main(int argc, char *argv[])
275                                          rfb_port += 5900;                                          rfb_port += 5900;
276                                  break;                                  break;
277    
278                          case 'E':                          case 'Q':
279                                  defer_time = strtol(optarg, NULL, 10);                                  defer_time = strtol(optarg, NULL, 10);
280                                  if (defer_time < 0)                                  if (defer_time < 0)
281                                          defer_time = 0;                                          defer_time = 0;
# Line 186  main(int argc, char *argv[]) Line 283  main(int argc, char *argv[])
283  #endif  #endif
284    
285                          case 'u':                          case 'u':
286                                  STRNCPY(username, optarg, sizeof(username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
287                                  username_option = 1;                                  username_option = 1;
288                                  break;                                  break;
289    
# Line 198  main(int argc, char *argv[]) Line 295  main(int argc, char *argv[])
295                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
296                                  break;                                  break;
297    
                         case 'S':  
                                 if (!strcmp(optarg, "standard"))  
                                 {  
                                         win_button_size = 18;  
                                         break;  
                                 }  
   
                                 win_button_size = strtol(optarg, &p, 10);  
   
                                 if (*p)  
                                 {  
                                         error("invalid button size\n");  
                                         return 1;  
                                 }  
   
                                 break;  
   
298                          case 'c':                          case 'c':
299                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
300                                  break;                                  break;
# Line 244  main(int argc, char *argv[]) Line 324  main(int argc, char *argv[])
324                                  break;                                  break;
325    
326                          case 'g':                          case 'g':
327                                    g_fullscreen = False;
328                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
329                                  {                                  {
330                                          width = height = 0;                                          g_width = g_height = 0;
331                                          break;                                          break;
332                                  }                                  }
333    
334                                  width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
335                                    if (g_width <= 0)
336                                    {
337                                            error("invalid geometry\n");
338                                            return 1;
339                                    }
340    
341                                  if (*p == 'x')                                  if (*p == 'x')
342                                          height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, NULL, 10);
343    
344                                  if ((width == 0) || (height == 0))                                  if (g_height <= 0)
345                                  {                                  {
346                                          error("invalid geometry\n");                                          error("invalid geometry\n");
347                                          return 1;                                          return 1;
348                                  }                                  }
349    
350                                    if (*p == '%')
351                                            g_width = -g_width;
352    
353                                  break;                                  break;
354    
355                          case 'f':                          case 'f':
356                                  fullscreen = True;                                  g_fullscreen = True;
357                                  break;                                  break;
358    
359                          case 'b':                          case 'b':
360                                  orders = False;                                  g_orders = False;
361                                  break;                                  break;
362    
363                          case 'e':                          case 'B':
364                                  encryption = False;                                  g_ownbackstore = False;
365                                  break;                                  break;
366    
367                            case 'e':
368                                    g_encryption = False;
369                                    break;
370                            case 'E':
371                                    packet_encryption = False;
372                                    break;
373                          case 'm':                          case 'm':
374                                  sendmotion = False;                                  g_sendmotion = False;
375                                  break;                                  break;
376    
377                          case 'C':                          case 'C':
378                                  owncolmap = True;                                  g_owncolmap = True;
379                                    break;
380    
381                            case 'D':
382                                    g_hide_decorations = True;
383                                  break;                                  break;
384    
385                          case 'K':                          case 'K':
386                                  grab_keyboard = False;                                  g_grab_keyboard = False;
387                                    break;
388    
389                            case 'S':
390                                    if (!strcmp(optarg, "standard"))
391                                    {
392                                            g_win_button_size = 18;
393                                            break;
394                                    }
395    
396                                    g_win_button_size = strtol(optarg, &p, 10);
397    
398                                    if (*p)
399                                    {
400                                            error("invalid button size\n");
401                                            return 1;
402                                    }
403    
404                                  break;                                  break;
405    
406                          case 'T':                          case 'T':
407                                  STRNCPY(title, optarg, sizeof(title));                                  STRNCPY(g_title, optarg, sizeof(g_title));
408                                  break;                                  break;
409    
410                          case 'D':                          case 'N':
411                                  hide_decorations = True;                                  g_numlock_sync = True;
412                                    break;
413    
414                            case 'X':
415                                    g_embed_wnd = strtol(optarg, NULL, 10);
416                                  break;                                  break;
417    
418                          case 'a':                          case 'a':
419                                  server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
420                                  if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15
421                                      && server_bpp != 24)                                      && g_server_bpp != 24)
422                                  {                                  {
423                                          error("invalid server bpp\n");                                          error("invalid server bpp\n");
424                                          return 1;                                          return 1;
425                                  }                                  }
426                                  break;                                  break;
427    
428                            case 'x':
429    
430                                    if (strncmp("modem", optarg, 1) == 0)
431                                    {
432                                            g_rdp5_performanceflags =
433                                                    RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
434                                                    RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
435                                    }
436                                    else if (strncmp("broadband", optarg, 1) == 0)
437                                    {
438                                            g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
439                                    }
440                                    else if (strncmp("lan", optarg, 1) == 0)
441                                    {
442                                            g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
443                                    }
444                                    else
445                                    {
446                                            g_rdp5_performanceflags = strtol(optarg, NULL, 16);
447                                    }
448                                    break;
449    
450                            case 'r':
451    
452                                    if (strncmp("sound", optarg, 5) == 0)
453                                    {
454                                            optarg += 5;
455    
456                                            if (*optarg == ':')
457                                            {
458                                                    *optarg++;
459                                                    while ((p = next_arg(optarg, ',')))
460                                                    {
461                                                            if (strncmp("remote", optarg, 6) == 0)
462                                                                    flags |= RDP_LOGON_LEAVE_AUDIO;
463    
464                                                            if (strncmp("local", optarg, 5) == 0)
465    #ifdef WITH_RDPSND
466                                                                    g_rdpsnd = True;
467    #else
468                                                                    warning("Not compiled with sound support");
469    #endif
470    
471                                                            if (strncmp("off", optarg, 3) == 0)
472                                                                    g_rdpsnd = False;
473    
474                                                            optarg = p;
475                                                    }
476                                            }
477                                            else
478                                            {
479    #ifdef WITH_RDPSND
480                                                    g_rdpsnd = True;
481    #else
482                                                    warning("Not compiled with sound support");
483    #endif
484                                            }
485                                    }
486                                    else if (strncmp("disk", optarg, 4) == 0)
487                                    {
488                                            /* -r disk:h:=/mnt/floppy */
489                                            disk_enum_devices(&g_num_devices, optarg + 4);
490                                    }
491                                    else if (strncmp("comport", optarg, 7) == 0)
492                                    {
493                                            serial_enum_devices(&g_num_devices, optarg + 7);
494                                    }
495                                    else if (strncmp("lptport", optarg, 7) == 0)
496                                    {
497                                            parallel_enum_devices(&g_num_devices, optarg + 7);
498                                    }
499                                    else if (strncmp("printer", optarg, 7) == 0)
500                                    {
501                                            printer_enum_devices(&g_num_devices, optarg + 7);
502                                    }
503                                    else if (strncmp("clientname", optarg, 7) == 0)
504                                    {
505                                            g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
506                                            strcpy(g_rdpdr_clientname, optarg + 11);
507                                    }
508                                    else
509                                    {
510                                            warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
511                                    }
512                                    break;
513    
514                            case '0':
515                                    g_console_session = True;
516                                    break;
517    
518                            case '4':
519                                    g_use_rdp5 = False;
520                                    break;
521    
522                          case '5':                          case '5':
523                                  use_rdp5 = True;                                  g_use_rdp5 = True;
524                                  break;                                  break;
525    
526                          case 'h':                          case 'h':
527                          case '?':                          case '?':
528                          default:                          default:
# Line 314  main(int argc, char *argv[]) Line 531  main(int argc, char *argv[])
531                  }                  }
532          }          }
533    
534          if (argc - optind < 1)          if (argc - optind != 1)
535          {          {
536                  usage(argv[0]);                  usage(argv[0]);
537                  return 1;                  return 1;
538          }          }
539    
540          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
541          p = strchr(server, ':');          parse_server_and_port(server);
         if (p != NULL)  
         {  
                 tcp_port_rdp = strtol(p + 1, NULL, 10);  
                 *p = 0;  
         }  
542    
543          if (!username_option)          if (!username_option)
544          {          {
# Line 337  main(int argc, char *argv[]) Line 549  main(int argc, char *argv[])
549                          return 1;                          return 1;
550                  }                  }
551    
552                  STRNCPY(username, pw->pw_name, sizeof(username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
553          }          }
554    
555          if (hostname[0] == 0)          if (hostname[0] == 0)
# Line 358  main(int argc, char *argv[]) Line 570  main(int argc, char *argv[])
570          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
571                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
572    
573          if (title[0] == 0)          if (g_title[0] == 0)
574          {          {
575                  strcpy(title, "rdesktop - ");                  strcpy(g_title, "rdesktop - ");
576                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));                  strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - "));
577          }          }
578    
579  #ifdef RDP2VNC  #ifdef RDP2VNC
580          rdp2vnc_connect(server, flags, domain, password, shell, directory);          rdp2vnc_connect(server, flags, domain, password, shell, directory);
581            return 0;
582  #else  #else
583    
584          if (!ui_init())          if (!ui_init())
585                  return 1;                  return 1;
586    
587    #ifdef WITH_RDPSND
588            if (g_rdpsnd)
589                    rdpsnd_init();
590    #endif
591            rdpdr_init();
592    
593          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
594                  return 1;                  return 1;
595    
596            /* By setting encryption to False here, we have an encrypted login
597               packet but unencrypted transfer of other packets */
598            if (!packet_encryption)
599                    g_encryption = False;
600    
601    
602          DEBUG(("Connection successful.\n"));          DEBUG(("Connection successful.\n"));
603          memset(password, 0, sizeof(password));          memset(password, 0, sizeof(password));
604    
605          if (ui_create_window())          if (ui_create_window())
606          {          {
607                  rdp_main_loop();                  rdp_retval = rdp_main_loop();
608                  ui_destroy_window();                  ui_destroy_window();
609          }          }
610    
# Line 387  main(int argc, char *argv[]) Line 612  main(int argc, char *argv[])
612          rdp_disconnect();          rdp_disconnect();
613          ui_deinit();          ui_deinit();
614    
615            if (True == rdp_retval)
616                    return 0;
617            else
618                    return 2;
619    
620  #endif  #endif
621    
         return 0;  
622  }  }
623    
624  #ifdef EGD_SOCKET  #ifdef EGD_SOCKET
# Line 552  void Line 781  void
781  hexdump(unsigned char *p, unsigned int len)  hexdump(unsigned char *p, unsigned int len)
782  {  {
783          unsigned char *line = p;          unsigned char *line = p;
784          unsigned int thisline, offset = 0;          int i, thisline, offset = 0;
         int i;  
785    
786          while (offset < len)          while (offset < len)
787          {          {
# Line 577  hexdump(unsigned char *p, unsigned int l Line 805  hexdump(unsigned char *p, unsigned int l
805          }          }
806  }  }
807    
808    /*
809      input: src is the string we look in for needle.
810             Needle may be escaped by a backslash, in
811             that case we ignore that particular needle.
812      return value: returns next src pointer, for
813            succesive executions, like in a while loop
814            if retval is 0, then there are no more args.
815      pitfalls:
816            src is modified. 0x00 chars are inserted to
817            terminate strings.
818            return val, points on the next val chr after ins
819            0x00
820    
821            example usage:
822            while( (pos = next_arg( optarg, ',')) ){
823                    printf("%s\n",optarg);
824                    optarg=pos;
825            }
826    
827    */
828    char *
829    next_arg(char *src, char needle)
830    {
831            char *nextval;
832            char *p;
833            char *mvp = 0;
834    
835            /* EOS */
836            if (*src == (char) 0x00)
837                    return 0;
838    
839            p = src;
840            /*  skip escaped needles */
841            while ((nextval = strchr(p, needle)))
842            {
843                    mvp = nextval - 1;
844                    /* found backslashed needle */
845                    if (*mvp == '\\' && (mvp > src))
846                    {
847                            /* move string one to the left */
848                            while (*(mvp + 1) != (char) 0x00)
849                            {
850                                    *mvp = *(mvp + 1);
851                                    *mvp++;
852                            }
853                            *mvp = (char) 0x00;
854                            p = nextval;
855                    }
856                    else
857                    {
858                            p = nextval + 1;
859                            break;
860                    }
861    
862            }
863    
864            /* more args available */
865            if (nextval)
866            {
867                    *nextval = (char) 0x00;
868                    return ++nextval;
869            }
870    
871            /* no more args after this, jump to EOS */
872            nextval = src + strlen(src);
873            return nextval;
874    }
875    
876    
877    void
878    toupper_str(char *p)
879    {
880            while (*p)
881            {
882                    if ((*p >= 'a') && (*p <= 'z'))
883                            *p = toupper((int) *p);
884                    p++;
885            }
886    }
887    
888    
889    /* not all clibs got ltoa */
890    #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
891    
892    char *
893    l_to_a(long N, int base)
894    {
895            static char ret[LTOA_BUFSIZE];
896    
897            char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
898    
899            register int divrem;
900    
901            if (base < 36 || 2 > base)
902                    base = 10;
903    
904            if (N < 0)
905            {
906                    *head++ = '-';
907                    N = -N;
908            }
909    
910            tail = buf + sizeof(buf);
911            *--tail = 0;
912    
913            do
914            {
915                    divrem = N % base;
916                    *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
917                    N /= base;
918            }
919            while (N);
920    
921            strcpy(head, tail);
922            return ret;
923    }
924    
925    
926  int  int
927  load_licence(unsigned char **data)  load_licence(unsigned char **data)
# Line 589  load_licence(unsigned char **data) Line 934  load_licence(unsigned char **data)
934          if (home == NULL)          if (home == NULL)
935                  return -1;                  return -1;
936    
937          path = xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
938          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
939    
940          fd = open(path, O_RDONLY);          fd = open(path, O_RDONLY);
# Line 599  load_licence(unsigned char **data) Line 944  load_licence(unsigned char **data)
944          if (fstat(fd, &st))          if (fstat(fd, &st))
945                  return -1;                  return -1;
946    
947          *data = xmalloc(st.st_size);          *data = (uint8 *) xmalloc(st.st_size);
948          length = read(fd, *data, st.st_size);          length = read(fd, *data, st.st_size);
949          close(fd);          close(fd);
950          xfree(path);          xfree(path);
# Line 616  save_licence(unsigned char *data, int le Line 961  save_licence(unsigned char *data, int le
961          if (home == NULL)          if (home == NULL)
962                  return;                  return;
963    
964          path = xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));          path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence."));
965    
966          sprintf(path, "%s/.rdesktop", home);          sprintf(path, "%s/.rdesktop", home);
967          if ((mkdir(path, 0700) == -1) && errno != EEXIST)          if ((mkdir(path, 0700) == -1) && errno != EEXIST)
# Line 628  save_licence(unsigned char *data, int le Line 973  save_licence(unsigned char *data, int le
973          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */          /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
974    
975          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);          sprintf(path, "%s/.rdesktop/licence.%s", home, hostname);
976          tmppath = xmalloc(strlen(path) + sizeof(".new"));          tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
977          strcpy(tmppath, path);          strcpy(tmppath, path);
978          strcat(tmppath, ".new");          strcat(tmppath, ".new");
979    
980          fd = open(tmppath, O_WRONLY|O_CREAT|O_TRUNC, 0600);          fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
981          if (fd == -1)          if (fd == -1)
982          {          {
983                  perror(tmppath);                  perror(tmppath);

Legend:
Removed from v.367  
changed lines
  Added in v.651

  ViewVC Help
Powered by ViewVC 1.1.26