Changeset b39eb79 in mainline for uspace/app
- Timestamp:
- 2011-12-26T17:21:21Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9b56a8dd
- Parents:
- cf5c05c0 (diff), 7e1b130 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 2 added
- 11 edited
-
klog/klog.c (modified) (1 diff)
-
mkbd/main.c (modified) (1 diff)
-
netecho/netecho.c (modified) (3 diffs)
-
nettest3/Makefile (added)
-
nettest3/nettest3.c (added)
-
tester/mm/common.c (modified) (1 diff)
-
tester/mm/mapping1.c (modified) (2 diffs)
-
trace/syscalls.c (modified) (1 diff)
-
usbinfo/dev.c (modified) (2 diffs)
-
usbinfo/info.c (modified) (2 diffs)
-
usbinfo/main.c (modified) (1 diff)
-
usbinfo/usbinfo.h (modified) (1 diff)
-
websrv/websrv.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/klog/klog.c
rcf5c05c0 rb39eb79 205 205 klog_length = size / sizeof(wchar_t); 206 206 207 klog = (wchar_t *) as_get_mappable_page(size); 208 if (klog == NULL) { 209 fprintf(stderr, "%s: Unable to allocate virtual memory area\n", 210 NAME); 211 return ENOMEM; 212 } 213 214 rc = physmem_map((void *) faddr, (void *) klog, pages, 215 AS_AREA_READ | AS_AREA_CACHEABLE); 207 rc = physmem_map((void *) faddr, pages, 208 AS_AREA_READ | AS_AREA_CACHEABLE, (void *) &klog); 216 209 if (rc != EOK) { 217 210 fprintf(stderr, "%s: Unable to map klog\n", NAME); -
uspace/app/mkbd/main.c
rcf5c05c0 rb39eb79 48 48 #include <usb/dev/pipes.h> 49 49 #include <async.h> 50 #include <usb/dev.h> 50 51 #include <usb/hid/usages/core.h> 51 52 #include <usb/hid/hidparser.h> -
uspace/app/netecho/netecho.c
rcf5c05c0 rb39eb79 241 241 /* Accept a socket if a stream socket is used */ 242 242 addrlen = sizeof(address_buf); 243 if (verbose) 244 printf("accept()\n"); 243 245 socket_id = accept(listening_id, (void *) address_buf, &addrlen); 244 246 if (socket_id <= 0) { … … 258 260 259 261 /* Receive a message to echo */ 262 if (verbose) 263 printf("recvfrom()\n"); 260 264 rcv_size = recvfrom(socket_id, data, size, 0, address, 261 265 &addrlen); … … 297 301 298 302 /* Answer the request either with the static reply or the original data */ 299 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 300 if (rc != EOK) 301 socket_print_error(stderr, rc, "Socket send: ", "\n"); 303 if (type == SOCK_STREAM) { 304 if (verbose) 305 printf("send()\n"); 306 rc = send(socket_id, reply ? reply : data, reply ? reply_length : length, 0); 307 if (rc != EOK) 308 socket_print_error(stderr, rc, "Socket send: ", "\n"); 309 } else { 310 if (verbose) 311 printf("sendto()\n"); 312 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 313 if (rc != EOK) 314 socket_print_error(stderr, rc, "Socket send: ", "\n"); 315 } 302 316 } 303 317 -
uspace/app/tester/mm/common.c
rcf5c05c0 rb39eb79 342 342 link_initialize(&area->link); 343 343 344 /* Map the memory area */345 void *addr = as_get_mappable_page(size);346 if (a ddr == NULL) {344 area->addr = as_area_create((void *) -1, size, 345 AS_AREA_WRITE | AS_AREA_READ); 346 if (area->addr == (void *) -1) { 347 347 free(area); 348 348 check_consistency("map_area (a)"); 349 return NULL;350 }351 352 area->addr = as_area_create(addr, size, AS_AREA_WRITE | AS_AREA_READ);353 if (area->addr == (void *) -1) {354 free(area);355 check_consistency("map_area (b)");356 349 return NULL; 357 350 } -
uspace/app/tester/mm/mapping1.c
rcf5c05c0 rb39eb79 35 35 #include "../tester.h" 36 36 37 #define BUFFER1_PAGES 438 #define BUFFER2_PAGES 237 #define BUFFER1_PAGES 4 38 #define BUFFER2_PAGES 2 39 39 40 40 static void *create_as_area(size_t size) 41 41 { 42 void *result = as_get_mappable_page(size);43 42 TPRINTF("Creating AS area...\n"); 44 if (as_area_create(result, size, 45 AS_AREA_READ | AS_AREA_WRITE) != result) { 43 44 void *result = as_area_create((void *) -1, size, 45 AS_AREA_READ | AS_AREA_WRITE); 46 if (result == (void *) -1) 46 47 return NULL; 47 }48 48 49 return result; 49 50 } … … 71 72 int i; 72 73 for (i = 0; i < page_count; i++) { 73 void *page_start = ((char *) area) + PAGE_SIZE * i;74 void *page_start = ((char *) area) + PAGE_SIZE * i; 74 75 int rc = as_get_physical_mapping(page_start, NULL); 75 76 if (rc != expected_rc) { -
uspace/app/trace/syscalls.c
rcf5c05c0 rb39eb79 72 72 [SYS_PHYSMEM_MAP] = { "physmem_map", 4, V_ERRNO }, 73 73 [SYS_IOSPACE_ENABLE] = { "iospace_enable", 1, V_ERRNO }, 74 [SYS_ REGISTER_IRQ] = { "register_irq", 4, V_ERRNO },75 [SYS_ UNREGISTER_IRQ] = { "unregister_irq", 2, V_ERRNO },74 [SYS_IRQ_REGISTER] = { "irq_register", 4, V_ERRNO }, 75 [SYS_IRQ_UNREGISTER] = { "irq_unregister", 2, V_ERRNO }, 76 76 77 77 [SYS_SYSINFO_GET_VAL_TYPE] = { "sysinfo_get_val_type", 2, V_INTEGER }, -
uspace/app/usbinfo/dev.c
rcf5c05c0 rb39eb79 34 34 * Representation of queried device. 35 35 */ 36 #include <usb/dev/pipes.h> 36 #include <usb/dev.h> 37 #include <usb/hc.h> 37 38 #include <errno.h> 38 39 #include <str_error.h> … … 52 53 bool transfer_started = false; 53 54 54 rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr); 55 usb_hc_connection_initialize(&dev->hc_conn, hc_handle); 56 57 rc = usb_device_connection_initialize( 58 &dev->wire, &dev->hc_conn, dev_addr); 55 59 if (rc != EOK) { 56 60 fprintf(stderr, -
uspace/app/usbinfo/info.c
rcf5c05c0 rb39eb79 287 287 void dump_strings(usbinfo_device_t *dev) 288 288 { 289 /* Find used indexes. Devices with more than 64 strings are very rare.*/ 290 uint64_t str_mask = 0; 291 find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0, 292 &str_mask); 293 usb_dp_walk_simple(dev->full_configuration_descriptor, 294 dev->full_configuration_descriptor_size, 295 usb_dp_standard_descriptor_nesting, 296 find_string_indexes_callback, 297 &str_mask); 298 299 if (str_mask == 0) { 300 printf("Device does not support string descriptors.\n"); 301 return; 302 } 303 289 304 /* Get supported languages. */ 290 305 l18_win_locales_t *langs; … … 305 320 } 306 321 printf(".\n"); 307 308 /* Find used indexes. Device with more than 64 strings are very rare.309 */310 uint64_t str_mask = 0;311 find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,312 &str_mask);313 usb_dp_walk_simple(dev->full_configuration_descriptor,314 dev->full_configuration_descriptor_size,315 usb_dp_standard_descriptor_nesting,316 find_string_indexes_callback,317 &str_mask);318 322 319 323 /* Get all strings and dump them. */ -
uspace/app/usbinfo/main.c
rcf5c05c0 rb39eb79 44 44 #include <loc.h> 45 45 #include <usb/hc.h> 46 #include <usb/dev.h> 46 47 #include <usb/dev/pipes.h> 47 48 #include "usbinfo.h" -
uspace/app/usbinfo/usbinfo.h
rcf5c05c0 rb39eb79 44 44 45 45 typedef struct { 46 usb_hc_connection_t hc_conn; 47 usb_device_connection_t wire; 46 48 usb_pipe_t ctrl_pipe; 47 usb_device_connection_t wire;48 49 usb_standard_device_descriptor_t device_descriptor; 49 50 uint8_t *full_configuration_descriptor; -
uspace/app/websrv/websrv.c
rcf5c05c0 rb39eb79 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 31 31 */ 32 32 /** 33 * @file (Less-than-skeleton)web server.33 * @file Skeletal web server. 34 34 */ 35 35 36 #include <bool.h> 37 #include <errno.h> 36 38 #include <stdio.h> 39 #include <sys/types.h> 40 #include <sys/stat.h> 41 #include <stdlib.h> 42 #include <fcntl.h> 37 43 38 44 #include <net/in.h> … … 44 50 #define PORT_NUMBER 8080 45 51 52 #define WEB_ROOT "/data/web" 53 46 54 /** Buffer for receiving the request. */ 47 55 #define BUFFER_SIZE 1024 48 static char buf[BUFFER_SIZE]; 56 static char rbuf[BUFFER_SIZE]; 57 static size_t rbuf_out, rbuf_in; 58 59 static char lbuf[BUFFER_SIZE + 1]; 60 static size_t lbuf_used; 61 62 static char fbuf[BUFFER_SIZE]; 49 63 50 64 /** Response to send to client. */ 51 static const char * response_msg =65 static const char *ok_msg = 52 66 "HTTP/1.0 200 OK\r\n" 53 "\r\n" 54 "<h1>Hello from HelenOS!</h1>\r\n"; 67 "\r\n"; 68 69 /** Receive one character (with buffering) */ 70 static int recv_char(int fd, char *c) 71 { 72 ssize_t rc; 73 74 if (rbuf_out == rbuf_in) { 75 rbuf_out = 0; 76 rbuf_in = 0; 77 78 rc = recv(fd, rbuf, BUFFER_SIZE, 0); 79 if (rc <= 0) { 80 printf("recv() failed (%zd)\n", rc); 81 return rc; 82 } 83 84 rbuf_in = rc; 85 } 86 87 *c = rbuf[rbuf_out++]; 88 return EOK; 89 } 90 91 /** Receive one line with length limit. */ 92 static int recv_line(int fd) 93 { 94 char c, prev; 95 int rc; 96 char *bp; 97 98 bp = lbuf; c = '\0'; 99 while (bp < lbuf + BUFFER_SIZE) { 100 prev = c; 101 rc = recv_char(fd, &c); 102 if (rc != EOK) 103 return rc; 104 105 *bp++ = c; 106 if (prev == '\r' && c == '\n') 107 break; 108 } 109 110 lbuf_used = bp - lbuf; 111 *bp = '\0'; 112 113 if (bp == lbuf + BUFFER_SIZE) 114 return ELIMIT; 115 116 return EOK; 117 } 118 119 static bool uri_is_valid(char *uri) 120 { 121 char *cp; 122 char c; 123 124 if (uri[0] != '/') 125 return false; 126 if (uri[1] == '.') 127 return false; 128 129 cp = uri + 1; 130 while (*cp != '\0') { 131 c = *cp++; 132 if (c == '/') 133 return false; 134 } 135 136 return true; 137 } 138 139 static int send_response(int conn_sd, const char *msg) 140 { 141 size_t response_size; 142 ssize_t rc; 143 144 response_size = str_size(msg); 145 146 /* Send a canned response. */ 147 printf("Send response...\n"); 148 rc = send(conn_sd, (void *) msg, response_size, 0); 149 if (rc < 0) { 150 printf("send() failed.\n"); 151 return rc; 152 } 153 154 return EOK; 155 } 156 157 static int uri_get(const char *uri, int conn_sd) 158 { 159 int rc; 160 char *fname; 161 int fd; 162 ssize_t nr; 163 164 if (str_cmp(uri, "/") == 0) 165 uri = "/index.htm"; 166 167 rc = asprintf(&fname, "%s%s", WEB_ROOT, uri); 168 if (rc < 0) 169 return ENOMEM; 170 171 fd = open(fname, O_RDONLY); 172 if (fd < 0) { 173 printf("File '%s' not found.\n", fname); 174 free(fname); 175 return ENOENT; 176 } 177 178 free(fname); 179 180 rc = send_response(conn_sd, ok_msg); 181 if (rc != EOK) 182 return rc; 183 184 while (true) { 185 nr = read(fd, fbuf, BUFFER_SIZE); 186 if (nr == 0) 187 break; 188 189 if (nr < 0) { 190 close(fd); 191 return EIO; 192 } 193 194 rc = send(conn_sd, fbuf, nr, 0); 195 if (rc < 0) { 196 printf("send() failed\n"); 197 close(fd); 198 return rc; 199 } 200 } 201 202 close(fd); 203 204 return EOK; 205 } 206 207 static int req_process(int conn_sd) 208 { 209 int rc; 210 char *uri, *end_uri; 211 212 rc = recv_line(conn_sd); 213 if (rc != EOK) { 214 printf("recv_line() failed\n"); 215 return rc; 216 } 217 218 printf("%s", lbuf); 219 220 if (str_lcmp(lbuf, "GET ", 4) != 0) { 221 printf("Invalid HTTP method.\n"); 222 return EINVAL; 223 } 224 225 uri = lbuf + 4; 226 end_uri = str_chr(uri, ' '); 227 if (end_uri == NULL) { 228 end_uri = lbuf + lbuf_used - 2; 229 assert(*end_uri == '\r'); 230 } 231 232 *end_uri = '\0'; 233 printf("Requested URI '%s'.\n", uri); 234 235 if (!uri_is_valid(uri)) { 236 printf("Invalid request URI.\n"); 237 return EINVAL; 238 } 239 240 return uri_get(uri, conn_sd); 241 } 55 242 56 243 int main(int argc, char *argv[]) … … 64 251 int rc; 65 252 66 size_t response_size;67 253 68 254 addr.sin_family = AF_INET; … … 94 280 return 1; 95 281 } 96 97 response_size = str_size(response_msg);98 282 99 283 printf("Listening for connections at port number %u.\n", PORT_NUMBER); … … 105 289 if (conn_sd < 0) { 106 290 printf("accept() failed.\n"); 107 return 1;291 continue; 108 292 } 109 293 … … 111 295 112 296 printf("Wait for client request\n"); 113 114 /* Really we should wait for a blank line. */ 115 rc = recv(conn_sd, buf, BUFFER_SIZE, 0); 116 if (rc < 0) { 117 printf("recv() failed\n"); 118 return 1; 119 } 120 121 /* Send a canned response. */ 122 printf("Send response...\n"); 123 rc = send(conn_sd, (void *) response_msg, response_size, 0); 124 if (rc < 0) { 125 printf("send() failed.\n"); 126 return 1; 127 } 297 rbuf_out = rbuf_in = 0; 298 299 rc = req_process(conn_sd); 300 if (rc != EOK) 301 printf("Error processing request.\n"); 128 302 129 303 rc = closesocket(conn_sd); 130 304 if (rc != EOK) { 131 305 printf("Error closing connection socket: %d\n", rc); 306 closesocket(listen_sd); 132 307 return 1; 133 308 }
Note:
See TracChangeset
for help on using the changeset viewer.
