Codebase list virt-viewer / e2df5a7
util: Replace virt_viewer_compare_version with _compare_buildid This allows us to do a more accurate version check if the .vv file producer wants to allow builds newer than x.y-z because they contain an important bug fix. Christophe Fergeau 8 years ago
4 changed file(s) with 61 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
140140 If remote-viewer version number isn't greater or equal to the required
141141 version, an error is raised with the expected version.
142142
143 The version format accepted is a list of integers separated by '.'.
143 The version format accepted is a list of integers separated by '.'. It can
144 be followed by a dash '-' and an additional build number with the same format.
144145
145146 Version comparison is done by comparing each integer from the list one by
146147 one. If any of the component is not a number, the version comparison will fail
795795 if (min_version == NULL) {
796796 return TRUE;
797797 }
798
799 version_cmp = virt_viewer_compare_version(min_version, PACKAGE_VERSION);
798 version_cmp = virt_viewer_compare_buildid(min_version, PACKAGE_VERSION BUILDID);
800799
801800 if (version_cmp > 0) {
802801 g_set_error(error,
00 /*
11 * Virt Viewer: A virtual machine console viewer
22 *
3 * Copyright (C) 2007-2012 Red Hat, Inc.
3 * Copyright (C) 2007-2015 Red Hat, Inc.
44 * Copyright (C) 2009-2012 Daniel P. Berrange
55 *
66 * This program is free software; you can redistribute it and/or modify
438438 return accel;
439439 }
440440
441 /**
442 * virt_viewer_compare_version:
443 * @s1: a version-like string
444 * @s2: a version-like string
445 *
446 * Compare two version-like strings: 1.1 > 1.0, 1.0.1 > 1.0, 1.10 > 1.7...
447 *
448 * String suffix (1.0rc1 etc) are not accepted, and will return 0.
449 *
450 * Returns: negative value if s1 < s2; zero if s1 = s2; positive value if s1 > s2.
451 **/
452 gint
441 static gboolean str_is_empty(const gchar *str)
442 {
443 return ((str == NULL) || (str[0] == '\0'));
444 }
445
446 static gint
453447 virt_viewer_compare_version(const gchar *s1, const gchar *s2)
454448 {
455449 gint i, retval = 0;
456450 gchar **v1, **v2;
457451
458 g_return_val_if_fail(s1 != NULL, 0);
459 g_return_val_if_fail(s2 != NULL, 0);
452 if (str_is_empty(s1) && str_is_empty(s2)) {
453 return 0;
454 } else if (str_is_empty(s1)) {
455 return -1;
456 } else if (str_is_empty(s2)) {
457 return 1;
458 }
460459
461460 v1 = g_strsplit(s1, ".", -1);
462461 v2 = g_strsplit(s2, ".", -1);
472471
473472 g_return_val_if_fail(e1 && e2, 0);
474473 if (*e1 || *e2) {
475 g_warning("the version string contains suffix");
474 g_warning("the version string contains a suffix");
476475 goto end;
477476 }
478477 }
486485 g_strfreev(v1);
487486 g_strfreev(v2);
488487 return retval;
488 }
489
490 /**
491 * virt_viewer_compare_buildid:
492 * @s1: a version-like string
493 * @s2: a version-like string
494 *
495 * Compare two buildid strings: 1.1-1 > 1.0-1, 1.0-2 > 1.0-1, 1.10 > 1.7...
496 *
497 * String suffix (1.0rc1 etc) are not accepted, and will return 0.
498 *
499 * Returns: negative value if s1 < s2; zero if s1 = s2; positive value if s1 > s2.
500 **/
501 gint
502 virt_viewer_compare_buildid(const gchar *s1, const gchar *s2)
503 {
504 int ret = 0;
505 GStrv split1 = NULL;
506 GStrv split2 = NULL;
507
508 split1 = g_strsplit(s1, "-", 2);
509 split2 = g_strsplit(s2, "-", 2);
510 if ((split1 == NULL) || (split2 == NULL)) {
511 goto end;
512 }
513 /* Compare versions */
514 ret = virt_viewer_compare_version(split1[0], split2[0]);
515 if (ret != 0) {
516 goto end;
517 }
518 if ((split1[0] == NULL) || (split2[0] == NULL)) {
519 goto end;
520 }
521
522 /* Compare -release */
523 ret = virt_viewer_compare_version(split1[1], split2[1]);
524
525 end:
526 g_strfreev(split1);
527 g_strfreev(split2);
528
529 return ret;
489530 }
490531
491532 /* simple sorting of monitors. Primary sort left-to-right, secondary sort from
5353 GConnectFlags connect_flags);
5454
5555 gchar* spice_hotkey_to_gtk_accelerator(const gchar *key);
56 gint virt_viewer_compare_version(const gchar *s1, const gchar *s2);
56 gint virt_viewer_compare_buildid(const gchar *s1, const gchar *s2);
5757
5858 /* monitor alignment */
5959 void virt_viewer_align_monitors_linear(GdkRectangle *displays, guint ndisplays);