diff --git a/content/kamailio/_index.md b/content/kamailio/_index.md index 563ec78aa8..c978dae405 100644 --- a/content/kamailio/_index.md +++ b/content/kamailio/_index.md @@ -13,4 +13,8 @@ toc: true # 文章列表 - 1. 文档 - - [第一节 如何熟悉Kamailio文档的文档结构](/kamailio/docs-index) \ No newline at end of file + - [熟悉Kamailio文档的文档结构](/kamailio/docs-index) + - [路由执行顺序](./msg-flow/) + - [kamailio 启动参数控制](./kamailio-cli-params) + - [DMQ模块源码学习笔记](./dmq-note) + - [源码笔记 - 自定义事件路由(上)](./customer-event-route) \ No newline at end of file diff --git a/content/kamailio/route-list-action/index.md b/content/kamailio/route-list-action/index.md new file mode 100644 index 0000000000..65cdd7f8fc --- /dev/null +++ b/content/kamailio/route-list-action/index.md @@ -0,0 +1,174 @@ +--- +title: "源码笔记 - 自定义事件路由(中)" +date: "2024-12-28 09:43:00" +draft: false +type: posts +tags: +- all +categories: +- all +--- + + + +[[_TOC_]] + + + +# route_list + +route.h定义了几个函数分别用来获取、查找、新增route + +```c +// src/core/route.h +int route_get(struct route_list *rt, char *name); +int route_lookup(struct route_list *rt, char *name); +void push(struct action *a, struct action **head); + +struct route_list +{ + struct action **rlist; + int idx; /* first empty entry */ + int entries; /* total number of entries */ + struct str_hash_table names; /* name to route index mappings */ +}; +``` + + + +## rlist + +我们对route_list数据模型进行简化: + +rlist是一个固定长度的一维数组,通过索引来访问对应的值。如果数组的空间不足,那么就创建一个两倍大的空数据,然后先把原始数据复制过去。这种复制方式保持的原始数据的索引位置。有点像golang的切片扩容机制。 + +这里最为重要的就是保持数组元素的索引位置在扩容后不变。 + +```c +static inline int route_new_list(struct route_list *rt) +{ + int ret; + struct action **tmp; + + ret = -1; + if(rt->idx >= rt->entries) { + // 两倍扩容 + tmp = pkg_realloc(rt->rlist, 2 * rt->entries * sizeof(struct action *)); + if(tmp == 0) { + LM_CRIT("out of memory\n"); + goto end; + } + /* init the newly allocated memory chunk */ + memset(&tmp[rt->entries], 0, rt->entries * sizeof(struct action *)); + rt->rlist = tmp; + rt->entries *= 2; + } + if(rt->idx < rt->entries) { + ret = rt->idx; + rt->idx++; + } +end: + return ret; +} +``` + + + +## str_hash_table + +我们对hash_table的数据模型进行简化,它其实就是一hash表,key是路由的名,值是一个正数,正数代表了路由执行单元的索引位置。 + + + +如果我们用js对route_list来表示 + +1. dispatcher:dst-down对应的是索引0 +2. 索引0在rlist里对应的是func1 +3. dispatcher:dst-down事件发生后,调用func1 + +```js +let rlist = [func1, func2, func3] +let names = { + 'dispatcher:dst-down': 0, + 'rtpengine:dtmf-event': 1 +} +``` + +其实这里完全可以不用数组,如果在js里, 可以直接用函数作为hash的key + +```js +let names = { + 'dispatcher:dst-down': func1, + 'rtpengine:dtmf-event': func2 +} +``` + + + +## action + +```c +// src/core/route_struct.h +struct action +{ + int cline; + char *cfile; + char *rname; + enum action_type type; /* forward, drop, log, send ...*/ + int count; + struct action *next; + action_u_t val[MAX_ACTIONS]; +}; +``` + + + +## str_hash_table + +```c +struct str_hash_table +{ + struct str_hash_head *table; + int size; +}; + +struct str_hash_head +{ + struct str_hash_entry *next; + struct str_hash_entry *prev; +}; + +struct str_hash_entry +{ + struct str_hash_entry *next; + struct str_hash_entry *prev; + str key; + unsigned int flags; + union + { + void *p; + char *s; + int n; + char data[sizeof(void *)]; + } u; +}; +``` + + + + + +在src/core/route.c中定义如下几个变量,分别管理着6钟不同的路由。 + +```c +// src/core/route.c +/* main routing script table */ +struct route_list main_rt; +struct route_list onreply_rt; +struct route_list failure_rt; +struct route_list branch_rt; +struct route_list onsend_rt; +struct route_list event_rt; +``` + + diff --git a/content/posts/2022/05/02-hugo-add-mermaid.md b/content/posts/2022/05/02-hugo-add-mermaid.md index 17ba91f006..b20be9d119 100644 --- a/content/posts/2022/05/02-hugo-add-mermaid.md +++ b/content/posts/2022/05/02-hugo-add-mermaid.md @@ -9,58 +9,47 @@ categories: - hugo --- -# 增加mermaid shortcodes +# step1 -在themes/YourTheme/layouts/shortcodes/mermaid.html 增加如下内容 +在themes/YourTheme/layouts/partials/footer.html 的最后追加如下内容 ```html - - - -
+ {{- .Inner | htmlEscape | safeHTML }} ++{{ .Page.Store.Set "hasMermaid" true }} ``` # 在blog中增加如下代码 -{{< notice warning >}} -注意下面的代码,你在实际写的时候,要把 /* 和 */ 删除 -{{< /notice >}} -```go -{{/*< mermaid align="left" theme="neutral" */>}} +```mermaid pie title French Words I Know "Merde" : 50 "Oui" : 35 "Alors" : 10 "Non" : 5 -{{/*< /mermaid >*/}} ``` -{{< mermaid align="left" theme="neutral" >}} -pie - title French Words I Know - "Merde" : 50 - "Oui" : 35 - "Alors" : 10 - "Non" : 5 -{{< /mermaid >}} - -{{< mermaid align="left" theme="neutral" >}} +```mermaid sequenceDiagram title French Words I Know autonumber Alice->>Bob: hello Bob-->>Alice: hi Alice->Bob: talking -{{< /mermaid >}} \ No newline at end of file +``` \ No newline at end of file diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html new file mode 100644 index 0000000000..7e754f406b --- /dev/null +++ b/layouts/_default/_markup/render-codeblock-mermaid.html @@ -0,0 +1,4 @@ +
+ {{- .Inner | htmlEscape | safeHTML }} ++{{ .Page.Store.Set "hasMermaid" true }} \ No newline at end of file diff --git a/themes/PaperMod/layouts/partials/footer.html b/themes/PaperMod/layouts/partials/footer.html index 52668eb306..93fae65425 100644 --- a/themes/PaperMod/layouts/partials/footer.html +++ b/themes/PaperMod/layouts/partials/footer.html @@ -133,3 +133,10 @@ }); {{- end }} + +{{if .Store.Get "hasMermaid" }} + +{{end }} \ No newline at end of file diff --git a/themes/PaperMod/layouts/shortcodes/mermaid.html b/themes/PaperMod/layouts/shortcodes/mermaid.html.bak similarity index 100% rename from themes/PaperMod/layouts/shortcodes/mermaid.html rename to themes/PaperMod/layouts/shortcodes/mermaid.html.bak