#include <vppinfra/bihash_template.c>
-/** @file Static http server, sufficient to
- serve .html / .css / .js content.
-*/
+/** @file static_server.c
+ * Static http server, sufficient to
+ * serve .html / .css / .js content.
+ */
/*? %%clicmd:group_label Static HTTP Server %% ?*/
http_static_server_main_t http_static_server_main;
vec_free (hs->path);
}
-/** \brief clean up a session
- */
-
-static void
-http_static_server_session_cleanup (http_session_t * hs)
-{
- if (!hs)
- return;
-
- http_static_server_detach_cache_entry (hs);
-
- http_static_server_session_lookup_del (hs->thread_index,
- hs->vpp_session_index);
- vec_free (hs->rx_buf);
- http_static_server_session_free (hs);
-}
-
/** \brief Disconnect a session
*/
-
static void
http_static_server_session_disconnect (http_session_t * hs)
{
/** \brief send http data
@param hs - http session
@param data - the data vector to transmit
+ @param length - length of data
@param offset - transmit offset for this operation
@return offset for next transmit operation, may be unchanged w/ full fifo
*/
close_session (http_session_t * hs)
{
http_static_server_session_disconnect (hs);
- http_static_server_session_cleanup (hs);
}
/** \brief Register a builtin GET or POST handler
dp = pool_elt_at_index (hsm->cache_pool, kv.value);
hs->data = dp->data;
/* Update the cache entry, mark it in-use */
- lru_update (hsm, dp, vlib_time_now (hsm->vlib_main));
+ lru_update (hsm, dp, vlib_time_now (vlib_get_main ()));
hs->cache_pool_index = dp - hsm->cache_pool;
dp->inuse++;
if (hsm->debug_level > 1)
if (hsm->debug_level > 1)
clib_warning ("index %d refcnt now %d", hs->cache_pool_index,
dp->inuse);
- lru_add (hsm, dp, vlib_time_now (hsm->vlib_main));
+ lru_add (hsm, dp, vlib_time_now (vlib_get_main ()));
kv.key = (u64) vec_dup (hs->path);
kv.value = dp - hsm->cache_pool;
/* Add to the lookup table */
/* What kind of dog food are we serving? */
suffix = (char *) (hs->path + vec_len (hs->path) - 1);
- while (*suffix != '.')
+ while ((u8 *) suffix >= hs->path && *suffix != '.')
suffix--;
suffix++;
http_type = "text/html";
{
http_static_server_main_t *hsm = &http_static_server_main;
vnet_disconnect_args_t _a = { 0 }, *a = &_a;
- http_session_t *hs;
-
- http_static_server_sessions_writer_lock ();
-
- hs = http_static_server_session_lookup (s->thread_index, s->session_index);
- http_static_server_session_cleanup (hs);
-
- http_static_server_sessions_writer_unlock ();
a->handle = session_handle (s);
a->app_index = hsm->app_index;
{
http_static_server_main_t *hsm = &http_static_server_main;
vnet_disconnect_args_t _a = { 0 }, *a = &_a;
- http_session_t *hs;
-
- http_static_server_sessions_writer_lock ();
-
- hs = http_static_server_session_lookup (s->thread_index, s->session_index);
- http_static_server_session_cleanup (hs);
-
- http_static_server_sessions_writer_unlock ();
a->handle = session_handle (s);
a->app_index = hsm->app_index;
static int
http_static_server_session_connected_callback (u32 app_index, u32 api_context,
- session_t * s, u8 is_fail)
+ session_t * s,
+ session_error_t err)
{
clib_warning ("called...");
return -1;
return -1;
}
+static void
+http_static_session_cleanup (session_t * s, session_cleanup_ntf_t ntf)
+{
+ http_session_t *hs;
+
+ if (ntf == SESSION_CLEANUP_TRANSPORT)
+ return;
+
+ http_static_server_sessions_writer_lock ();
+
+ hs = http_static_server_session_lookup (s->thread_index, s->session_index);
+ if (!hs)
+ goto done;
+
+ http_static_server_detach_cache_entry (hs);
+ http_static_server_session_lookup_del (hs->thread_index,
+ hs->vpp_session_index);
+ vec_free (hs->rx_buf);
+ http_static_server_session_free (hs);
+
+done:
+ http_static_server_sessions_writer_unlock ();
+}
+
/** \brief Session-layer virtual function table
*/
static session_cb_vft_t http_static_server_session_cb_vft = {
.add_segment_callback = http_static_server_add_segment_callback,
.builtin_app_rx_callback = http_static_server_rx_callback,
.builtin_app_tx_callback = http_static_server_tx_callback,
- .session_reset_callback = http_static_server_session_reset_callback
+ .session_reset_callback = http_static_server_session_reset_callback,
+ .session_cleanup_callback = http_static_session_cleanup,
};
static int
}
static void
-http_static_server_session_cleanup_cb (void *hs_handlep)
+http_static_server_session_close_cb (void *hs_handlep)
{
http_static_server_main_t *hsm = &http_static_server_main;
http_session_t *hs;
return;
hs->timer_handle = ~0;
http_static_server_session_disconnect (hs);
- http_static_server_session_cleanup (hs);
}
/** \brief Expired session timer-wheel callback
/* Get session handle. The first bit is the timer id */
hs_handle = expired_timers[i] & 0x7FFFFFFF;
session_send_rpc_evt_to_thread (hs_handle >> 24,
- http_static_server_session_cleanup_cb,
+ http_static_server_session_close_cb,
uword_to_pointer (hs_handle, void *));
}
}
hsm->first_index = hsm->last_index = ~0;
clib_timebase_init (&hsm->timebase, 0 /* GMT */ ,
- CLIB_TIMEBASE_DAYLIGHT_NONE);
+ CLIB_TIMEBASE_DAYLIGHT_NONE,
+ &vm->clib_time /* share the system clock */ );
return 0;
}