You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.3 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Perior_action_count 5
int main(int argc, char *argv[]) {
//char *str = "{\"__ow_body\": [{\"action_name\": \"/guest/noop2\", \"activation_id\": \"ae0b8d60759642d18b8d60759622d14c\", \"message\": \" hello world!\"}, {\"action_name\": \"/guest/noop3\", \"activation_id\": \"52b5d51af9bd40a0b5d51af9bd10a078\", \"message\": \" hello world!\"}], \"__ow_headers\": {\"accept\": \"*/*\", \"accept-encoding\": \"gzip, deflate\", \"content-type\": \"application/json\", \"host\": \"controllers\", \"user-agent\": \"python-requests/2.18.4\", \"x-forwarded-for\": \"172.17.0.1\", \"x-forwarded-host\": \"172.17.0.1\", \"x-forwarded-port\": \"8080\", \"x-forwarded-proto\": \"http\", \"x-forwarded-url\": \"http://172.17.0.1/api/23bc46b1-71f6-4ed5-8c54-816aa4f8c502/noop4-api/noop4-path\", \"x-real-ip\": \"172.17.0.1\", \"x-request-id\": \"fda5d48c51bbc97ee8602d3f2ab8d90a\"}, \"__ow_method\": \"post\", \"__ow_path\": \"\"}";
char *str = argv[1];
char *value = NULL ;
char *key = "action_name";
char *perior_action[Perior_action_count];
int perior_action_count=0;
char *start = strstr(str, key);
while (start)
{
start =start+ strlen(key) + 4; // 跳过键部分,指向值的开始
char *end = strstr(start, ",");
//end +=2 ; // 查找值的结束引号
int length = end - start;
value = (char *)malloc(length + 1); // +1 用于存储字符串结束符
if (value == NULL) printf("Memory allocation failed\n");
if (end) {
// 复制值到 value 中
strncpy(value, start, length-1);
value[length] = '\0'; // 添加字符串结束符
}
perior_action[perior_action_count]=value;
perior_action_count++;
start = strstr(end, key);
}
printf ("argv1:%s\n",argv[1]);
if (perior_action_count != 0)
{for (int i = 0; i < perior_action_count; i++)
{printf("perior action:%s\n",perior_action[i]);
free (perior_action[i]);}
}
const char *actvation_id = getenv("__OW_ACTIVATION_ID");
const char *action = getenv("__OW_ACTION_NAME");
printf("{\"action_name\" : \"%s\", \"activation_id\":\"%s\",\"message\": \" hello world!\" }\n",action,actvation_id);
return 0; // 返回 0 表示程序成功
}