ObjFW  Diff

Differences From Artifact [25a9151924]:

To Artifact [0370baa1c4]:


632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
			return false;
		if (memcmp(addrIPX1->sipx_node, addrIPX2->sipx_node,
		    IPX_NODE_LEN) != 0)
			return false;

		return true;
	case OFSocketAddressFamilyUNIX:
		/*
		 * This is a bit tricky. The only thing that is well-defined is
		 * the path. So compare the path, and if both don't have a
		 * path, compare bytes.
		 */

		if (address1->length != address2->length)
			return false;

		pool = objc_autoreleasePoolPush();

		path1 = OFSocketAddressUNIXPath(address1);
		path2 = OFSocketAddressUNIXPath(address2);

		if (path1 == nil && path2 == nil) {
			objc_autoreleasePoolPop(pool);

			return (memcmp(&address1->sockaddr.un,
			    &address2->sockaddr.un, address1->length) == 0);
		}

		if (path1 == nil || path2 == nil)
			ret = false;
		else
			ret = [path1 isEqual: path2];

		objc_autoreleasePoolPop(pool);

		return ret;
	default:
		@throw [OFInvalidArgumentException exception];
	}







<
<
<
<
<
<
<
<
<





|


|
<


<
<
<
|







632
633
634
635
636
637
638









639
640
641
642
643
644
645
646
647

648
649



650
651
652
653
654
655
656
657
			return false;
		if (memcmp(addrIPX1->sipx_node, addrIPX2->sipx_node,
		    IPX_NODE_LEN) != 0)
			return false;

		return true;
	case OFSocketAddressFamilyUNIX:









		pool = objc_autoreleasePoolPush();

		path1 = OFSocketAddressUNIXPath(address1);
		path2 = OFSocketAddressUNIXPath(address2);

		if (path1 == nil || path2 == nil) {
			objc_autoreleasePoolPop(pool);

			return false;

		}




		ret = [path1 isEqual: path2];

		objc_autoreleasePoolPop(pool);

		return ret;
	default:
		@throw [OFInvalidArgumentException exception];
	}
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
			OFHashAdd(&hash, network[i]);

		for (size_t i = 0; i < IPX_NODE_LEN; i++)
			OFHashAdd(&hash, address->sockaddr.ipx.sipx_node[i]);

		break;
	case OFSocketAddressFamilyUNIX:;
		/*
		 * This is a bit tricky. The only thing that is well-defined is
		 * the path. So hash the path if we have one, otherwise the
		 * bytes.
		 */
		void *pool = objc_autoreleasePoolPush();
		OFString *path = OFSocketAddressUNIXPath(address);

		if (path != nil) {
			hash = path.hash;
			objc_autoreleasePoolPop(pool);
			return hash;
		}

		objc_autoreleasePoolPop(pool);

		for (socklen_t i = 0; i < address->length; i++)
			OFHashAdd(&hash,
			    ((const char *)&address->sockaddr.un)[i]);

		break;
	default:
		@throw [OFInvalidArgumentException exception];
	}

	OFHashFinalize(&hash);

	return hash;







<
<
<
<
<



<
|
<
<
<



<
<
<
|
<







713
714
715
716
717
718
719





720
721
722

723



724
725
726



727

728
729
730
731
732
733
734
			OFHashAdd(&hash, network[i]);

		for (size_t i = 0; i < IPX_NODE_LEN; i++)
			OFHashAdd(&hash, address->sockaddr.ipx.sipx_node[i]);

		break;
	case OFSocketAddressFamilyUNIX:;





		void *pool = objc_autoreleasePoolPush();
		OFString *path = OFSocketAddressUNIXPath(address);


		hash = path.hash;




		objc_autoreleasePoolPop(pool);




		return hash;

	default:
		@throw [OFInvalidArgumentException exception];
	}

	OFHashFinalize(&hash);

	return hash;
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948



949
950
951
952
953

	memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN);
}

OFString *
OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address)
{
	socklen_t maxLength = (socklen_t)sizeof(address->sockaddr.un);
	size_t length;

	if (address->family != OFSocketAddressFamilyUNIX ||
	    address->length > maxLength)
		@throw [OFInvalidArgumentException exception];

	length = sizeof(address->sockaddr.un.sun_path) -
	    (maxLength - address->length);

	if (length == 0)
		return nil;




	return [OFString stringWithCString: address->sockaddr.un.sun_path
				  encoding: [OFLocale encoding]
				    length: length];
}







|











>
>
>





904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

	memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN);
}

OFString *
OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address)
{
	const socklen_t maxLength = (socklen_t)sizeof(address->sockaddr.un);
	size_t length;

	if (address->family != OFSocketAddressFamilyUNIX ||
	    address->length > maxLength)
		@throw [OFInvalidArgumentException exception];

	length = sizeof(address->sockaddr.un.sun_path) -
	    (maxLength - address->length);

	if (length == 0)
		return nil;

	while (address->sockaddr.un.sun_path[length - 1] == '\0')
		length--;

	return [OFString stringWithCString: address->sockaddr.un.sun_path
				  encoding: [OFLocale encoding]
				    length: length];
}