static int parse_msrp(char *sz, size_t len, struct mrpdhelper_notify *n) { if (parse_notification(&sz[1], n) < 0) return -1; if (parse_msrp_string(&sz[4], len - 4, n) < 0) return -1; return parse_registrar(sz, n, NULL); }
int api_notification_list(ONION_FUNC_PROTO_STR) { const char * userid = onion_request_get_query(req, "userid"); const char * appkey = onion_request_get_query(req, "appkey"); const char * sessid = onion_request_get_query(req, "sessid"); if (userid == NULL || sessid == NULL || appkey == NULL) { return api_error(p, req, res, API_RT_WRONGPARAM); } struct userec *ue = getuser(userid); if (ue == 0) { return api_error(p, req, res, API_RT_NOSUCHUSER); } int r = check_user_session(ue, sessid, appkey); if (r != API_RT_SUCCESSFUL) { free(ue); return api_error(p, req, res, r); } struct json_object *obj = json_tokener_parse("{\"errcode\": 0, \"notifications\": []}"); struct json_object *noti_array = json_object_object_get(obj, "notifications"); NotifyItemList allNotifyItems = parse_notification(ue->userid); struct json_object * item = NULL; struct NotifyItem * currItem; struct boardmem *b; for (currItem = (struct NotifyItem *)allNotifyItems; currItem != NULL; currItem = currItem->next) { item = json_object_new_object(); json_object_object_add(item, "board", json_object_new_string(currItem->board)); json_object_object_add(item, "noti_time", json_object_new_int64(currItem->noti_time)); json_object_object_add(item, "from_userid", json_object_new_string(currItem->from_userid)); json_object_object_add(item, "title", json_object_new_string(currItem->title_utf)); json_object_object_add(item, "type", json_object_new_int(currItem->type)); b = getboardbyname(currItem->board); json_object_object_add(item, "secstr", json_object_new_string(b->header.sec1)); json_object_array_add(noti_array, item); } free_notification(allNotifyItems); api_set_json_header(res); onion_response_write0(res, json_object_to_json_string(obj)); json_object_put(obj); free(ue); return OCS_PROCESSED; }
static int parse_mmrp(char *sz, size_t len, struct mrpdhelper_notify *n) { if (len < 9) /* protect against sscanf(&sz[8],...) runaway */ return -1; if (parse_notification(&sz[1], n) < 0) return -1; if (parse_state(&sz[5], n) < 0) return -1; n->attrib = mrpdhelper_attribtype_mvrp; if (sscanf(&sz[8], "M=%" SCNx64, &n->u.m.mac) != 1) return -1; return parse_registrar(sz, n, NULL); }
static int parse_mmrp(char *sz, size_t len, struct mrpdhelper_notify *n) { /* format MIN MJO M=112233445566 R=112233445566 len = 38 */ if (len < 38) return -1; if (parse_notification(&sz[1], n) < 0) return -1; if (parse_state(&sz[5], n) < 0) return -1; n->attrib = mrpdhelper_attribtype_mvrp; if (sscanf(&sz[8], "M=%" SCNx64, &n->u.m.mac) != 1) return -1; return parse_registrar(sz, n, NULL); }
static int parse_mvrp(char *sz, size_t len, struct mrpdhelper_notify *n) { /* format VIN VJO 1234 R=112233445566 len = 28 */ if (len < 28) return -1; if (parse_notification(&sz[1], n) < 0) return -1; if (parse_state(&sz[5], n) < 0) return -1; n->attrib = mrpdhelper_attribtype_mvrp; if (sscanf(&sz[8], "%04x ", &n->u.v.vid) != 1) return -1; return parse_registrar(sz, n, NULL); }