[syslinux:lwip] pxe: move operations common to TCP-based protocols to a common file
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Sun Apr 24 21:03:21 PDT 2011
Commit-ID: 6c5e4a4bcfc991a6e578f65976891bcde31d0c56
Gitweb: http://syslinux.zytor.com/commit/6c5e4a4bcfc991a6e578f65976891bcde31d0c56
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sat, 23 Apr 2011 20:48:42 -0700
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Sat, 23 Apr 2011 20:50:00 -0700
pxe: move operations common to TCP-based protocols to a common file
Move operations that are common to all TCP-based protocols into a
common file, tcp.c.
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
core/fs/pxe/http.c | 66 ++++++-----------------------------------------
core/fs/pxe/pxe.h | 8 ++++-
core/fs/pxe/tcp.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+), 60 deletions(-)
diff --git a/core/fs/pxe/http.c b/core/fs/pxe/http.c
index 2f5a645..8d19755 100644
--- a/core/fs/pxe/http.c
+++ b/core/fs/pxe/http.c
@@ -6,56 +6,6 @@
#define HTTP_PORT 80
-static void http_close_file(struct inode *inode)
-{
- struct pxe_pvt_inode *socket = PVT(inode);
- if (socket->buf) {
- netbuf_delete(socket->buf);
- socket->buf = NULL;
- }
- if (socket->conn) {
- netconn_delete(socket->conn);
- socket->conn = NULL;
- }
-}
-
-static void http_fill_buffer(struct inode *inode)
-{
- struct pxe_pvt_inode *socket = PVT(inode);
- void *data;
- u16_t len;
- err_t err;
-
- /* Clean up or advance an inuse netbuf */
- if (socket->buf) {
- if (netbuf_next(socket->buf) < 0) {
- netbuf_delete(socket->buf);
- socket->buf = NULL;
- }
- }
- /* If needed get a new netbuf */
- if (!socket->buf) {
- socket->buf = netconn_recv(socket->conn);
- if (!socket->buf) {
- socket->tftp_goteof = 1;
- if (inode->size == -1)
- inode->size = socket->tftp_filepos;
- http_close_file(inode);
- return;
- }
- }
- /* Report the current fragment of the netbuf */
- err = netbuf_data(socket->buf, &data, &len);
- if (err) {
- printf("netbuf_data err: %d\n", err);
- kaboom();
- }
- socket->tftp_dataptr = data;
- socket->tftp_filepos += len;
- socket->tftp_bytesleft = len;
- return;
-}
-
static bool is_tspecial(int ch)
{
bool tspecial = false;
@@ -65,7 +15,7 @@ static bool is_tspecial(int ch)
case '/': case '[': case ']': case '?': case '=':
case '{': case '}': case ' ': case '\t':
tspecial = true;
- break;
+ break;
}
return tspecial;
}
@@ -86,7 +36,7 @@ static bool append_ch(char *str, size_t size, size_t *pos, int ch)
bool success = true;
if ((*pos + 1) >= size) {
*pos = 0;
- success = false;
+ success = false;
} else {
str[*pos] = ch;
str[*pos + 1] = '\0';
@@ -124,8 +74,8 @@ void http_open(struct url_info *url, struct inode *inode)
int pos;
int redirect_count;
- socket->fill_buffer = http_fill_buffer;
- socket->close = http_close_file;
+ socket->fill_buffer = tcp_fill_buffer;
+ socket->close = tcp_close_file;
redirect_count = 0;
restart:
@@ -268,7 +218,7 @@ restart:
/* Bogus cases try to recover */
else if (ch == '\n')
state = st_fieldfirst;
- else
+ else
state = st_skipline;
break;
@@ -300,7 +250,7 @@ restart:
if (ch == '\n')
state = st_fieldfirst;
break;
-
+
case st_eoh:
break; /* Should never happen */
}
@@ -331,7 +281,7 @@ restart:
strlcpy(new_url, location, sizeof new_url);
parse_url(url, new_url);
url_set_ip(url);
- http_close_file(inode);
+ tcp_close_file(inode);
/* XXX: This needs to go all the way back to scheme selection */
goto restart;
break;
@@ -342,6 +292,6 @@ restart:
return;
fail:
inode->size = 0;
- http_close_file(inode);
+ tcp_close_file(inode);
return;
}
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index bb833d6..7d5c43e 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -52,7 +52,7 @@ static inline int hexval(char c)
#define DNS_MAX_SERVERS 4 /* Max no of DNS servers */
/*
- * structures
+ * structures
*/
struct pxenv_t {
uint8_t signature[6]; /* PXENV+ */
@@ -205,7 +205,7 @@ static inline uint32_t gateway(uint32_t ip)
}
/*
- * functions
+ * functions
*/
/* pxeisr.inc */
@@ -254,4 +254,8 @@ void gpxe_open(struct inode *inode, const char *url);
/* http.c */
void http_open(struct url_info *url, struct inode *inode);
+/* tcp.c */
+void tcp_close_file(struct inode *inode);
+void tcp_fill_buffer(struct inode *inode);
+
#endif /* pxe.h */
diff --git a/core/fs/pxe/tcp.c b/core/fs/pxe/tcp.c
new file mode 100644
index 0000000..af0cffc
--- /dev/null
+++ b/core/fs/pxe/tcp.c
@@ -0,0 +1,72 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2011 Intel Corporation; author: H. Peter Anvin
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston MA 02110-1301, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * tcp.c
+ *
+ * Common operations for TCP-based network protocols
+ */
+
+#include <lwip/api.h>
+#include "pxe.h"
+#include "../../../version.h"
+#include "url.h"
+
+void tcp_close_file(struct inode *inode)
+{
+ struct pxe_pvt_inode *socket = PVT(inode);
+ if (socket->buf) {
+ netbuf_delete(socket->buf);
+ socket->buf = NULL;
+ }
+ if (socket->conn) {
+ netconn_delete(socket->conn);
+ socket->conn = NULL;
+ }
+}
+
+void tcp_fill_buffer(struct inode *inode)
+{
+ struct pxe_pvt_inode *socket = PVT(inode);
+ void *data;
+ u16_t len;
+ err_t err;
+
+ /* Clean up or advance an inuse netbuf */
+ if (socket->buf) {
+ if (netbuf_next(socket->buf) < 0) {
+ netbuf_delete(socket->buf);
+ socket->buf = NULL;
+ }
+ }
+ /* If needed get a new netbuf */
+ if (!socket->buf) {
+ socket->buf = netconn_recv(socket->conn);
+ if (!socket->buf) {
+ socket->tftp_goteof = 1;
+ if (inode->size == -1)
+ inode->size = socket->tftp_filepos;
+ tcp_close_file(inode);
+ return;
+ }
+ }
+ /* Report the current fragment of the netbuf */
+ err = netbuf_data(socket->buf, &data, &len);
+ if (err) {
+ printf("netbuf_data err: %d\n", err);
+ kaboom();
+ }
+ socket->tftp_dataptr = data;
+ socket->tftp_filepos += len;
+ socket->tftp_bytesleft = len;
+ return;
+}
More information about the Syslinux-commits
mailing list