- New winsock (part 2 of x)
[reactos.git] / dll / win32 / mswsock / dns / string.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS DNS Shared Library
4 * FILE: lib/dnslib/string.c
5 * PURPOSE: functions for string manipulation and conversion.
6 */
7
8 /* INCLUDES ******************************************************************/
9 #include "precomp.h"
10
11 /* DATA **********************************************************************/
12
13 /* FUNCTIONS *****************************************************************/
14
15 ULONG
16 WINAPI
17 Dns_StringCopy(OUT PVOID Destination,
18 IN OUT PULONG DestinationSize,
19 IN PVOID String,
20 IN ULONG StringSize OPTIONAL,
21 IN DWORD InputType,
22 IN DWORD OutputType)
23 {
24 ULONG DestSize;
25 ULONG OutputSize = 0;
26
27 /* Check if the caller already gave us the string size */
28 if (!StringSize)
29 {
30 /* He didn't, get the input type */
31 if (InputType == UnicodeString)
32 {
33 /* Unicode string, calculate the size */
34 StringSize = (ULONG)wcslen((LPWSTR)String);
35 }
36 else
37 {
38 /* ANSI or UTF-8 sting, get the size */
39 StringSize = (ULONG)strlen((LPSTR)String);
40 }
41 }
42
43 /* Check if we have a limit on the desination size */
44 if (DestinationSize)
45 {
46 /* Make sure that we can respect it */
47 DestSize = Dns_GetBufferLengthForStringCopy(String,
48 StringSize,
49 InputType,
50 OutputType);
51 if (*DestinationSize < DestSize)
52 {
53 /* Fail due to missing buffer space */
54 SetLastError(ERROR_MORE_DATA);
55
56 /* Return how much data we actually need */
57 *DestinationSize = DestSize;
58 return 0;
59 }
60 else if (!DestSize)
61 {
62 /* Fail due to invalid data */
63 SetLastError(ERROR_INVALID_DATA);
64 return 0;
65 }
66
67 /* Return how much data we actually need */
68 *DestinationSize = DestSize;
69 }
70
71 /* Now check if this is a Unicode String as input */
72 if (InputType == UnicodeString)
73 {
74 /* Check if the output is ANSI */
75 if (OutputType == AnsiString)
76 {
77 /* Convert and return the final desination size */
78 OutputSize = WideCharToMultiByte(CP_ACP,
79 0,
80 String,
81 StringSize,
82 Destination,
83 -1,
84 NULL,
85 NULL) + 1;
86 }
87 else if (OutputType == UnicodeString)
88 {
89 /* Copy the string */
90 StringSize = StringSize * sizeof(WCHAR);
91 RtlMoveMemory(Destination, String, StringSize);
92
93 /* Return output length */
94 OutputSize = StringSize + 2;
95 }
96 else if (OutputType == Utf8String)
97 {
98 /* FIXME */
99 OutputSize = 0;
100 }
101 }
102 else if (InputType == AnsiString)
103 {
104 /* It's ANSI, is the output ansi too? */
105 if (OutputType == AnsiString)
106 {
107 /* Copy the string */
108 RtlMoveMemory(Destination, String, StringSize);
109
110 /* Return output length */
111 OutputSize = StringSize + 1;
112 }
113 else if (OutputType == UnicodeString)
114 {
115 /* Convert to Unicode and return size */
116 OutputSize = MultiByteToWideChar(CP_ACP,
117 0,
118 String,
119 StringSize,
120 Destination,
121 -1) * sizeof(WCHAR) + 2;
122 }
123 else if (OutputType == Utf8String)
124 {
125 /* FIXME */
126 OutputSize = 0;
127 }
128 }
129 else if (InputType == Utf8String)
130 {
131 /* FIXME */
132 OutputSize = 0;
133 }
134
135 /* Return the output size */
136 return OutputSize;
137 }
138
139 LPWSTR
140 WINAPI
141 Dns_CreateStringCopy_W(IN LPWSTR Name)
142 {
143 SIZE_T StringLength;
144 LPWSTR NameCopy;
145
146 /* Make sure that we have a name */
147 if (!Name)
148 {
149 /* Fail */
150 SetLastError(ERROR_INVALID_PARAMETER);
151 return NULL;
152 }
153
154 /* Find out the size of the string */
155 StringLength = (wcslen(Name) + 1) * sizeof(WCHAR);
156
157 /* Allocate space for the copy */
158 NameCopy = Dns_AllocZero(StringLength);
159 if (NameCopy)
160 {
161 /* Copy it */
162 RtlCopyMemory(NameCopy, Name, StringLength);
163 }
164 else
165 {
166 /* Fail */
167 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
168 }
169
170 /* Return the copy */
171 return NameCopy;
172 }
173
174 ULONG
175 WINAPI
176 Dns_GetBufferLengthForStringCopy(IN PVOID String,
177 IN ULONG Size OPTIONAL,
178 IN DWORD InputType,
179 IN DWORD OutputType)
180 {
181 ULONG OutputSize = 0;
182
183 /* Check what kind of string this is */
184 if (InputType == UnicodeString)
185 {
186 /* Check if we have a size */
187 if (!Size)
188 {
189 /* Get it ourselves */
190 Size = (ULONG)wcslen(String);
191 }
192
193 /* Check the output type */
194 if (OutputType == UnicodeString)
195 {
196 /* Convert the size to bytes */
197 OutputSize = (Size + 1) * sizeof(WCHAR);
198 }
199 else if (OutputType == Utf8String)
200 {
201 /* FIXME */
202 OutputSize = 0;
203 }
204 else
205 {
206 /* Find out how much it will be in ANSI bytes */
207 OutputSize = WideCharToMultiByte(CP_ACP,
208 0,
209 String,
210 Size,
211 NULL,
212 0,
213 NULL,
214 NULL) + 1;
215 }
216 }
217 else if (InputType == AnsiString)
218 {
219 /* Check if we have a size */
220 if (!Size)
221 {
222 /* Get it ourselves */
223 Size = (ULONG)strlen(String);
224 }
225
226 /* Check the output type */
227 if (OutputType == AnsiString)
228 {
229 /* Just add a byte for the null char */
230 OutputSize = Size + 1;
231 }
232 else if (OutputType == UnicodeString)
233 {
234 /* Calculate the bytes for a Unicode string */
235 OutputSize = (MultiByteToWideChar(CP_ACP,
236 0,
237 String,
238 Size,
239 NULL,
240 0) + 1) * sizeof(WCHAR);
241 }
242 else if (OutputType == Utf8String)
243 {
244 /* FIXME */
245 OutputSize = 0;
246 }
247 }
248 else if (InputType == Utf8String)
249 {
250 /* FIXME */
251 OutputSize = 0;
252 }
253
254 /* Return the size required */
255 return OutputSize;
256 }
257
258 /*
259 * COPYRIGHT: See COPYING in the top level directory
260 * PROJECT: ReactOS DNS Shared Library
261 * FILE: lib/dnslib/string.c
262 * PURPOSE: functions for string manipulation and conversion.
263 */
264
265 /* INCLUDES ******************************************************************/
266 #include "precomp.h"
267
268 /* DATA **********************************************************************/
269
270 /* FUNCTIONS *****************************************************************/
271
272 ULONG
273 WINAPI
274 Dns_StringCopy(OUT PVOID Destination,
275 IN OUT PULONG DestinationSize,
276 IN PVOID String,
277 IN ULONG StringSize OPTIONAL,
278 IN DWORD InputType,
279 IN DWORD OutputType)
280 {
281 ULONG DestSize;
282 ULONG OutputSize = 0;
283
284 /* Check if the caller already gave us the string size */
285 if (!StringSize)
286 {
287 /* He didn't, get the input type */
288 if (InputType == UnicodeString)
289 {
290 /* Unicode string, calculate the size */
291 StringSize = (ULONG)wcslen((LPWSTR)String);
292 }
293 else
294 {
295 /* ANSI or UTF-8 sting, get the size */
296 StringSize = (ULONG)strlen((LPSTR)String);
297 }
298 }
299
300 /* Check if we have a limit on the desination size */
301 if (DestinationSize)
302 {
303 /* Make sure that we can respect it */
304 DestSize = Dns_GetBufferLengthForStringCopy(String,
305 StringSize,
306 InputType,
307 OutputType);
308 if (*DestinationSize < DestSize)
309 {
310 /* Fail due to missing buffer space */
311 SetLastError(ERROR_MORE_DATA);
312
313 /* Return how much data we actually need */
314 *DestinationSize = DestSize;
315 return 0;
316 }
317 else if (!DestSize)
318 {
319 /* Fail due to invalid data */
320 SetLastError(ERROR_INVALID_DATA);
321 return 0;
322 }
323
324 /* Return how much data we actually need */
325 *DestinationSize = DestSize;
326 }
327
328 /* Now check if this is a Unicode String as input */
329 if (InputType == UnicodeString)
330 {
331 /* Check if the output is ANSI */
332 if (OutputType == AnsiString)
333 {
334 /* Convert and return the final desination size */
335 OutputSize = WideCharToMultiByte(CP_ACP,
336 0,
337 String,
338 StringSize,
339 Destination,
340 -1,
341 NULL,
342 NULL) + 1;
343 }
344 else if (OutputType == UnicodeString)
345 {
346 /* Copy the string */
347 StringSize = StringSize * sizeof(WCHAR);
348 RtlMoveMemory(Destination, String, StringSize);
349
350 /* Return output length */
351 OutputSize = StringSize + 2;
352 }
353 else if (OutputType == Utf8String)
354 {
355 /* FIXME */
356 OutputSize = 0;
357 }
358 }
359 else if (InputType == AnsiString)
360 {
361 /* It's ANSI, is the output ansi too? */
362 if (OutputType == AnsiString)
363 {
364 /* Copy the string */
365 RtlMoveMemory(Destination, String, StringSize);
366
367 /* Return output length */
368 OutputSize = StringSize + 1;
369 }
370 else if (OutputType == UnicodeString)
371 {
372 /* Convert to Unicode and return size */
373 OutputSize = MultiByteToWideChar(CP_ACP,
374 0,
375 String,
376 StringSize,
377 Destination,
378 -1) * sizeof(WCHAR) + 2;
379 }
380 else if (OutputType == Utf8String)
381 {
382 /* FIXME */
383 OutputSize = 0;
384 }
385 }
386 else if (InputType == Utf8String)
387 {
388 /* FIXME */
389 OutputSize = 0;
390 }
391
392 /* Return the output size */
393 return OutputSize;
394 }
395
396 LPWSTR
397 WINAPI
398 Dns_CreateStringCopy_W(IN LPWSTR Name)
399 {
400 SIZE_T StringLength;
401 LPWSTR NameCopy;
402
403 /* Make sure that we have a name */
404 if (!Name)
405 {
406 /* Fail */
407 SetLastError(ERROR_INVALID_PARAMETER);
408 return NULL;
409 }
410
411 /* Find out the size of the string */
412 StringLength = (wcslen(Name) + 1) * sizeof(WCHAR);
413
414 /* Allocate space for the copy */
415 NameCopy = Dns_AllocZero(StringLength);
416 if (NameCopy)
417 {
418 /* Copy it */
419 RtlCopyMemory(NameCopy, Name, StringLength);
420 }
421 else
422 {
423 /* Fail */
424 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
425 }
426
427 /* Return the copy */
428 return NameCopy;
429 }
430
431 ULONG
432 WINAPI
433 Dns_GetBufferLengthForStringCopy(IN PVOID String,
434 IN ULONG Size OPTIONAL,
435 IN DWORD InputType,
436 IN DWORD OutputType)
437 {
438 ULONG OutputSize = 0;
439
440 /* Check what kind of string this is */
441 if (InputType == UnicodeString)
442 {
443 /* Check if we have a size */
444 if (!Size)
445 {
446 /* Get it ourselves */
447 Size = (ULONG)wcslen(String);
448 }
449
450 /* Check the output type */
451 if (OutputType == UnicodeString)
452 {
453 /* Convert the size to bytes */
454 OutputSize = (Size + 1) * sizeof(WCHAR);
455 }
456 else if (OutputType == Utf8String)
457 {
458 /* FIXME */
459 OutputSize = 0;
460 }
461 else
462 {
463 /* Find out how much it will be in ANSI bytes */
464 OutputSize = WideCharToMultiByte(CP_ACP,
465 0,
466 String,
467 Size,
468 NULL,
469 0,
470 NULL,
471 NULL) + 1;
472 }
473 }
474 else if (InputType == AnsiString)
475 {
476 /* Check if we have a size */
477 if (!Size)
478 {
479 /* Get it ourselves */
480 Size = (ULONG)strlen(String);
481 }
482
483 /* Check the output type */
484 if (OutputType == AnsiString)
485 {
486 /* Just add a byte for the null char */
487 OutputSize = Size + 1;
488 }
489 else if (OutputType == UnicodeString)
490 {
491 /* Calculate the bytes for a Unicode string */
492 OutputSize = (MultiByteToWideChar(CP_ACP,
493 0,
494 String,
495 Size,
496 NULL,
497 0) + 1) * sizeof(WCHAR);
498 }
499 else if (OutputType == Utf8String)
500 {
501 /* FIXME */
502 OutputSize = 0;
503 }
504 }
505 else if (InputType == Utf8String)
506 {
507 /* FIXME */
508 OutputSize = 0;
509 }
510
511 /* Return the size required */
512 return OutputSize;
513 }
514
515 /*
516 * COPYRIGHT: See COPYING in the top level directory
517 * PROJECT: ReactOS DNS Shared Library
518 * FILE: lib/dnslib/string.c
519 * PURPOSE: functions for string manipulation and conversion.
520 */
521
522 /* INCLUDES ******************************************************************/
523 #include "precomp.h"
524
525 /* DATA **********************************************************************/
526
527 /* FUNCTIONS *****************************************************************/
528
529 ULONG
530 WINAPI
531 Dns_StringCopy(OUT PVOID Destination,
532 IN OUT PULONG DestinationSize,
533 IN PVOID String,
534 IN ULONG StringSize OPTIONAL,
535 IN DWORD InputType,
536 IN DWORD OutputType)
537 {
538 ULONG DestSize;
539 ULONG OutputSize = 0;
540
541 /* Check if the caller already gave us the string size */
542 if (!StringSize)
543 {
544 /* He didn't, get the input type */
545 if (InputType == UnicodeString)
546 {
547 /* Unicode string, calculate the size */
548 StringSize = (ULONG)wcslen((LPWSTR)String);
549 }
550 else
551 {
552 /* ANSI or UTF-8 sting, get the size */
553 StringSize = (ULONG)strlen((LPSTR)String);
554 }
555 }
556
557 /* Check if we have a limit on the desination size */
558 if (DestinationSize)
559 {
560 /* Make sure that we can respect it */
561 DestSize = Dns_GetBufferLengthForStringCopy(String,
562 StringSize,
563 InputType,
564 OutputType);
565 if (*DestinationSize < DestSize)
566 {
567 /* Fail due to missing buffer space */
568 SetLastError(ERROR_MORE_DATA);
569
570 /* Return how much data we actually need */
571 *DestinationSize = DestSize;
572 return 0;
573 }
574 else if (!DestSize)
575 {
576 /* Fail due to invalid data */
577 SetLastError(ERROR_INVALID_DATA);
578 return 0;
579 }
580
581 /* Return how much data we actually need */
582 *DestinationSize = DestSize;
583 }
584
585 /* Now check if this is a Unicode String as input */
586 if (InputType == UnicodeString)
587 {
588 /* Check if the output is ANSI */
589 if (OutputType == AnsiString)
590 {
591 /* Convert and return the final desination size */
592 OutputSize = WideCharToMultiByte(CP_ACP,
593 0,
594 String,
595 StringSize,
596 Destination,
597 -1,
598 NULL,
599 NULL) + 1;
600 }
601 else if (OutputType == UnicodeString)
602 {
603 /* Copy the string */
604 StringSize = StringSize * sizeof(WCHAR);
605 RtlMoveMemory(Destination, String, StringSize);
606
607 /* Return output length */
608 OutputSize = StringSize + 2;
609 }
610 else if (OutputType == Utf8String)
611 {
612 /* FIXME */
613 OutputSize = 0;
614 }
615 }
616 else if (InputType == AnsiString)
617 {
618 /* It's ANSI, is the output ansi too? */
619 if (OutputType == AnsiString)
620 {
621 /* Copy the string */
622 RtlMoveMemory(Destination, String, StringSize);
623
624 /* Return output length */
625 OutputSize = StringSize + 1;
626 }
627 else if (OutputType == UnicodeString)
628 {
629 /* Convert to Unicode and return size */
630 OutputSize = MultiByteToWideChar(CP_ACP,
631 0,
632 String,
633 StringSize,
634 Destination,
635 -1) * sizeof(WCHAR) + 2;
636 }
637 else if (OutputType == Utf8String)
638 {
639 /* FIXME */
640 OutputSize = 0;
641 }
642 }
643 else if (InputType == Utf8String)
644 {
645 /* FIXME */
646 OutputSize = 0;
647 }
648
649 /* Return the output size */
650 return OutputSize;
651 }
652
653 LPWSTR
654 WINAPI
655 Dns_CreateStringCopy_W(IN LPWSTR Name)
656 {
657 SIZE_T StringLength;
658 LPWSTR NameCopy;
659
660 /* Make sure that we have a name */
661 if (!Name)
662 {
663 /* Fail */
664 SetLastError(ERROR_INVALID_PARAMETER);
665 return NULL;
666 }
667
668 /* Find out the size of the string */
669 StringLength = (wcslen(Name) + 1) * sizeof(WCHAR);
670
671 /* Allocate space for the copy */
672 NameCopy = Dns_AllocZero(StringLength);
673 if (NameCopy)
674 {
675 /* Copy it */
676 RtlCopyMemory(NameCopy, Name, StringLength);
677 }
678 else
679 {
680 /* Fail */
681 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
682 }
683
684 /* Return the copy */
685 return NameCopy;
686 }
687
688 ULONG
689 WINAPI
690 Dns_GetBufferLengthForStringCopy(IN PVOID String,
691 IN ULONG Size OPTIONAL,
692 IN DWORD InputType,
693 IN DWORD OutputType)
694 {
695 ULONG OutputSize = 0;
696
697 /* Check what kind of string this is */
698 if (InputType == UnicodeString)
699 {
700 /* Check if we have a size */
701 if (!Size)
702 {
703 /* Get it ourselves */
704 Size = (ULONG)wcslen(String);
705 }
706
707 /* Check the output type */
708 if (OutputType == UnicodeString)
709 {
710 /* Convert the size to bytes */
711 OutputSize = (Size + 1) * sizeof(WCHAR);
712 }
713 else if (OutputType == Utf8String)
714 {
715 /* FIXME */
716 OutputSize = 0;
717 }
718 else
719 {
720 /* Find out how much it will be in ANSI bytes */
721 OutputSize = WideCharToMultiByte(CP_ACP,
722 0,
723 String,
724 Size,
725 NULL,
726 0,
727 NULL,
728 NULL) + 1;
729 }
730 }
731 else if (InputType == AnsiString)
732 {
733 /* Check if we have a size */
734 if (!Size)
735 {
736 /* Get it ourselves */
737 Size = (ULONG)strlen(String);
738 }
739
740 /* Check the output type */
741 if (OutputType == AnsiString)
742 {
743 /* Just add a byte for the null char */
744 OutputSize = Size + 1;
745 }
746 else if (OutputType == UnicodeString)
747 {
748 /* Calculate the bytes for a Unicode string */
749 OutputSize = (MultiByteToWideChar(CP_ACP,
750 0,
751 String,
752 Size,
753 NULL,
754 0) + 1) * sizeof(WCHAR);
755 }
756 else if (OutputType == Utf8String)
757 {
758 /* FIXME */
759 OutputSize = 0;
760 }
761 }
762 else if (InputType == Utf8String)
763 {
764 /* FIXME */
765 OutputSize = 0;
766 }
767
768 /* Return the size required */
769 return OutputSize;
770 }
771
772 /*
773 * COPYRIGHT: See COPYING in the top level directory
774 * PROJECT: ReactOS DNS Shared Library
775 * FILE: lib/dnslib/string.c
776 * PURPOSE: functions for string manipulation and conversion.
777 */
778
779 /* INCLUDES ******************************************************************/
780 #include "precomp.h"
781
782 /* DATA **********************************************************************/
783
784 /* FUNCTIONS *****************************************************************/
785
786 ULONG
787 WINAPI
788 Dns_StringCopy(OUT PVOID Destination,
789 IN OUT PULONG DestinationSize,
790 IN PVOID String,
791 IN ULONG StringSize OPTIONAL,
792 IN DWORD InputType,
793 IN DWORD OutputType)
794 {
795 ULONG DestSize;
796 ULONG OutputSize = 0;
797
798 /* Check if the caller already gave us the string size */
799 if (!StringSize)
800 {
801 /* He didn't, get the input type */
802 if (InputType == UnicodeString)
803 {
804 /* Unicode string, calculate the size */
805 StringSize = (ULONG)wcslen((LPWSTR)String);
806 }
807 else
808 {
809 /* ANSI or UTF-8 sting, get the size */
810 StringSize = (ULONG)strlen((LPSTR)String);
811 }
812 }
813
814 /* Check if we have a limit on the desination size */
815 if (DestinationSize)
816 {
817 /* Make sure that we can respect it */
818 DestSize = Dns_GetBufferLengthForStringCopy(String,
819 StringSize,
820 InputType,
821 OutputType);
822 if (*DestinationSize < DestSize)
823 {
824 /* Fail due to missing buffer space */
825 SetLastError(ERROR_MORE_DATA);
826
827 /* Return how much data we actually need */
828 *DestinationSize = DestSize;
829 return 0;
830 }
831 else if (!DestSize)
832 {
833 /* Fail due to invalid data */
834 SetLastError(ERROR_INVALID_DATA);
835 return 0;
836 }
837
838 /* Return how much data we actually need */
839 *DestinationSize = DestSize;
840 }
841
842 /* Now check if this is a Unicode String as input */
843 if (InputType == UnicodeString)
844 {
845 /* Check if the output is ANSI */
846 if (OutputType == AnsiString)
847 {
848 /* Convert and return the final desination size */
849 OutputSize = WideCharToMultiByte(CP_ACP,
850 0,
851 String,
852 StringSize,
853 Destination,
854 -1,
855 NULL,
856 NULL) + 1;
857 }
858 else if (OutputType == UnicodeString)
859 {
860 /* Copy the string */
861 StringSize = StringSize * sizeof(WCHAR);
862 RtlMoveMemory(Destination, String, StringSize);
863
864 /* Return output length */
865 OutputSize = StringSize + 2;
866 }
867 else if (OutputType == Utf8String)
868 {
869 /* FIXME */
870 OutputSize = 0;
871 }
872 }
873 else if (InputType == AnsiString)
874 {
875 /* It's ANSI, is the output ansi too? */
876 if (OutputType == AnsiString)
877 {
878 /* Copy the string */
879 RtlMoveMemory(Destination, String, StringSize);
880
881 /* Return output length */
882 OutputSize = StringSize + 1;
883 }
884 else if (OutputType == UnicodeString)
885 {
886 /* Convert to Unicode and return size */
887 OutputSize = MultiByteToWideChar(CP_ACP,
888 0,
889 String,
890 StringSize,
891 Destination,
892 -1) * sizeof(WCHAR) + 2;
893 }
894 else if (OutputType == Utf8String)
895 {
896 /* FIXME */
897 OutputSize = 0;
898 }
899 }
900 else if (InputType == Utf8String)
901 {
902 /* FIXME */
903 OutputSize = 0;
904 }
905
906 /* Return the output size */
907 return OutputSize;
908 }
909
910 LPWSTR
911 WINAPI
912 Dns_CreateStringCopy_W(IN LPWSTR Name)
913 {
914 SIZE_T StringLength;
915 LPWSTR NameCopy;
916
917 /* Make sure that we have a name */
918 if (!Name)
919 {
920 /* Fail */
921 SetLastError(ERROR_INVALID_PARAMETER);
922 return NULL;
923 }
924
925 /* Find out the size of the string */
926 StringLength = (wcslen(Name) + 1) * sizeof(WCHAR);
927
928 /* Allocate space for the copy */
929 NameCopy = Dns_AllocZero(StringLength);
930 if (NameCopy)
931 {
932 /* Copy it */
933 RtlCopyMemory(NameCopy, Name, StringLength);
934 }
935 else
936 {
937 /* Fail */
938 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
939 }
940
941 /* Return the copy */
942 return NameCopy;
943 }
944
945 ULONG
946 WINAPI
947 Dns_GetBufferLengthForStringCopy(IN PVOID String,
948 IN ULONG Size OPTIONAL,
949 IN DWORD InputType,
950 IN DWORD OutputType)
951 {
952 ULONG OutputSize = 0;
953
954 /* Check what kind of string this is */
955 if (InputType == UnicodeString)
956 {
957 /* Check if we have a size */
958 if (!Size)
959 {
960 /* Get it ourselves */
961 Size = (ULONG)wcslen(String);
962 }
963
964 /* Check the output type */
965 if (OutputType == UnicodeString)
966 {
967 /* Convert the size to bytes */
968 OutputSize = (Size + 1) * sizeof(WCHAR);
969 }
970 else if (OutputType == Utf8String)
971 {
972 /* FIXME */
973 OutputSize = 0;
974 }
975 else
976 {
977 /* Find out how much it will be in ANSI bytes */
978 OutputSize = WideCharToMultiByte(CP_ACP,
979 0,
980 String,
981 Size,
982 NULL,
983 0,
984 NULL,
985 NULL) + 1;
986 }
987 }
988 else if (InputType == AnsiString)
989 {
990 /* Check if we have a size */
991 if (!Size)
992 {
993 /* Get it ourselves */
994 Size = (ULONG)strlen(String);
995 }
996
997 /* Check the output type */
998 if (OutputType == AnsiString)
999 {
1000 /* Just add a byte for the null char */
1001 OutputSize = Size + 1;
1002 }
1003 else if (OutputType == UnicodeString)
1004 {
1005 /* Calculate the bytes for a Unicode string */
1006 OutputSize = (MultiByteToWideChar(CP_ACP,
1007 0,
1008 String,
1009 Size,
1010 NULL,
1011 0) + 1) * sizeof(WCHAR);
1012 }
1013 else if (OutputType == Utf8String)
1014 {
1015 /* FIXME */
1016 OutputSize = 0;
1017 }
1018 }
1019 else if (InputType == Utf8String)
1020 {
1021 /* FIXME */
1022 OutputSize = 0;
1023 }
1024
1025 /* Return the size required */
1026 return OutputSize;
1027 }
1028