MCPcopy Create free account
hub / github.com/apache/trafficserver / TSPluginInit

Function TSPluginInit

example/plugins/c-api/add_header/add_header.cc:123–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123void
124TSPluginInit(int argc, const char *argv[])
125{
126 TSMLoc field_loc;
127 const char *p;
128 int i, retval;
129 TSPluginRegistrationInfo info;
130
131 info.plugin_name = PLUGIN_NAME;
132 info.vendor_name = "Apache Software Foundation";
133 info.support_email = "dev@trafficserver.apache.org";
134
135 if (TSPluginRegister(&info) != TS_SUCCESS) {
136 TSError("[%s] Plugin registration failed", PLUGIN_NAME);
137 goto error;
138 }
139
140 if (argc < 2) {
141 TSError(R"([%s] Usage: %s "name1: value1" "name2: value2" ...>)", PLUGIN_NAME, argv[0]);
142 goto error;
143 }
144
145 hdr_bufp = TSMBufferCreate();
146 if (TSMimeHdrCreate(hdr_bufp, &hdr_loc) != TS_SUCCESS) {
147 TSError("[%s] Can not create mime header", PLUGIN_NAME);
148 goto error;
149 }
150
151 for (i = 1; i < argc; i++) {
152 if (TSMimeHdrFieldCreate(hdr_bufp, hdr_loc, &field_loc) != TS_SUCCESS) {
153 TSError("[%s] Unable to create field", PLUGIN_NAME);
154 goto error;
155 }
156
157 p = strchr(argv[i], ':');
158 if (p) {
159 retval = TSMimeHdrFieldNameSet(hdr_bufp, hdr_loc, field_loc, argv[i], p - argv[i]);
160 if (retval == TS_ERROR) {
161 TSError("[%s] Unable to name field", PLUGIN_NAME);
162 goto error;
163 }
164
165 p += 1;
166 while (isspace(*p)) {
167 p += 1;
168 }
169 retval = TSMimeHdrFieldValueStringInsert(hdr_bufp, hdr_loc, field_loc, -1, p, strlen(p));
170 if (retval == TS_ERROR) {
171 TSError("[%s] Unable to insert field value", PLUGIN_NAME);
172 goto error;
173 }
174 } else {
175 retval = TSMimeHdrFieldNameSet(hdr_bufp, hdr_loc, field_loc, argv[i], strlen(argv[i]));
176 if (retval == TS_ERROR) {
177 TSError("[%s] Unable to set field name", PLUGIN_NAME);
178 goto error;
179 }
180 }

Callers

nothing calls this directly

Calls 11

TSPluginRegisterFunction · 0.85
TSMBufferCreateFunction · 0.85
TSMimeHdrCreateFunction · 0.85
TSMimeHdrFieldCreateFunction · 0.85
TSMimeHdrFieldNameSetFunction · 0.85
TSMimeHdrFieldAppendFunction · 0.85
TSHttpHookAddFunction · 0.85
TSContCreateFunction · 0.85
TSMutexCreateFunction · 0.85
TSErrorFunction · 0.50

Tested by

no test coverage detected