UbixOS  2.0
shell.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the lwIP TCP/IP stack.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  * $Id: shell.c 54 2016-01-11 01:29:55Z reddawg $
34  */
35 
36 #include <lib/kmalloc.h>
37 #include <ubixos/fork.h>
38 #include <string.h>
39 
40 #include "net/mem.h"
41 #include "net/debug.h"
42 #include "net/def.h"
43 #include <net/api.h>
44 #include "net/stats.h"
45 
46 #include "lib/kprintf.h"
47 char *buffer = 0x0;
48 
49 #define ESUCCESS 0
50 #define ESYNTAX -1
51 #define ETOOFEW -2
52 #define ETOOMANY -3
53 #define ECLOSED -4
54 
55 #define NCONNS 10
56 // UBU static struct netconn *conns[NCONNS];
57 
58 static void sendstr(const char *str, struct netconn *conn) {
59  netconn_write(conn, (void *) str, strlen(str), NETCONN_COPY);
60 }
61 
62 static void prompt(struct netconn *conn) {
63  sendstr("uBixCube:@sys> ", conn);
64 }
65 
66 static void shell_main(struct netconn *conn) {
67  struct netbuf *buf = 0x0;
68  uInt32 len;
69  uInt32 err = 0;
70  // UBU int i;
71  // UBU char bufr[1500];
72  buf = kmalloc(1500);
73  prompt(conn);
74  while (1) {
75  err = netconn_recv(conn, &buf);
76  if (buf != 0x0)
77  netbuf_copy(buf, buffer, 1024);
78  len = netbuf_len(buf);
79  netbuf_delete(buf);
80  buffer[len - 2] = '\0';
81  if (!strcmp(buffer, "quit")) {
82  netconn_close(conn);
83  break;
84  }
85  else if (!strcmp(buffer, "ls")) {
86  sendstr("no\nfiles\nhere\n", conn);
87  }
88  else if (!strcmp(buffer, "uname")) {
89  sendstr("UbixOS v1.0 reddawg@devel.ubixos.com:/ubix.elf\n", conn);
90  }
91  prompt(conn);
92  }
93 }
94 
95 void shell_thread(void *arg) {
96  struct netconn *conn = 0x0, *newconn = 0x0;
97 
98  buffer = (char *) kmalloc(1024);
99 
100  conn = netconn_new(NETCONN_TCP);
101 
102  netconn_bind(conn, IP4_ADDR_ANY, 23);
103  netconn_listen(conn);
104 
105  while (1) {
106  netconn_accept(conn,&newconn);
107  shell_main(newconn);
108  //netconn_delete(newconn);
109  }
110 }
def.h
buffer
char * buffer
Definition: shell.c:47
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
fork.h
string.h
shell_thread
void shell_thread(void *arg)
Definition: shell.c:95
strcmp
int strcmp(const char *str1, const char *str2)
strlen
int strlen(const char *str)
Definition: strlen.c:55
stats.h
kprintf.h
buf
Definition: buf.h:35
kmalloc
void * kmalloc(uInt32 len)
Definition: kmalloc.c:241
mem.h
kmalloc.h
debug.h
api.h