Changeset b39eb79 in mainline for uspace/app


Ignore:
Timestamp:
2011-12-26T17:21:21Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
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.
Message:

Mainline changes.

Location:
uspace/app
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/klog/klog.c

    rcf5c05c0 rb39eb79  
    205205        klog_length = size / sizeof(wchar_t);
    206206       
    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);
    216209        if (rc != EOK) {
    217210                fprintf(stderr, "%s: Unable to map klog\n", NAME);
  • uspace/app/mkbd/main.c

    rcf5c05c0 rb39eb79  
    4848#include <usb/dev/pipes.h>
    4949#include <async.h>
     50#include <usb/dev.h>
    5051#include <usb/hid/usages/core.h>
    5152#include <usb/hid/hidparser.h>
  • uspace/app/netecho/netecho.c

    rcf5c05c0 rb39eb79  
    241241                /* Accept a socket if a stream socket is used */
    242242                addrlen = sizeof(address_buf);
     243                if (verbose)
     244                        printf("accept()\n");
    243245                socket_id = accept(listening_id, (void *) address_buf, &addrlen);
    244246                if (socket_id <= 0) {
     
    258260
    259261                /* Receive a message to echo */
     262                if (verbose)
     263                        printf("recvfrom()\n");
    260264                rcv_size = recvfrom(socket_id, data, size, 0, address,
    261265                    &addrlen);
     
    297301
    298302                        /* 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                        }
    302316                }
    303317
  • uspace/app/tester/mm/common.c

    rcf5c05c0 rb39eb79  
    342342        link_initialize(&area->link);
    343343       
    344         /* Map the memory area */
    345         void *addr = as_get_mappable_page(size);
    346         if (addr == NULL) {
     344        area->addr = as_area_create((void *) -1, size,
     345            AS_AREA_WRITE | AS_AREA_READ);
     346        if (area->addr == (void *) -1) {
    347347                free(area);
    348348                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)");
    356349                return NULL;
    357350        }
  • uspace/app/tester/mm/mapping1.c

    rcf5c05c0 rb39eb79  
    3535#include "../tester.h"
    3636
    37 #define BUFFER1_PAGES 4
    38 #define BUFFER2_PAGES 2
     37#define BUFFER1_PAGES  4
     38#define BUFFER2_PAGES  2
    3939
    4040static void *create_as_area(size_t size)
    4141{
    42         void *result = as_get_mappable_page(size);
    4342        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)
    4647                return NULL;
    47         }
     48       
    4849        return result;
    4950}
     
    7172        int i;
    7273        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;
    7475                int rc = as_get_physical_mapping(page_start, NULL);
    7576                if (rc != expected_rc) {
  • uspace/app/trace/syscalls.c

    rcf5c05c0 rb39eb79  
    7272    [SYS_PHYSMEM_MAP] = { "physmem_map",                4,      V_ERRNO },
    7373    [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 },
    7676
    7777    [SYS_SYSINFO_GET_VAL_TYPE] = { "sysinfo_get_val_type",              2,      V_INTEGER },
  • uspace/app/usbinfo/dev.c

    rcf5c05c0 rb39eb79  
    3434 * Representation of queried device.
    3535 */
    36 #include <usb/dev/pipes.h>
     36#include <usb/dev.h>
     37#include <usb/hc.h>
    3738#include <errno.h>
    3839#include <str_error.h>
     
    5253        bool transfer_started = false;
    5354
    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);
    5559        if (rc != EOK) {
    5660                fprintf(stderr,
  • uspace/app/usbinfo/info.c

    rcf5c05c0 rb39eb79  
    287287void dump_strings(usbinfo_device_t *dev)
    288288{
     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
    289304        /* Get supported languages. */
    290305        l18_win_locales_t *langs;
     
    305320        }
    306321        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);
    318322
    319323        /* Get all strings and dump them. */
  • uspace/app/usbinfo/main.c

    rcf5c05c0 rb39eb79  
    4444#include <loc.h>
    4545#include <usb/hc.h>
     46#include <usb/dev.h>
    4647#include <usb/dev/pipes.h>
    4748#include "usbinfo.h"
  • uspace/app/usbinfo/usbinfo.h

    rcf5c05c0 rb39eb79  
    4444
    4545typedef struct {
     46        usb_hc_connection_t hc_conn;
     47        usb_device_connection_t wire;
    4648        usb_pipe_t ctrl_pipe;
    47         usb_device_connection_t wire;
    4849        usb_standard_device_descriptor_t device_descriptor;
    4950        uint8_t *full_configuration_descriptor;
  • uspace/app/websrv/websrv.c

    rcf5c05c0 rb39eb79  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/**
    33  * @file (Less-than-skeleton) web server.
     33 * @file Skeletal web server.
    3434 */
    3535
     36#include <bool.h>
     37#include <errno.h>
    3638#include <stdio.h>
     39#include <sys/types.h>
     40#include <sys/stat.h>
     41#include <stdlib.h>
     42#include <fcntl.h>
    3743
    3844#include <net/in.h>
     
    4450#define PORT_NUMBER 8080
    4551
     52#define WEB_ROOT "/data/web"
     53
    4654/** Buffer for receiving the request. */
    4755#define BUFFER_SIZE 1024
    48 static char buf[BUFFER_SIZE];
     56static char rbuf[BUFFER_SIZE];
     57static size_t rbuf_out, rbuf_in;
     58
     59static char lbuf[BUFFER_SIZE + 1];
     60static size_t lbuf_used;
     61
     62static char fbuf[BUFFER_SIZE];
    4963
    5064/** Response to send to client. */
    51 static const char *response_msg =
     65static const char *ok_msg =
    5266    "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) */
     70static 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. */
     92static 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
     119static 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
     139static 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
     157static 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
     207static 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}
    55242
    56243int main(int argc, char *argv[])
     
    64251        int rc;
    65252
    66         size_t response_size;
    67253
    68254        addr.sin_family = AF_INET;
     
    94280                return 1;
    95281        }
    96 
    97         response_size = str_size(response_msg);
    98282
    99283        printf("Listening for connections at port number %u.\n", PORT_NUMBER);
     
    105289                if (conn_sd < 0) {
    106290                        printf("accept() failed.\n");
    107                         return 1;
     291                        continue;
    108292                }
    109293
     
    111295
    112296                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");
    128302
    129303                rc = closesocket(conn_sd);
    130304                if (rc != EOK) {
    131305                        printf("Error closing connection socket: %d\n", rc);
     306                        closesocket(listen_sd);
    132307                        return 1;
    133308                }
Note: See TracChangeset for help on using the changeset viewer.