File cnx.c changed (mode: 100644) (index 0d29b96..23f08ad) |
63 |
63 |
#define RESPONSE_X_PART01 "\ |
#define RESPONSE_X_PART01 "\ |
64 |
64 |
\r\n\ |
\r\n\ |
65 |
65 |
connection: close\r\n\ |
connection: close\r\n\ |
66 |
|
content-type: text/html\r\n\ |
|
|
66 |
|
content-type: text/html;charset=utf-8\r\n\ |
67 |
67 |
content-length: " |
content-length: " |
68 |
68 |
/*---------------------------------------------------------------------------------------------------------------------------*/ |
/*---------------------------------------------------------------------------------------------------------------------------*/ |
69 |
69 |
/* here, we must generate the body length as a decimal number */ |
/* here, we must generate the body length as a decimal number */ |
|
... |
... |
LNANOMSGBRD_CONFIG_TITLE \ |
100 |
100 |
<label>fichier autre:<input name=\"file\" type=\"file\" accept=\"application/octet-stream\"/></label>\ |
<label>fichier autre:<input name=\"file\" type=\"file\" accept=\"application/octet-stream\"/></label>\ |
101 |
101 |
<button type=\"submit\">envoyer le fichier autre</button>\ |
<button type=\"submit\">envoyer le fichier autre</button>\ |
102 |
102 |
</form>\ |
</form>\ |
|
103 |
|
<hr>\ |
103 |
104 |
<form action=\"/message\" method=\"post\" enctype=\"multipart/form-data\">\ |
<form action=\"/message\" method=\"post\" enctype=\"multipart/form-data\">\ |
104 |
|
<label>message:<textarea name=\"message\" rows=\"8\" cols=\"80\"></textarea></label>\ |
|
|
105 |
|
<label>message:<br><textarea name=\"message\" rows=\"4\" cols=\"63\"></textarea></label><br>\ |
105 |
106 |
<button type=\"submit\">envoyer le message</button>\ |
<button type=\"submit\">envoyer le message</button>\ |
106 |
107 |
</form>\ |
</form>\ |
107 |
108 |
<hr>" |
<hr>" |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1463 |
1464 |
break; |
break; |
1464 |
1465 |
} |
} |
1465 |
1466 |
if (ISERR(r)) { |
if (ISERR(r)) { |
1466 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de créer le nouveau fichier dans notre espace de stockage. Changer le nom du fichier et re-essayer.</p>"); |
|
|
1467 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de créer le nouveau fichier dans notre espace de stockage. Changer le nom du fichier et re-essayer.</p><hr>"); |
1467 |
1468 |
return; |
return; |
1468 |
1469 |
} |
} |
1469 |
1470 |
fd = (si)r; |
fd = (si)r; |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1478 |
1479 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
1479 |
1480 |
/* now, we try to book storage space for the file and the body trailer */ |
/* now, we try to book storage space for the file and the body trailer */ |
1480 |
1481 |
if (remaining_body_bytes_n == 0) { /* don't try to fallocate 0 */ |
if (remaining_body_bytes_n == 0) { /* don't try to fallocate 0 */ |
1481 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de réserver un espace de stockage vide pour le fichier (\"fallocate\").</p>"); |
|
|
1482 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de réserver un espace de stockage vide pour le fichier (\"fallocate\").</p><hr>"); |
1482 |
1483 |
goto err_unlink; |
goto err_unlink; |
1483 |
1484 |
} |
} |
1484 |
1485 |
loop { |
loop { |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1487 |
1488 |
break; |
break; |
1488 |
1489 |
} |
} |
1489 |
1490 |
if (ISERR(r)) { /* could not book room in our storage */ |
if (ISERR(r)) { /* could not book room in our storage */ |
1490 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de réserver l'espace de stockage pour le fichier. Le fichier est peut-être trop gros.</p>"); |
|
|
1491 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de réserver l'espace de stockage pour le fichier. Le fichier est peut-être trop gros.</p><hr>"); |
1491 |
1492 |
goto err_unlink; |
goto err_unlink; |
1492 |
1493 |
} |
} |
1493 |
1494 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
1494 |
1495 |
/* we booked our storage room, let's write what we already have */ |
/* we booked our storage room, let's write what we already have */ |
1495 |
1496 |
if ( ((u8*)(tls->body.part.uploaded_file_start) + file_with_body_trailer_already_read_bytes_n) >= |
if ( ((u8*)(tls->body.part.uploaded_file_start) + file_with_body_trailer_already_read_bytes_n) >= |
1496 |
1497 |
((u8*)tls + THREAD_LOCAL_STORAGE_BYTES_N) ) { |
((u8*)tls + THREAD_LOCAL_STORAGE_BYTES_N) ) { |
1497 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de commencer à écrire dans l'espace de stockage le fichier (\"tls size mismatch\").</p>"); |
|
|
1498 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:impossible de commencer à écrire dans l'espace de stockage le fichier (\"tls size mismatch\").</p><hr>"); |
1498 |
1499 |
goto err_unlink; |
goto err_unlink; |
1499 |
1500 |
} |
} |
1500 |
1501 |
u8 *next_write = (u8*)(tls->body.part.uploaded_file_start); |
u8 *next_write = (u8*)(tls->body.part.uploaded_file_start); |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1508 |
1509 |
break; |
break; |
1509 |
1510 |
} |
} |
1510 |
1511 |
if (ISERR(r)) { |
if (ISERR(r)) { |
1511 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:une erreur est survenue lors de l'écriture dans l'espace de stockage du fichier (\"tls file write\").</p>"); |
|
|
1512 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:une erreur est survenue lors de l'écriture dans l'espace de stockage du fichier (\"tls file write\").</p><hr>"); |
1512 |
1513 |
goto err_unlink; |
goto err_unlink; |
1513 |
1514 |
} |
} |
1514 |
1515 |
remaining_bytes_n_to_write -= (u64)r; |
remaining_bytes_n_to_write -= (u64)r; |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1525 |
1526 |
break; |
break; |
1526 |
1527 |
} |
} |
1527 |
1528 |
if (ISERR(r) || r == 0) { |
if (ISERR(r) || r == 0) { |
1528 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:une erreur est survenue lors du transfère ou de l'écriture dans l'espace de stockage du fichier (\"sendfile\").</p>"); |
|
|
1529 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR:une erreur est survenue lors du transfère ou de l'écriture dans l'espace de stockage du fichier (\"sendfile\").</p><hr>"); |
1529 |
1530 |
goto err_unlink; |
goto err_unlink; |
1530 |
1531 |
} |
} |
1531 |
1532 |
remaining_body_bytes_n -= (u64)r; |
remaining_body_bytes_n -= (u64)r; |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1555 |
1556 |
break; |
break; |
1556 |
1557 |
} |
} |
1557 |
1558 |
if (ISERR(r)) { |
if (ISERR(r)) { |
1558 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: une erreur de post-traitement est survenue sur le fichier envoyé (\"file trailer mmaping\").</p>"); |
|
|
1559 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: une erreur de post-traitement est survenue sur le fichier envoyé (\"file trailer mmaping\").</p><hr>"); |
1559 |
1560 |
goto err_unlink; |
goto err_unlink; |
1560 |
1561 |
} |
} |
1561 |
1562 |
u8 *trailer_bytes = (u8*)r; |
u8 *trailer_bytes = (u8*)r; |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1568 |
1569 |
u8 *cursor = trailer_bytes; |
u8 *cursor = trailer_bytes; |
1569 |
1570 |
loop { |
loop { |
1570 |
1571 |
if (cursor == trailer_bytes_end) { |
if (cursor == trailer_bytes_end) { |
1571 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: une erreur de post-traitement est survenue sur le fichier envoyé (\"end marker not found\").</p>"); |
|
|
1572 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: une erreur de post-traitement est survenue sur le fichier envoyé (\"end marker not found\").</p><hr>"); |
1572 |
1573 |
goto err_mmap_file_trailer; |
goto err_mmap_file_trailer; |
1573 |
1574 |
} |
} |
1574 |
1575 |
if (*cursor == boundary_delimiter[part_boundary_delimiter_seen_bytes_n]) { |
if (*cursor == boundary_delimiter[part_boundary_delimiter_seen_bytes_n]) { |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1601 |
1602 |
break; |
break; |
1602 |
1603 |
} |
} |
1603 |
1604 |
if (ISERR(r)) { |
if (ISERR(r)) { |
1604 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: une erreur de post-traitement est survenue sur le fichier envoyé (\"ftruncate\").</p>"); |
|
|
1605 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: une erreur de post-traitement est survenue sur le fichier envoyé (\"ftruncate\").</p><hr>"); |
1605 |
1606 |
goto err_unlink; |
goto err_unlink; |
1606 |
1607 |
} |
} |
1607 |
1608 |
/*===================================================================================================================*/ |
/*===================================================================================================================*/ |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1617 |
1618 |
} |
} |
1618 |
1619 |
if (ISERR(r)) { |
if (ISERR(r)) { |
1619 |
1620 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1620 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: verrouillage défectueux du fichier d'index.</p>"); |
|
|
1621 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: verrouillage défectueux du fichier d'index.</p><hr>"); |
1621 |
1622 |
goto err_unlink; |
goto err_unlink; |
1622 |
1623 |
} |
} |
1623 |
1624 |
/* grow the index mmaping */ |
/* grow the index mmaping */ |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1628 |
1629 |
break; |
break; |
1629 |
1630 |
} |
} |
1630 |
1631 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1631 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible d'augmenter la taille du fichier d'index.</p>"); |
|
|
1632 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible d'augmenter la taille du fichier d'index.</p><hr>"); |
1632 |
1633 |
goto err_unlink; |
goto err_unlink; |
1633 |
1634 |
} |
} |
1634 |
1635 |
/* pick the right file type from the POST request line target */ |
/* pick the right file type from the POST request line target */ |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1654 |
1655 |
break; |
break; |
1655 |
1656 |
} |
} |
1656 |
1657 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1657 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible de synchroniser le fichier d'index dans l'espace de stockage</p>"); |
|
|
1658 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible de synchroniser le fichier d'index dans l'espace de stockage</p><hr>"); |
1658 |
1659 |
goto err_unlink; |
goto err_unlink; |
1659 |
1660 |
} |
} |
1660 |
1661 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
|
... |
... |
static void file_receive(struct thread_local_storage *tls) |
1667 |
1668 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1668 |
1669 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
1669 |
1670 |
u64 response_body_bytes_n; |
u64 response_body_bytes_n; |
1670 |
|
#define INFO_MESSAGE_HTML "<p>INFORMATION: fichier reçu.</p>" |
|
|
1671 |
|
#define INFO_MESSAGE_HTML "<p>INFORMATION: fichier reçu.</p><hr>" |
1671 |
1672 |
response_body_generate(tls, &response_body_bytes_n, WITH_LOCKED_IDX, INFO_MESSAGE_HTML, sizeof(INFO_MESSAGE_HTML) - 1); |
response_body_generate(tls, &response_body_bytes_n, WITH_LOCKED_IDX, INFO_MESSAGE_HTML, sizeof(INFO_MESSAGE_HTML) - 1); |
1672 |
1673 |
response_with_body_send(tls, CODE_200, response_body_bytes_n); |
response_with_body_send(tls, CODE_200, response_body_bytes_n); |
1673 |
1674 |
#undef INFO_MESSAGE_HTML |
#undef INFO_MESSAGE_HTML |
|
... |
... |
static void message_receive(struct thread_local_storage *tls) |
1707 |
1708 |
u8 *cursor = tls->body.part.uploaded_message_start; |
u8 *cursor = tls->body.part.uploaded_message_start; |
1708 |
1709 |
loop { |
loop { |
1709 |
1710 |
if (!get_byte(tls, cursor)) { |
if (!get_byte(tls, cursor)) { |
1710 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: impossible de trouver la fin du message envoyé (\"unable to get byte\").</p>"); |
|
|
1711 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: impossible de trouver la fin du message envoyé (\"unable to get byte\").</p><hr>"); |
1711 |
1712 |
return; |
return; |
1712 |
1713 |
} |
} |
1713 |
1714 |
if (*cursor == boundary_delimiter[part_boundary_delimiter_seen_bytes_n]) { |
if (*cursor == boundary_delimiter[part_boundary_delimiter_seen_bytes_n]) { |
|
... |
... |
static void message_receive(struct thread_local_storage *tls) |
1727 |
1728 |
u8 *message_end = cursor - part_boundary_delimiter_bytes_n + 1; |
u8 *message_end = cursor - part_boundary_delimiter_bytes_n + 1; |
1728 |
1729 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
1729 |
1730 |
if (tls->body.part.uploaded_message_start == message_end) { |
if (tls->body.part.uploaded_message_start == message_end) { |
1730 |
|
RESPONSE_400_SEND_IDX("<p>INFORMATION: le message reçu était vide donc il a été ignoré.</p>"); |
|
|
1731 |
|
RESPONSE_400_SEND_IDX("<p>INFORMATION: le message reçu était vide donc il a été ignoré.</p><hr>"); |
1731 |
1732 |
return; |
return; |
1732 |
1733 |
} |
} |
1733 |
1734 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
|
... |
... |
static void message_receive(struct thread_local_storage *tls) |
1741 |
1742 |
} |
} |
1742 |
1743 |
if (ISERR(r)) { |
if (ISERR(r)) { |
1743 |
1744 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1744 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: verrouillage défectueux du fichier d'index.</p>"); |
|
|
1745 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: verrouillage défectueux du fichier d'index.</p><hr>"); |
1745 |
1746 |
return; |
return; |
1746 |
1747 |
} |
} |
1747 |
1748 |
/* grow the index mmaping */ |
/* grow the index mmaping */ |
|
... |
... |
static void message_receive(struct thread_local_storage *tls) |
1753 |
1754 |
break; |
break; |
1754 |
1755 |
} |
} |
1755 |
1756 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1756 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible d'augmenter la taille du fichier d'index.</p>"); |
|
|
1757 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible d'augmenter la taille du fichier d'index.</p><hr>"); |
1757 |
1758 |
return; |
return; |
1758 |
1759 |
} |
} |
1759 |
1760 |
/* pick the right file type from the POST request line target */ |
/* pick the right file type from the POST request line target */ |
|
... |
... |
static void message_receive(struct thread_local_storage *tls) |
1778 |
1779 |
break; |
break; |
1779 |
1780 |
} |
} |
1780 |
1781 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1781 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible de synchroniser le fichier d'index dans l'espace de stockage</p>"); |
|
|
1782 |
|
RESPONSE_400_SEND_NOIDX("<p>ERREUR: impossible de synchroniser le fichier d'index dans l'espace de stockage</p><hr>"); |
1782 |
1783 |
return; |
return; |
1783 |
1784 |
} |
} |
1784 |
1785 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
|
... |
... |
static void message_receive(struct thread_local_storage *tls) |
1791 |
1792 |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
lnanomsgbrd_spin_unlock(&lnanomsgbrd_g_idx_lock); |
1792 |
1793 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
1793 |
1794 |
u64 response_body_bytes_n; |
u64 response_body_bytes_n; |
1794 |
|
#define INFO_MESSAGE_HTML "<p>INFORMATION: message reçu.</p>" |
|
|
1795 |
|
#define INFO_MESSAGE_HTML "<p>INFORMATION: message reçu.</p><hr>" |
1795 |
1796 |
response_body_generate(tls, &response_body_bytes_n, WITH_LOCKED_IDX, INFO_MESSAGE_HTML, sizeof(INFO_MESSAGE_HTML) - 1); |
response_body_generate(tls, &response_body_bytes_n, WITH_LOCKED_IDX, INFO_MESSAGE_HTML, sizeof(INFO_MESSAGE_HTML) - 1); |
1796 |
1797 |
response_with_body_send(tls, CODE_200, response_body_bytes_n); |
response_with_body_send(tls, CODE_200, response_body_bytes_n); |
1797 |
1798 |
#undef INFO_MESSAGE_HTML |
#undef INFO_MESSAGE_HTML |
|
... |
... |
content-type: " |
1875 |
1876 |
static void file_send(struct thread_local_storage *tls) |
static void file_send(struct thread_local_storage *tls) |
1876 |
1877 |
{ |
{ |
1877 |
1878 |
if (!target_extract_filename(tls)) { |
if (!target_extract_filename(tls)) { |
1878 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: type de téléchargement de fichier inconnu.</p>"); |
|
|
1879 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: type de téléchargement de fichier inconnu.</p><hr>"); |
1879 |
1880 |
return; |
return; |
1880 |
1881 |
} |
} |
1881 |
1882 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |
|
... |
... |
static void file_send(struct thread_local_storage *tls) |
1909 |
1910 |
} |
} |
1910 |
1911 |
if (ISERR(r) || ((fd_statx.mask & STATX_SIZE) == 0)) { |
if (ISERR(r) || ((fd_statx.mask & STATX_SIZE) == 0)) { |
1911 |
1912 |
close(fd); |
close(fd); |
1912 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: impossible d'obtenir la taille du fichier (\"statx\").</p>"); |
|
|
1913 |
|
RESPONSE_400_SEND_IDX("<p>ERREUR: impossible d'obtenir la taille du fichier (\"statx\").</p><hr>"); |
1913 |
1914 |
return; |
return; |
1914 |
1915 |
} |
} |
1915 |
1916 |
/*-------------------------------------------------------------------------------------------------------------------*/ |
/*-------------------------------------------------------------------------------------------------------------------*/ |