1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 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 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 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 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 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 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
// // DO NOT EDIT. THIS FILE IS GENERATED FROM ../../../dist/idl/nsIHttpServer.idl // /// `interface nsIHttpServer : nsISupports` /// // The actual type definition for the interface. This struct has methods // declared on it which will call through its vtable. You never want to pass // this type around by value, always pass it behind a reference. #[repr(C)] pub struct nsIHttpServer { vtable: *const nsIHttpServerVTable, /// This field is a phantomdata to ensure that the VTable type and any /// struct containing it is not safe to send across threads, as XPCOM is /// generally not threadsafe. /// /// XPCOM interfaces in general are not safe to send across threads. __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>, } // Implementing XpCom for an interface exposes its IID, which allows for easy // use of the `.query_interface<T>` helper method. This also defines that // method for nsIHttpServer. unsafe impl XpCom for nsIHttpServer { const IID: nsIID = nsID(0xcea8812e, 0xfaa6, 0x4013, [0x93, 0x96, 0xf9, 0x93, 0x6c, 0xbb, 0x74, 0xec]); } // We need to implement the RefCounted trait so we can be used with `RefPtr`. // This trait teaches `RefPtr` how to manage our memory. unsafe impl RefCounted for nsIHttpServer { #[inline] unsafe fn addref(&self) { self.AddRef(); } #[inline] unsafe fn release(&self) { self.Release(); } } // This trait is implemented on all types which can be coerced to from nsIHttpServer. // It is used in the implementation of `fn coerce<T>`. We hide it from the // documentation, because it clutters it up a lot. #[doc(hidden)] pub trait nsIHttpServerCoerce { /// Cheaply cast a value of this type from a `nsIHttpServer`. fn coerce_from(v: &nsIHttpServer) -> &Self; } // The trivial implementation: We can obviously coerce ourselves to ourselves. impl nsIHttpServerCoerce for nsIHttpServer { #[inline] fn coerce_from(v: &nsIHttpServer) -> &Self { v } } impl nsIHttpServer { /// Cast this `nsIHttpServer` to one of its base interfaces. #[inline] pub fn coerce<T: nsIHttpServerCoerce>(&self) -> &T { T::coerce_from(self) } } // Every interface struct type implements `Deref` to its base interface. This // causes methods on the base interfaces to be directly avaliable on the // object. For example, you can call `.AddRef` or `.QueryInterface` directly // on any interface which inherits from `nsISupports`. impl ::std::ops::Deref for nsIHttpServer { type Target = nsISupports; #[inline] fn deref(&self) -> &nsISupports { unsafe { ::std::mem::transmute(self) } } } // Ensure we can use .coerce() to cast to our base types as well. Any type which // our base interface can coerce from should be coercable from us as well. impl<T: nsISupportsCoerce> nsIHttpServerCoerce for T { #[inline] fn coerce_from(v: &nsIHttpServer) -> &Self { T::coerce_from(v) } } // This struct represents the interface's VTable. A pointer to a statically // allocated version of this struct is at the beginning of every nsIHttpServer // object. It contains one pointer field for each method in the interface. In // the case where we can't generate a binding for a method, we include a void // pointer. #[doc(hidden)] #[repr(C)] pub struct nsIHttpServerVTable { /// We need to include the members from the base interface's vtable at the start /// of the VTable definition. pub __base: nsISupportsVTable, /* void start (in long port); */ pub Start: unsafe extern "system" fn (this: *const nsIHttpServer, port: libc::int32_t) -> nsresult, /* void stop (in nsIHttpServerStoppedCallback callback); */ pub Stop: unsafe extern "system" fn (this: *const nsIHttpServer, callback: *const nsIHttpServerStoppedCallback) -> nsresult, /* void registerFile (in string path, in nsIFile file); */ pub RegisterFile: unsafe extern "system" fn (this: *const nsIHttpServer, path: *const libc::c_char, file: *const nsIFile) -> nsresult, /* void registerPathHandler (in string path, in nsIHttpRequestHandler handler); */ pub RegisterPathHandler: unsafe extern "system" fn (this: *const nsIHttpServer, path: *const libc::c_char, handler: *const nsIHttpRequestHandler) -> nsresult, /* void registerPrefixHandler (in string prefix, in nsIHttpRequestHandler handler); */ pub RegisterPrefixHandler: unsafe extern "system" fn (this: *const nsIHttpServer, prefix: *const libc::c_char, handler: *const nsIHttpRequestHandler) -> nsresult, /* void registerErrorHandler (in unsigned long code, in nsIHttpRequestHandler handler); */ pub RegisterErrorHandler: unsafe extern "system" fn (this: *const nsIHttpServer, code: libc::uint32_t, handler: *const nsIHttpRequestHandler) -> nsresult, /* void registerDirectory (in string path, in nsIFile dir); */ pub RegisterDirectory: unsafe extern "system" fn (this: *const nsIHttpServer, path: *const libc::c_char, dir: *const nsIFile) -> nsresult, /* void registerContentType (in string extension, in string type); */ pub RegisterContentType: unsafe extern "system" fn (this: *const nsIHttpServer, extension: *const libc::c_char, type_: *const libc::c_char) -> nsresult, /* void setIndexHandler (in nsIHttpRequestHandler handler); */ pub SetIndexHandler: unsafe extern "system" fn (this: *const nsIHttpServer, handler: *const nsIHttpRequestHandler) -> nsresult, /* readonly attribute nsIHttpServerIdentity identity; */ pub GetIdentity: unsafe extern "system" fn (this: *const nsIHttpServer, aIdentity: *mut *const nsIHttpServerIdentity) -> nsresult, /* AString getState (in AString path, in AString key); */ pub GetState: unsafe extern "system" fn (this: *const nsIHttpServer, path: &::nsstring::nsAString, key: &::nsstring::nsAString, _retval: &mut ::nsstring::nsAString) -> nsresult, /* void setState (in AString path, in AString key, in AString value); */ pub SetState: unsafe extern "system" fn (this: *const nsIHttpServer, path: &::nsstring::nsAString, key: &::nsstring::nsAString, value: &::nsstring::nsAString) -> nsresult, /* AString getSharedState (in AString key); */ pub GetSharedState: unsafe extern "system" fn (this: *const nsIHttpServer, key: &::nsstring::nsAString, _retval: &mut ::nsstring::nsAString) -> nsresult, /* void setSharedState (in AString key, in AString value); */ pub SetSharedState: unsafe extern "system" fn (this: *const nsIHttpServer, key: &::nsstring::nsAString, value: &::nsstring::nsAString) -> nsresult, /* nsISupports getObjectState (in AString key); */ pub GetObjectState: unsafe extern "system" fn (this: *const nsIHttpServer, key: &::nsstring::nsAString, _retval: *mut *const nsISupports) -> nsresult, /* void setObjectState (in AString key, in nsISupports value); */ pub SetObjectState: unsafe extern "system" fn (this: *const nsIHttpServer, key: &::nsstring::nsAString, value: *const nsISupports) -> nsresult, } // The implementations of the function wrappers which are exposed to rust code. // Call these methods rather than manually calling through the VTable struct. impl nsIHttpServer { /// ```text /// /** /// * An interface which represents an HTTP server. /// */ /// /** /// * Starts up this server, listening upon the given port. /// * /// * @param port /// * the port upon which listening should happen, or -1 if no specific port is /// * desired /// * @throws NS_ERROR_ALREADY_INITIALIZED /// * if this server is already started /// * @throws NS_ERROR_NOT_AVAILABLE /// * if the server is not started and cannot be started on the desired port /// * (perhaps because the port is already in use or because the process does /// * not have privileges to do so) /// * @note /// * Behavior is undefined if this method is called after stop() has been /// * called on this but before the provided callback function has been /// * called. /// */ /// ``` /// /// `void start (in long port);` #[inline] pub unsafe fn Start(&self, port: libc::int32_t) -> nsresult { ((*self.vtable).Start)(self, port) } /// ```text /// /** /// * Shuts down this server if it is running (including the period of time after /// * stop() has been called but before the provided callback has been called). /// * /// * @param callback /// * an asynchronous callback used to notify the user when this server is /// * stopped and all pending requests have been fully served /// * @throws NS_ERROR_NULL_POINTER /// * if callback is null /// * @throws NS_ERROR_UNEXPECTED /// * if this server is not running /// */ /// ``` /// /// `void stop (in nsIHttpServerStoppedCallback callback);` #[inline] pub unsafe fn Stop(&self, callback: *const nsIHttpServerStoppedCallback) -> nsresult { ((*self.vtable).Stop)(self, callback) } /// ```text /// /** /// * Associates the local file represented by the string file with all requests /// * which match request. /// * /// * @param path /// * the path which is to be mapped to the given file; must begin with "/" and /// * be a valid URI path (i.e., no query string, hash reference, etc.) /// * @param file /// * the file to serve for the given path, or null to remove any mapping that /// * might exist; this file must exist for the lifetime of the server /// */ /// ``` /// /// `void registerFile (in string path, in nsIFile file);` #[inline] pub unsafe fn RegisterFile(&self, path: *const libc::c_char, file: *const nsIFile) -> nsresult { ((*self.vtable).RegisterFile)(self, path, file) } /// ```text /// /** /// * Registers a custom path handler. /// * /// * @param path /// * the path on the server (beginning with a "/") which is to be handled by /// * handler; this path must not include a query string or hash component; it /// * also should usually be canonicalized, since most browsers will do so /// * before sending otherwise-matching requests /// * @param handler /// * an object which will handle any requests for the given path, or null to /// * remove any existing handler; if while the server is running the handler /// * throws an exception while responding to a request, an HTTP 500 response /// * will be returned /// * @throws NS_ERROR_INVALID_ARG /// * if path does not begin with a "/" /// */ /// ``` /// /// `void registerPathHandler (in string path, in nsIHttpRequestHandler handler);` #[inline] pub unsafe fn RegisterPathHandler(&self, path: *const libc::c_char, handler: *const nsIHttpRequestHandler) -> nsresult { ((*self.vtable).RegisterPathHandler)(self, path, handler) } /// ```text /// /** /// * Registers a custom prefix handler. /// * /// * @param prefix /// * the path on the server (beginning and ending with "/") which is to be /// * handled by handler; this path must not include a query string or hash /// * component. All requests that start with this prefix will be directed to /// * the given handler. /// * @param handler /// * an object which will handle any requests for the given path, or null to /// * remove any existing handler; if while the server is running the handler /// * throws an exception while responding to a request, an HTTP 500 response /// * will be returned /// * @throws NS_ERROR_INVALID_ARG /// * if path does not begin with a "/" or does not end with a "/" /// */ /// ``` /// /// `void registerPrefixHandler (in string prefix, in nsIHttpRequestHandler handler);` #[inline] pub unsafe fn RegisterPrefixHandler(&self, prefix: *const libc::c_char, handler: *const nsIHttpRequestHandler) -> nsresult { ((*self.vtable).RegisterPrefixHandler)(self, prefix, handler) } /// ```text /// /** /// * Registers a custom error page handler. /// * /// * @param code /// * the error code which is to be handled by handler /// * @param handler /// * an object which will handle any requests which generate the given status /// * code, or null to remove any existing handler. If the handler throws an /// * exception during server operation, fallback is to the genericized error /// * handler (the x00 version), then to 500, using a user-defined error /// * handler if one exists or the server default handler otherwise. Fallback /// * will never occur from a user-provided handler that throws to the same /// * handler as provided by the server, e.g. a throwing user 404 falls back to /// * 400, not a server-provided 404 that might not throw. /// * @note /// * If the error handler handles HTTP 500 and throws, behavior is undefined. /// */ /// ``` /// /// `void registerErrorHandler (in unsigned long code, in nsIHttpRequestHandler handler);` #[inline] pub unsafe fn RegisterErrorHandler(&self, code: libc::uint32_t, handler: *const nsIHttpRequestHandler) -> nsresult { ((*self.vtable).RegisterErrorHandler)(self, code, handler) } /// ```text /// /** /// * Maps all requests to paths beneath path to the corresponding file beneath /// * dir. /// * /// * @param path /// * the absolute path on the server against which requests will be served /// * from dir (e.g., "/", "/foo/", etc.); must begin and end with a forward /// * slash /// * @param dir /// * the directory to be used to serve all requests for paths underneath path /// * (except those further overridden by another, deeper path registered with /// * another directory); if null, any current mapping for the given path is /// * removed /// * @throws NS_ERROR_INVALID_ARG /// * if dir is non-null and does not exist or is not a directory, or if path /// * does not begin with and end with a forward slash /// */ /// ``` /// /// `void registerDirectory (in string path, in nsIFile dir);` #[inline] pub unsafe fn RegisterDirectory(&self, path: *const libc::c_char, dir: *const nsIFile) -> nsresult { ((*self.vtable).RegisterDirectory)(self, path, dir) } /// ```text /// /** /// * Associates files with the given extension with the given Content-Type when /// * served by this server, in the absence of any file-specific information /// * about the desired Content-Type. If type is empty, removes any extant /// * mapping, if one is present. /// * /// * @throws NS_ERROR_INVALID_ARG /// * if the given type is not a valid header field value, i.e. if it doesn't /// * match the field-value production in RFC 2616 /// * @note /// * No syntax checking is done of the given type, beyond ensuring that it is /// * a valid header field value. Behavior when not given a string matching /// * the media-type production in RFC 2616 section 3.7 is undefined. /// * Implementations may choose to define specific behavior for types which do /// * not match the production, such as for CGI functionality. /// * @note /// * Implementations MAY treat type as a trusted argument; users who fail to /// * generate this string from trusted data risk security vulnerabilities. /// */ /// ``` /// /// `void registerContentType (in string extension, in string type);` #[inline] pub unsafe fn RegisterContentType(&self, extension: *const libc::c_char, type_: *const libc::c_char) -> nsresult { ((*self.vtable).RegisterContentType)(self, extension, type_) } /// ```text /// /** /// * Sets the handler used to display the contents of a directory if /// * the directory contains no index page. /// * /// * @param handler /// * an object which will handle any requests for directories which /// * do not contain index pages, or null to reset to the default /// * index handler; if while the server is running the handler /// * throws an exception while responding to a request, an HTTP 500 /// * response will be returned. An nsIFile corresponding to the /// * directory is available from the metadata object passed to the /// * handler, under the key "directory". /// */ /// ``` /// /// `void setIndexHandler (in nsIHttpRequestHandler handler);` #[inline] pub unsafe fn SetIndexHandler(&self, handler: *const nsIHttpRequestHandler) -> nsresult { ((*self.vtable).SetIndexHandler)(self, handler) } /// ```text /// /** Represents the locations at which this server is reachable. */ /// ``` /// /// `readonly attribute nsIHttpServerIdentity identity;` #[inline] pub unsafe fn GetIdentity(&self, aIdentity: *mut *const nsIHttpServerIdentity) -> nsresult { ((*self.vtable).GetIdentity)(self, aIdentity) } /// ```text /// /** /// * Retrieves the string associated with the given key in this, for the given /// * path's saved state. All keys are initially associated with the empty /// * string. /// */ /// ``` /// /// `AString getState (in AString path, in AString key);` #[inline] pub unsafe fn GetState(&self, path: &::nsstring::nsAString, key: &::nsstring::nsAString, _retval: &mut ::nsstring::nsAString) -> nsresult { ((*self.vtable).GetState)(self, path, key, _retval) } /// ```text /// /** /// * Sets the string associated with the given key in this, for the given path's /// * saved state. /// */ /// ``` /// /// `void setState (in AString path, in AString key, in AString value);` #[inline] pub unsafe fn SetState(&self, path: &::nsstring::nsAString, key: &::nsstring::nsAString, value: &::nsstring::nsAString) -> nsresult { ((*self.vtable).SetState)(self, path, key, value) } /// ```text /// /** /// * Retrieves the string associated with the given key in this, in /// * entire-server saved state. All keys are initially associated with the /// * empty string. /// */ /// ``` /// /// `AString getSharedState (in AString key);` #[inline] pub unsafe fn GetSharedState(&self, key: &::nsstring::nsAString, _retval: &mut ::nsstring::nsAString) -> nsresult { ((*self.vtable).GetSharedState)(self, key, _retval) } /// ```text /// /** /// * Sets the string associated with the given key in this, in entire-server /// * saved state. /// */ /// ``` /// /// `void setSharedState (in AString key, in AString value);` #[inline] pub unsafe fn SetSharedState(&self, key: &::nsstring::nsAString, value: &::nsstring::nsAString) -> nsresult { ((*self.vtable).SetSharedState)(self, key, value) } /// ```text /// /** /// * Retrieves the object associated with the given key in this in /// * object-valued saved state. All keys are initially associated with null. /// */ /// ``` /// /// `nsISupports getObjectState (in AString key);` #[inline] pub unsafe fn GetObjectState(&self, key: &::nsstring::nsAString, _retval: *mut *const nsISupports) -> nsresult { ((*self.vtable).GetObjectState)(self, key, _retval) } /// ```text /// /** /// * Sets the object associated with the given key in this in object-valued /// * saved state. The value may be null. /// */ /// ``` /// /// `void setObjectState (in AString key, in nsISupports value);` #[inline] pub unsafe fn SetObjectState(&self, key: &::nsstring::nsAString, value: *const nsISupports) -> nsresult { ((*self.vtable).SetObjectState)(self, key, value) } } /// `interface nsIHttpServerStoppedCallback : nsISupports` /// // The actual type definition for the interface. This struct has methods // declared on it which will call through its vtable. You never want to pass // this type around by value, always pass it behind a reference. #[repr(C)] pub struct nsIHttpServerStoppedCallback { vtable: *const nsIHttpServerStoppedCallbackVTable, /// This field is a phantomdata to ensure that the VTable type and any /// struct containing it is not safe to send across threads, as XPCOM is /// generally not threadsafe. /// /// XPCOM interfaces in general are not safe to send across threads. __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>, } // Implementing XpCom for an interface exposes its IID, which allows for easy // use of the `.query_interface<T>` helper method. This also defines that // method for nsIHttpServerStoppedCallback. unsafe impl XpCom for nsIHttpServerStoppedCallback { const IID: nsIID = nsID(0x925a6d33, 0x9937, 0x4c63, [0xab, 0xe1, 0xa1, 0xc5, 0x6a, 0x98, 0x64, 0x55]); } // We need to implement the RefCounted trait so we can be used with `RefPtr`. // This trait teaches `RefPtr` how to manage our memory. unsafe impl RefCounted for nsIHttpServerStoppedCallback { #[inline] unsafe fn addref(&self) { self.AddRef(); } #[inline] unsafe fn release(&self) { self.Release(); } } // This trait is implemented on all types which can be coerced to from nsIHttpServerStoppedCallback. // It is used in the implementation of `fn coerce<T>`. We hide it from the // documentation, because it clutters it up a lot. #[doc(hidden)] pub trait nsIHttpServerStoppedCallbackCoerce { /// Cheaply cast a value of this type from a `nsIHttpServerStoppedCallback`. fn coerce_from(v: &nsIHttpServerStoppedCallback) -> &Self; } // The trivial implementation: We can obviously coerce ourselves to ourselves. impl nsIHttpServerStoppedCallbackCoerce for nsIHttpServerStoppedCallback { #[inline] fn coerce_from(v: &nsIHttpServerStoppedCallback) -> &Self { v } } impl nsIHttpServerStoppedCallback { /// Cast this `nsIHttpServerStoppedCallback` to one of its base interfaces. #[inline] pub fn coerce<T: nsIHttpServerStoppedCallbackCoerce>(&self) -> &T { T::coerce_from(self) } } // Every interface struct type implements `Deref` to its base interface. This // causes methods on the base interfaces to be directly avaliable on the // object. For example, you can call `.AddRef` or `.QueryInterface` directly // on any interface which inherits from `nsISupports`. impl ::std::ops::Deref for nsIHttpServerStoppedCallback { type Target = nsISupports; #[inline] fn deref(&self) -> &nsISupports { unsafe { ::std::mem::transmute(self) } } } // Ensure we can use .coerce() to cast to our base types as well. Any type which // our base interface can coerce from should be coercable from us as well. impl<T: nsISupportsCoerce> nsIHttpServerStoppedCallbackCoerce for T { #[inline] fn coerce_from(v: &nsIHttpServerStoppedCallback) -> &Self { T::coerce_from(v) } } // This struct represents the interface's VTable. A pointer to a statically // allocated version of this struct is at the beginning of every nsIHttpServerStoppedCallback // object. It contains one pointer field for each method in the interface. In // the case where we can't generate a binding for a method, we include a void // pointer. #[doc(hidden)] #[repr(C)] pub struct nsIHttpServerStoppedCallbackVTable { /// We need to include the members from the base interface's vtable at the start /// of the VTable definition. pub __base: nsISupportsVTable, /* void onStopped (); */ pub OnStopped: unsafe extern "system" fn (this: *const nsIHttpServerStoppedCallback) -> nsresult, } // The implementations of the function wrappers which are exposed to rust code. // Call these methods rather than manually calling through the VTable struct. impl nsIHttpServerStoppedCallback { /// ```text /// /** /// * An interface through which a notification of the complete stopping (socket /// * closure, in-flight requests all fully served and responded to) of an HTTP /// * server may be received. /// */ /// /** Called when the corresponding server has been fully stopped. */ /// ``` /// /// `void onStopped ();` #[inline] pub unsafe fn OnStopped(&self, ) -> nsresult { ((*self.vtable).OnStopped)(self, ) } } /// `interface nsIHttpServerIdentity : nsISupports` /// // The actual type definition for the interface. This struct has methods // declared on it which will call through its vtable. You never want to pass // this type around by value, always pass it behind a reference. #[repr(C)] pub struct nsIHttpServerIdentity { vtable: *const nsIHttpServerIdentityVTable, /// This field is a phantomdata to ensure that the VTable type and any /// struct containing it is not safe to send across threads, as XPCOM is /// generally not threadsafe. /// /// XPCOM interfaces in general are not safe to send across threads. __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>, } // Implementing XpCom for an interface exposes its IID, which allows for easy // use of the `.query_interface<T>` helper method. This also defines that // method for nsIHttpServerIdentity. unsafe impl XpCom for nsIHttpServerIdentity { const IID: nsIID = nsID(0xa89de175, 0xae8e, 0x4c46, [0x91, 0xa5, 0x0d, 0xba, 0x99, 0xbb, 0xd2, 0x84]); } // We need to implement the RefCounted trait so we can be used with `RefPtr`. // This trait teaches `RefPtr` how to manage our memory. unsafe impl RefCounted for nsIHttpServerIdentity { #[inline] unsafe fn addref(&self) { self.AddRef(); } #[inline] unsafe fn release(&self) { self.Release(); } } // This trait is implemented on all types which can be coerced to from nsIHttpServerIdentity. // It is used in the implementation of `fn coerce<T>`. We hide it from the // documentation, because it clutters it up a lot. #[doc(hidden)] pub trait nsIHttpServerIdentityCoerce { /// Cheaply cast a value of this type from a `nsIHttpServerIdentity`. fn coerce_from(v: &nsIHttpServerIdentity) -> &Self; } // The trivial implementation: We can obviously coerce ourselves to ourselves. impl nsIHttpServerIdentityCoerce for nsIHttpServerIdentity { #[inline] fn coerce_from(v: &nsIHttpServerIdentity) -> &Self { v } } impl nsIHttpServerIdentity { /// Cast this `nsIHttpServerIdentity` to one of its base interfaces. #[inline] pub fn coerce<T: nsIHttpServerIdentityCoerce>(&self) -> &T { T::coerce_from(self) } } // Every interface struct type implements `Deref` to its base interface. This // causes methods on the base interfaces to be directly avaliable on the // object. For example, you can call `.AddRef` or `.QueryInterface` directly // on any interface which inherits from `nsISupports`. impl ::std::ops::Deref for nsIHttpServerIdentity { type Target = nsISupports; #[inline] fn deref(&self) -> &nsISupports { unsafe { ::std::mem::transmute(self) } } } // Ensure we can use .coerce() to cast to our base types as well. Any type which // our base interface can coerce from should be coercable from us as well. impl<T: nsISupportsCoerce> nsIHttpServerIdentityCoerce for T { #[inline] fn coerce_from(v: &nsIHttpServerIdentity) -> &Self { T::coerce_from(v) } } // This struct represents the interface's VTable. A pointer to a statically // allocated version of this struct is at the beginning of every nsIHttpServerIdentity // object. It contains one pointer field for each method in the interface. In // the case where we can't generate a binding for a method, we include a void // pointer. #[doc(hidden)] #[repr(C)] pub struct nsIHttpServerIdentityVTable { /// We need to include the members from the base interface's vtable at the start /// of the VTable definition. pub __base: nsISupportsVTable, /* readonly attribute string primaryScheme; */ pub GetPrimaryScheme: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, aPrimaryScheme: *mut *const libc::c_char) -> nsresult, /* readonly attribute string primaryHost; */ pub GetPrimaryHost: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, aPrimaryHost: *mut *const libc::c_char) -> nsresult, /* readonly attribute long primaryPort; */ pub GetPrimaryPort: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, aPrimaryPort: *mut libc::int32_t) -> nsresult, /* void add (in string scheme, in string host, in long port); */ pub Add: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t) -> nsresult, /* boolean remove (in string scheme, in string host, in long port); */ pub Remove: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t, _retval: *mut bool) -> nsresult, /* boolean has (in string scheme, in string host, in long port); */ pub Has: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t, _retval: *mut bool) -> nsresult, /* string getScheme (in string host, in long port); */ pub GetScheme: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, host: *const libc::c_char, port: libc::int32_t, _retval: *mut *const libc::c_char) -> nsresult, /* void setPrimary (in string scheme, in string host, in long port); */ pub SetPrimary: unsafe extern "system" fn (this: *const nsIHttpServerIdentity, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t) -> nsresult, } // The implementations of the function wrappers which are exposed to rust code. // Call these methods rather than manually calling through the VTable struct. impl nsIHttpServerIdentity { /// ```text /// /** /// * Represents a set of names for a server, one of which is the primary name for /// * the server and the rest of which are secondary. By default every server will /// * contain ("http", "localhost", port) and ("http", "127.0.0.1", port) as names, /// * where port is what was provided to the corresponding server when started; /// * however, except for their being removed when the corresponding server stops /// * they have no special importance. /// */ /// /** /// * The primary scheme at which the corresponding server is located, defaulting /// * to 'http'. This name will be the value of nsIHttpRequest.scheme for /// * HTTP/1.0 requests. /// * /// * This value is always set when the corresponding server is running. If the /// * server is not running, this value is set only if it has been set to a /// * non-default name using setPrimary. In this case reading this value will /// * throw NS_ERROR_NOT_INITIALIZED. /// */ /// ``` /// /// `readonly attribute string primaryScheme;` #[inline] pub unsafe fn GetPrimaryScheme(&self, aPrimaryScheme: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetPrimaryScheme)(self, aPrimaryScheme) } /// ```text /// /** /// * The primary name by which the corresponding server is known, defaulting to /// * 'localhost'. This name will be the value of nsIHttpRequest.host for /// * HTTP/1.0 requests. /// * /// * This value is always set when the corresponding server is running. If the /// * server is not running, this value is set only if it has been set to a /// * non-default name using setPrimary. In this case reading this value will /// * throw NS_ERROR_NOT_INITIALIZED. /// */ /// ``` /// /// `readonly attribute string primaryHost;` #[inline] pub unsafe fn GetPrimaryHost(&self, aPrimaryHost: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetPrimaryHost)(self, aPrimaryHost) } /// ```text /// /** /// * The primary port on which the corresponding server runs, defaulting to the /// * associated server's port. This name will be the value of /// * nsIHttpRequest.port for HTTP/1.0 requests. /// * /// * This value is always set when the corresponding server is running. If the /// * server is not running, this value is set only if it has been set to a /// * non-default name using setPrimary. In this case reading this value will /// * throw NS_ERROR_NOT_INITIALIZED. /// */ /// ``` /// /// `readonly attribute long primaryPort;` #[inline] pub unsafe fn GetPrimaryPort(&self, aPrimaryPort: *mut libc::int32_t) -> nsresult { ((*self.vtable).GetPrimaryPort)(self, aPrimaryPort) } /// ```text /// /** /// * Adds a location at which this server may be accessed. /// * /// * @throws NS_ERROR_ILLEGAL_VALUE /// * if scheme or host do not match the scheme or host productions imported /// * into RFC 2616 from RFC 2396, or if port is not a valid port number /// */ /// ``` /// /// `void add (in string scheme, in string host, in long port);` #[inline] pub unsafe fn Add(&self, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t) -> nsresult { ((*self.vtable).Add)(self, scheme, host, port) } /// ```text /// /** /// * Removes this name from the list of names by which the corresponding server /// * is known. If name is also the primary name for the server, the primary /// * name reverts to 'http://127.0.0.1' with the associated server's port. /// * /// * @throws NS_ERROR_ILLEGAL_VALUE /// * if scheme or host do not match the scheme or host productions imported /// * into RFC 2616 from RFC 2396, or if port is not a valid port number /// * @returns /// * true if the given name was a name for this server, false otherwise /// */ /// ``` /// /// `boolean remove (in string scheme, in string host, in long port);` #[inline] pub unsafe fn Remove(&self, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t, _retval: *mut bool) -> nsresult { ((*self.vtable).Remove)(self, scheme, host, port, _retval) } /// ```text /// /** /// * Returns true if the given name is in this, false otherwise. /// * /// * @throws NS_ERROR_ILLEGAL_VALUE /// * if scheme or host do not match the scheme or host productions imported /// * into RFC 2616 from RFC 2396, or if port is not a valid port number /// */ /// ``` /// /// `boolean has (in string scheme, in string host, in long port);` #[inline] pub unsafe fn Has(&self, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t, _retval: *mut bool) -> nsresult { ((*self.vtable).Has)(self, scheme, host, port, _retval) } /// ```text /// /** /// * Returns the scheme for the name with the given host and port, if one is /// * present; otherwise returns the empty string. /// * /// * @throws NS_ERROR_ILLEGAL_VALUE /// * if host does not match the host production imported into RFC 2616 from /// * RFC 2396, or if port is not a valid port number /// */ /// ``` /// /// `string getScheme (in string host, in long port);` #[inline] pub unsafe fn GetScheme(&self, host: *const libc::c_char, port: libc::int32_t, _retval: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetScheme)(self, host, port, _retval) } /// ```text /// /** /// * Designates the given name as the primary name in this and adds it to this /// * if it is not already present. /// * /// * @throws NS_ERROR_ILLEGAL_VALUE /// * if scheme or host do not match the scheme or host productions imported /// * into RFC 2616 from RFC 2396, or if port is not a valid port number /// */ /// ``` /// /// `void setPrimary (in string scheme, in string host, in long port);` #[inline] pub unsafe fn SetPrimary(&self, scheme: *const libc::c_char, host: *const libc::c_char, port: libc::int32_t) -> nsresult { ((*self.vtable).SetPrimary)(self, scheme, host, port) } } /// `interface nsIHttpRequestHandler : nsISupports` /// // The actual type definition for the interface. This struct has methods // declared on it which will call through its vtable. You never want to pass // this type around by value, always pass it behind a reference. #[repr(C)] pub struct nsIHttpRequestHandler { vtable: *const nsIHttpRequestHandlerVTable, /// This field is a phantomdata to ensure that the VTable type and any /// struct containing it is not safe to send across threads, as XPCOM is /// generally not threadsafe. /// /// XPCOM interfaces in general are not safe to send across threads. __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>, } // Implementing XpCom for an interface exposes its IID, which allows for easy // use of the `.query_interface<T>` helper method. This also defines that // method for nsIHttpRequestHandler. unsafe impl XpCom for nsIHttpRequestHandler { const IID: nsIID = nsID(0x2bbb4db7, 0xd285, 0x42b3, [0xa3, 0xce, 0x14, 0x2b, 0x8c, 0xc7, 0xe1, 0x39]); } // We need to implement the RefCounted trait so we can be used with `RefPtr`. // This trait teaches `RefPtr` how to manage our memory. unsafe impl RefCounted for nsIHttpRequestHandler { #[inline] unsafe fn addref(&self) { self.AddRef(); } #[inline] unsafe fn release(&self) { self.Release(); } } // This trait is implemented on all types which can be coerced to from nsIHttpRequestHandler. // It is used in the implementation of `fn coerce<T>`. We hide it from the // documentation, because it clutters it up a lot. #[doc(hidden)] pub trait nsIHttpRequestHandlerCoerce { /// Cheaply cast a value of this type from a `nsIHttpRequestHandler`. fn coerce_from(v: &nsIHttpRequestHandler) -> &Self; } // The trivial implementation: We can obviously coerce ourselves to ourselves. impl nsIHttpRequestHandlerCoerce for nsIHttpRequestHandler { #[inline] fn coerce_from(v: &nsIHttpRequestHandler) -> &Self { v } } impl nsIHttpRequestHandler { /// Cast this `nsIHttpRequestHandler` to one of its base interfaces. #[inline] pub fn coerce<T: nsIHttpRequestHandlerCoerce>(&self) -> &T { T::coerce_from(self) } } // Every interface struct type implements `Deref` to its base interface. This // causes methods on the base interfaces to be directly avaliable on the // object. For example, you can call `.AddRef` or `.QueryInterface` directly // on any interface which inherits from `nsISupports`. impl ::std::ops::Deref for nsIHttpRequestHandler { type Target = nsISupports; #[inline] fn deref(&self) -> &nsISupports { unsafe { ::std::mem::transmute(self) } } } // Ensure we can use .coerce() to cast to our base types as well. Any type which // our base interface can coerce from should be coercable from us as well. impl<T: nsISupportsCoerce> nsIHttpRequestHandlerCoerce for T { #[inline] fn coerce_from(v: &nsIHttpRequestHandler) -> &Self { T::coerce_from(v) } } // This struct represents the interface's VTable. A pointer to a statically // allocated version of this struct is at the beginning of every nsIHttpRequestHandler // object. It contains one pointer field for each method in the interface. In // the case where we can't generate a binding for a method, we include a void // pointer. #[doc(hidden)] #[repr(C)] pub struct nsIHttpRequestHandlerVTable { /// We need to include the members from the base interface's vtable at the start /// of the VTable definition. pub __base: nsISupportsVTable, /* void handle (in nsIHttpRequest request, in nsIHttpResponse response); */ pub Handle: unsafe extern "system" fn (this: *const nsIHttpRequestHandler, request: *const nsIHttpRequest, response: *const nsIHttpResponse) -> nsresult, } // The implementations of the function wrappers which are exposed to rust code. // Call these methods rather than manually calling through the VTable struct. impl nsIHttpRequestHandler { /// ```text /// /** /// * A representation of a handler for HTTP requests. The handler is used by /// * calling its .handle method with data for an incoming request; it is the /// * handler's job to use that data as it sees fit to make the desired response. /// * /// * @note /// * This interface uses the [function] attribute, so you can pass a /// * script-defined function with the functionality of handle() to any /// * method which has a nsIHttpRequestHandler parameter, instead of wrapping /// * it in an otherwise empty object. /// */ /// /** /// * Processes an HTTP request and initializes the passed-in response to reflect /// * the correct HTTP response. /// * /// * If this method throws an exception, externally observable behavior depends /// * upon whether is being processed asynchronously. If such is the case, the /// * output is some prefix (perhaps all, perhaps none, perhaps only some) of the /// * data which would have been sent if, instead, the response had been finished /// * at that point. If no data has been written, the response has not had /// * seizePower() called on it, and it is not being asynchronously created, an /// * error handler will be invoked (usually 500 unless otherwise specified). /// * /// * Some uses of nsIHttpRequestHandler may require this method to never throw /// * an exception; in the general case, however, this method may throw an /// * exception (causing an HTTP 500 response to occur, if the above conditions /// * are met). /// * /// * @param request /// * data representing an HTTP request /// * @param response /// * an initially-empty response which must be modified to reflect the data /// * which should be sent as the response to the request described by metadata /// */ /// ``` /// /// `void handle (in nsIHttpRequest request, in nsIHttpResponse response);` #[inline] pub unsafe fn Handle(&self, request: *const nsIHttpRequest, response: *const nsIHttpResponse) -> nsresult { ((*self.vtable).Handle)(self, request, response) } } /// `interface nsIHttpRequest : nsISupports` /// // The actual type definition for the interface. This struct has methods // declared on it which will call through its vtable. You never want to pass // this type around by value, always pass it behind a reference. #[repr(C)] pub struct nsIHttpRequest { vtable: *const nsIHttpRequestVTable, /// This field is a phantomdata to ensure that the VTable type and any /// struct containing it is not safe to send across threads, as XPCOM is /// generally not threadsafe. /// /// XPCOM interfaces in general are not safe to send across threads. __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>, } // Implementing XpCom for an interface exposes its IID, which allows for easy // use of the `.query_interface<T>` helper method. This also defines that // method for nsIHttpRequest. unsafe impl XpCom for nsIHttpRequest { const IID: nsIID = nsID(0x978cf30e, 0xad73, 0x42ee, [0x8f, 0x22, 0xfe, 0x0a, 0xaf, 0x1b, 0xf5, 0xd2]); } // We need to implement the RefCounted trait so we can be used with `RefPtr`. // This trait teaches `RefPtr` how to manage our memory. unsafe impl RefCounted for nsIHttpRequest { #[inline] unsafe fn addref(&self) { self.AddRef(); } #[inline] unsafe fn release(&self) { self.Release(); } } // This trait is implemented on all types which can be coerced to from nsIHttpRequest. // It is used in the implementation of `fn coerce<T>`. We hide it from the // documentation, because it clutters it up a lot. #[doc(hidden)] pub trait nsIHttpRequestCoerce { /// Cheaply cast a value of this type from a `nsIHttpRequest`. fn coerce_from(v: &nsIHttpRequest) -> &Self; } // The trivial implementation: We can obviously coerce ourselves to ourselves. impl nsIHttpRequestCoerce for nsIHttpRequest { #[inline] fn coerce_from(v: &nsIHttpRequest) -> &Self { v } } impl nsIHttpRequest { /// Cast this `nsIHttpRequest` to one of its base interfaces. #[inline] pub fn coerce<T: nsIHttpRequestCoerce>(&self) -> &T { T::coerce_from(self) } } // Every interface struct type implements `Deref` to its base interface. This // causes methods on the base interfaces to be directly avaliable on the // object. For example, you can call `.AddRef` or `.QueryInterface` directly // on any interface which inherits from `nsISupports`. impl ::std::ops::Deref for nsIHttpRequest { type Target = nsISupports; #[inline] fn deref(&self) -> &nsISupports { unsafe { ::std::mem::transmute(self) } } } // Ensure we can use .coerce() to cast to our base types as well. Any type which // our base interface can coerce from should be coercable from us as well. impl<T: nsISupportsCoerce> nsIHttpRequestCoerce for T { #[inline] fn coerce_from(v: &nsIHttpRequest) -> &Self { T::coerce_from(v) } } // This struct represents the interface's VTable. A pointer to a statically // allocated version of this struct is at the beginning of every nsIHttpRequest // object. It contains one pointer field for each method in the interface. In // the case where we can't generate a binding for a method, we include a void // pointer. #[doc(hidden)] #[repr(C)] pub struct nsIHttpRequestVTable { /// We need to include the members from the base interface's vtable at the start /// of the VTable definition. pub __base: nsISupportsVTable, /* readonly attribute string method; */ pub GetMethod: unsafe extern "system" fn (this: *const nsIHttpRequest, aMethod: *mut *const libc::c_char) -> nsresult, /* readonly attribute string scheme; */ pub GetScheme: unsafe extern "system" fn (this: *const nsIHttpRequest, aScheme: *mut *const libc::c_char) -> nsresult, /* readonly attribute string host; */ pub GetHost: unsafe extern "system" fn (this: *const nsIHttpRequest, aHost: *mut *const libc::c_char) -> nsresult, /* readonly attribute unsigned long port; */ pub GetPort: unsafe extern "system" fn (this: *const nsIHttpRequest, aPort: *mut libc::uint32_t) -> nsresult, /* readonly attribute string path; */ pub GetPath: unsafe extern "system" fn (this: *const nsIHttpRequest, aPath: *mut *const libc::c_char) -> nsresult, /* readonly attribute string queryString; */ pub GetQueryString: unsafe extern "system" fn (this: *const nsIHttpRequest, aQueryString: *mut *const libc::c_char) -> nsresult, /* readonly attribute string httpVersion; */ pub GetHttpVersion: unsafe extern "system" fn (this: *const nsIHttpRequest, aHttpVersion: *mut *const libc::c_char) -> nsresult, /* string getHeader (in string fieldName); */ pub GetHeader: unsafe extern "system" fn (this: *const nsIHttpRequest, fieldName: *const libc::c_char, _retval: *mut *const libc::c_char) -> nsresult, /* boolean hasHeader (in string fieldName); */ pub HasHeader: unsafe extern "system" fn (this: *const nsIHttpRequest, fieldName: *const libc::c_char, _retval: *mut bool) -> nsresult, /* readonly attribute nsISimpleEnumerator headers; */ pub GetHeaders: unsafe extern "system" fn (this: *const nsIHttpRequest, aHeaders: *mut *const nsISimpleEnumerator) -> nsresult, /* readonly attribute nsIInputStream bodyInputStream; */ pub GetBodyInputStream: unsafe extern "system" fn (this: *const nsIHttpRequest, aBodyInputStream: *mut *const nsIInputStream) -> nsresult, } // The implementations of the function wrappers which are exposed to rust code. // Call these methods rather than manually calling through the VTable struct. impl nsIHttpRequest { /// ```text /// /** /// * A representation of the data included in an HTTP request. /// */ /// /** /// * The request type for this request (see RFC 2616, section 5.1.1). /// */ /// ``` /// /// `readonly attribute string method;` #[inline] pub unsafe fn GetMethod(&self, aMethod: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetMethod)(self, aMethod) } /// ```text /// /** /// * The scheme of the requested path, usually 'http' but might possibly be /// * 'https' if some form of SSL tunneling is in use. Note that this value /// * cannot be accurately determined unless the incoming request used the /// * absolute-path form of the request line; it defaults to 'http', so only /// * if it is something else can you be entirely certain it's correct. /// */ /// ``` /// /// `readonly attribute string scheme;` #[inline] pub unsafe fn GetScheme(&self, aScheme: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetScheme)(self, aScheme) } /// ```text /// /** /// * The host of the data being requested (e.g. "localhost" for the /// * http://localhost:8080/file resource). Note that the relevant port on the /// * host is specified in this.port. This value is in the ASCII character /// * encoding. /// */ /// ``` /// /// `readonly attribute string host;` #[inline] pub unsafe fn GetHost(&self, aHost: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetHost)(self, aHost) } /// ```text /// /** /// * The port on the server on which the request was received. /// */ /// ``` /// /// `readonly attribute unsigned long port;` #[inline] pub unsafe fn GetPort(&self, aPort: *mut libc::uint32_t) -> nsresult { ((*self.vtable).GetPort)(self, aPort) } /// ```text /// /** /// * The requested path, without any query string (e.g. "/dir/file.txt"). It is /// * guaranteed to begin with a "/". The individual components in this string /// * are URL-encoded. /// */ /// ``` /// /// `readonly attribute string path;` #[inline] pub unsafe fn GetPath(&self, aPath: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetPath)(self, aPath) } /// ```text /// /** /// * The URL-encoded query string associated with this request, not including /// * the initial "?", or "" if no query string was present. /// */ /// ``` /// /// `readonly attribute string queryString;` #[inline] pub unsafe fn GetQueryString(&self, aQueryString: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetQueryString)(self, aQueryString) } /// ```text /// /** /// * A string containing the HTTP version of the request (i.e., "1.1"). Leading /// * zeros for either component of the version will be omitted. (In other /// * words, if the request contains the version "1.01", this attribute will be /// * "1.1"; see RFC 2616, section 3.1.) /// */ /// ``` /// /// `readonly attribute string httpVersion;` #[inline] pub unsafe fn GetHttpVersion(&self, aHttpVersion: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetHttpVersion)(self, aHttpVersion) } /// ```text /// /** /// * Returns the value for the header in this request specified by fieldName. /// * /// * @param fieldName /// * the name of the field whose value is to be gotten; note that since HTTP /// * header field names are case-insensitive, this method produces equivalent /// * results for "HeAdER" and "hEADer" as fieldName /// * @returns /// * The result is a string containing the individual values of the header, /// * usually separated with a comma. The headers WWW-Authenticate, /// * Proxy-Authenticate, and Set-Cookie violate the HTTP specification, /// * however, and for these headers only the separator string is '\n'. /// * /// * @throws NS_ERROR_INVALID_ARG /// * if fieldName does not constitute a valid header field name /// * @throws NS_ERROR_NOT_AVAILABLE /// * if the given header does not exist in this /// */ /// ``` /// /// `string getHeader (in string fieldName);` #[inline] pub unsafe fn GetHeader(&self, fieldName: *const libc::c_char, _retval: *mut *const libc::c_char) -> nsresult { ((*self.vtable).GetHeader)(self, fieldName, _retval) } /// ```text /// /** /// * Returns true if a header with the given field name exists in this, false /// * otherwise. /// * /// * @param fieldName /// * the field name whose existence is to be determined in this; note that /// * since HTTP header field names are case-insensitive, this method produces /// * equivalent results for "HeAdER" and "hEADer" as fieldName /// * @throws NS_ERROR_INVALID_ARG /// * if fieldName does not constitute a valid header field name /// */ /// ``` /// /// `boolean hasHeader (in string fieldName);` #[inline] pub unsafe fn HasHeader(&self, fieldName: *const libc::c_char, _retval: *mut bool) -> nsresult { ((*self.vtable).HasHeader)(self, fieldName, _retval) } /// ```text /// /** /// * An nsISimpleEnumerator of nsISupportsStrings over the names of the headers /// * in this request. The header field names in the enumerator may not /// * necessarily have the same case as they do in the request itself. /// */ /// ``` /// /// `readonly attribute nsISimpleEnumerator headers;` #[inline] pub unsafe fn GetHeaders(&self, aHeaders: *mut *const nsISimpleEnumerator) -> nsresult { ((*self.vtable).GetHeaders)(self, aHeaders) } /// ```text /// /** /// * A stream from which data appearing in the body of this request can be read. /// */ /// ``` /// /// `readonly attribute nsIInputStream bodyInputStream;` #[inline] pub unsafe fn GetBodyInputStream(&self, aBodyInputStream: *mut *const nsIInputStream) -> nsresult { ((*self.vtable).GetBodyInputStream)(self, aBodyInputStream) } } /// `interface nsIHttpResponse : nsISupports` /// // The actual type definition for the interface. This struct has methods // declared on it which will call through its vtable. You never want to pass // this type around by value, always pass it behind a reference. #[repr(C)] pub struct nsIHttpResponse { vtable: *const nsIHttpResponseVTable, /// This field is a phantomdata to ensure that the VTable type and any /// struct containing it is not safe to send across threads, as XPCOM is /// generally not threadsafe. /// /// XPCOM interfaces in general are not safe to send across threads. __nosync: ::std::marker::PhantomData<::std::rc::Rc<u8>>, } // Implementing XpCom for an interface exposes its IID, which allows for easy // use of the `.query_interface<T>` helper method. This also defines that // method for nsIHttpResponse. unsafe impl XpCom for nsIHttpResponse { const IID: nsIID = nsID(0x1acd16c2, 0xdc59, 0x42fa, [0x91, 0x60, 0x4f, 0x26, 0xc4, 0x3c, 0x1c, 0x21]); } // We need to implement the RefCounted trait so we can be used with `RefPtr`. // This trait teaches `RefPtr` how to manage our memory. unsafe impl RefCounted for nsIHttpResponse { #[inline] unsafe fn addref(&self) { self.AddRef(); } #[inline] unsafe fn release(&self) { self.Release(); } } // This trait is implemented on all types which can be coerced to from nsIHttpResponse. // It is used in the implementation of `fn coerce<T>`. We hide it from the // documentation, because it clutters it up a lot. #[doc(hidden)] pub trait nsIHttpResponseCoerce { /// Cheaply cast a value of this type from a `nsIHttpResponse`. fn coerce_from(v: &nsIHttpResponse) -> &Self; } // The trivial implementation: We can obviously coerce ourselves to ourselves. impl nsIHttpResponseCoerce for nsIHttpResponse { #[inline] fn coerce_from(v: &nsIHttpResponse) -> &Self { v } } impl nsIHttpResponse { /// Cast this `nsIHttpResponse` to one of its base interfaces. #[inline] pub fn coerce<T: nsIHttpResponseCoerce>(&self) -> &T { T::coerce_from(self) } } // Every interface struct type implements `Deref` to its base interface. This // causes methods on the base interfaces to be directly avaliable on the // object. For example, you can call `.AddRef` or `.QueryInterface` directly // on any interface which inherits from `nsISupports`. impl ::std::ops::Deref for nsIHttpResponse { type Target = nsISupports; #[inline] fn deref(&self) -> &nsISupports { unsafe { ::std::mem::transmute(self) } } } // Ensure we can use .coerce() to cast to our base types as well. Any type which // our base interface can coerce from should be coercable from us as well. impl<T: nsISupportsCoerce> nsIHttpResponseCoerce for T { #[inline] fn coerce_from(v: &nsIHttpResponse) -> &Self { T::coerce_from(v) } } // This struct represents the interface's VTable. A pointer to a statically // allocated version of this struct is at the beginning of every nsIHttpResponse // object. It contains one pointer field for each method in the interface. In // the case where we can't generate a binding for a method, we include a void // pointer. #[doc(hidden)] #[repr(C)] pub struct nsIHttpResponseVTable { /// We need to include the members from the base interface's vtable at the start /// of the VTable definition. pub __base: nsISupportsVTable, /* void setStatusLine (in string httpVersion, in unsigned short statusCode, in string description); */ pub SetStatusLine: unsafe extern "system" fn (this: *const nsIHttpResponse, httpVersion: *const libc::c_char, statusCode: libc::uint16_t, description: *const libc::c_char) -> nsresult, /* void setHeader (in string name, in string value, in boolean merge); */ pub SetHeader: unsafe extern "system" fn (this: *const nsIHttpResponse, name: *const libc::c_char, value: *const libc::c_char, merge: bool) -> nsresult, /* void setHeaderNoCheck (in string name, in string value); */ pub SetHeaderNoCheck: unsafe extern "system" fn (this: *const nsIHttpResponse, name: *const libc::c_char, value: *const libc::c_char) -> nsresult, /* readonly attribute nsIOutputStream bodyOutputStream; */ pub GetBodyOutputStream: unsafe extern "system" fn (this: *const nsIHttpResponse, aBodyOutputStream: *mut *const nsIOutputStream) -> nsresult, /* void write (in string data); */ pub Write: unsafe extern "system" fn (this: *const nsIHttpResponse, data: *const libc::c_char) -> nsresult, /* void processAsync (); */ pub ProcessAsync: unsafe extern "system" fn (this: *const nsIHttpResponse) -> nsresult, /* void seizePower (); */ pub SeizePower: unsafe extern "system" fn (this: *const nsIHttpResponse) -> nsresult, /* void finish (); */ pub Finish: unsafe extern "system" fn (this: *const nsIHttpResponse) -> nsresult, } // The implementations of the function wrappers which are exposed to rust code. // Call these methods rather than manually calling through the VTable struct. impl nsIHttpResponse { /// ```text /// /** /// * Represents an HTTP response, as described in RFC 2616, section 6. /// */ /// /** /// * Sets the status line for this. If this method is never called on this, the /// * status line defaults to "HTTP/", followed by the server's default HTTP /// * version (e.g. "1.1"), followed by " 200 OK". /// * /// * @param httpVersion /// * the HTTP version of this, as a string (e.g. "1.1"); if null, the server /// * default is used /// * @param code /// * the numeric HTTP status code for this /// * @param description /// * a human-readable description of code; may be null if no description is /// * desired /// * @throws NS_ERROR_INVALID_ARG /// * if httpVersion is not a valid HTTP version string, statusCode is greater /// * than 999, or description contains invalid characters /// * @throws NS_ERROR_NOT_AVAILABLE /// * if this response is being processed asynchronously and data has been /// * written to this response's body, or if seizePower() has been called on /// * this /// */ /// ``` /// /// `void setStatusLine (in string httpVersion, in unsigned short statusCode, in string description);` #[inline] pub unsafe fn SetStatusLine(&self, httpVersion: *const libc::c_char, statusCode: libc::uint16_t, description: *const libc::c_char) -> nsresult { ((*self.vtable).SetStatusLine)(self, httpVersion, statusCode, description) } /// ```text /// /** /// * Sets the specified header in this. /// * /// * @param name /// * the name of the header; must match the field-name production per RFC 2616 /// * @param value /// * the value of the header; must match the field-value production per RFC /// * 2616 /// * @param merge /// * when true, if the given header already exists in this, the values passed /// * to this function will be merged into the existing header, per RFC 2616 /// * header semantics (except for the Set-Cookie, WWW-Authenticate, and /// * Proxy-Authenticate headers, which will treat each such merged header as /// * an additional instance of the header, for real-world compatibility /// * reasons); when false, replaces any existing header of the given name (if /// * any exists) with a new header with the specified value /// * @throws NS_ERROR_INVALID_ARG /// * if name or value is not a valid header component /// * @throws NS_ERROR_NOT_AVAILABLE /// * if this response is being processed asynchronously and data has been /// * written to this response's body, or if seizePower() has been called on /// * this /// */ /// ``` /// /// `void setHeader (in string name, in string value, in boolean merge);` #[inline] pub unsafe fn SetHeader(&self, name: *const libc::c_char, value: *const libc::c_char, merge: bool) -> nsresult { ((*self.vtable).SetHeader)(self, name, value, merge) } /// ```text /// /** /// * This is used for testing our header handling, so header will be sent out /// * without transformation. There can be multiple headers. /// */ /// ``` /// /// `void setHeaderNoCheck (in string name, in string value);` #[inline] pub unsafe fn SetHeaderNoCheck(&self, name: *const libc::c_char, value: *const libc::c_char) -> nsresult { ((*self.vtable).SetHeaderNoCheck)(self, name, value) } /// ```text /// /** /// * A stream to which data appearing in the body of this response (or in the /// * totality of the response if seizePower() is called) should be written. /// * After this response has been designated as being processed asynchronously, /// * or after seizePower() has been called on this, subsequent writes will no /// * longer be buffered and will be written to the underlying transport without /// * delaying until the entire response is constructed. Write-through may or /// * may not be synchronous in the implementation, and in any case particular /// * behavior may not be observable to the HTTP client as intermediate buffers /// * both in the server socket and in the client may delay written data; be /// * prepared for delays at any time. /// * /// * @throws NS_ERROR_NOT_AVAILABLE /// * if accessed after this response is fully constructed /// */ /// ``` /// /// `readonly attribute nsIOutputStream bodyOutputStream;` #[inline] pub unsafe fn GetBodyOutputStream(&self, aBodyOutputStream: *mut *const nsIOutputStream) -> nsresult { ((*self.vtable).GetBodyOutputStream)(self, aBodyOutputStream) } /// ```text /// /** /// * Writes a string to the response's output stream. This method is merely a /// * convenient shorthand for writing the same data to bodyOutputStream /// * directly. /// * /// * @note /// * This method is only guaranteed to work with ASCII data. /// * @throws NS_ERROR_NOT_AVAILABLE /// * if called after this response has been fully constructed /// */ /// ``` /// /// `void write (in string data);` #[inline] pub unsafe fn Write(&self, data: *const libc::c_char) -> nsresult { ((*self.vtable).Write)(self, data) } /// ```text /// /** /// * Signals that this response is being constructed asynchronously. Requests /// * are typically completely constructed during nsIHttpRequestHandler.handle; /// * however, responses which require significant resources (time, memory, /// * processing) to construct can be created and sent incrementally by calling /// * this method during the call to nsIHttpRequestHandler.handle. This method /// * only has this effect when called during nsIHttpRequestHandler.handle; /// * behavior is undefined if it is called at a later time. It may be called /// * multiple times with no ill effect, so long as each call occurs before /// * finish() is called. /// * /// * @throws NS_ERROR_UNEXPECTED /// * if not initially called within a nsIHttpRequestHandler.handle call or if /// * called after this response has been finished /// * @throws NS_ERROR_NOT_AVAILABLE /// * if seizePower() has been called on this /// */ /// ``` /// /// `void processAsync ();` #[inline] pub unsafe fn ProcessAsync(&self, ) -> nsresult { ((*self.vtable).ProcessAsync)(self, ) } /// ```text /// /** /// * Seizes complete control of this response (and its connection) from the /// * server, allowing raw and unfettered access to data being sent in the HTTP /// * response. Once this method has been called the only property which may be /// * accessed without an exception being thrown is bodyOutputStream, and the /// * only methods which may be accessed without an exception being thrown are /// * write(), finish(), and seizePower() (which may be called multiple times /// * without ill effect so long as all calls are otherwise allowed). /// * /// * After a successful call, all data subsequently written to the body of this /// * response is written directly to the corresponding connection. (Previously- /// * written data is silently discarded.) No status line or headers are sent /// * before doing so; if the response handler wishes to write such data, it must /// * do so manually. Data generation completes only when finish() is called; it /// * is not enough to simply call close() on bodyOutputStream. /// * /// * @throws NS_ERROR_NOT_AVAILABLE /// * if processAsync() has been called on this /// * @throws NS_ERROR_UNEXPECTED /// * if finish() has been called on this /// */ /// ``` /// /// `void seizePower ();` #[inline] pub unsafe fn SeizePower(&self, ) -> nsresult { ((*self.vtable).SeizePower)(self, ) } /// ```text /// /** /// * Signals that construction of this response is complete and that it may be /// * sent over the network to the client, or if seizePower() has been called /// * signals that all data has been written and that the underlying connection /// * may be closed. This method may only be called after processAsync() or /// * seizePower() has been called. This method is idempotent. /// * /// * @throws NS_ERROR_UNEXPECTED /// * if processAsync() or seizePower() has not already been properly called /// */ /// ``` /// /// `void finish ();` #[inline] pub unsafe fn Finish(&self, ) -> nsresult { ((*self.vtable).Finish)(self, ) } }