Update config line with the values from the params array */
| 1148 | |
| 1149 | /* Update config line with the values from the params array */ |
| 1150 | void util_parms_update(struct params_context *params, struct context *cnt, const char *cfgitm) |
| 1151 | { |
| 1152 | int indx, retcd; |
| 1153 | char newline[PATH_MAX]; |
| 1154 | char cpyline[PATH_MAX]; |
| 1155 | char fmt[15]; |
| 1156 | |
| 1157 | memset(newline,'\0', PATH_MAX); |
| 1158 | memset(cpyline,'\0', PATH_MAX); |
| 1159 | |
| 1160 | for (indx = 0; indx < params->params_count; indx++) { |
| 1161 | |
| 1162 | /* Determine format spec for newline*/ |
| 1163 | memset(fmt,'\0', 15); |
| 1164 | if (indx > 0) { |
| 1165 | memcpy(fmt,"%s,", 3); |
| 1166 | } |
| 1167 | |
| 1168 | if ((strstr(params->params_array[indx].param_name," ") == NULL) && |
| 1169 | (strstr(params->params_array[indx].param_name,",") == NULL) && |
| 1170 | (strstr(params->params_array[indx].param_name,"=") == NULL)) { |
| 1171 | memcpy(fmt + strlen(fmt),"%s", 2); |
| 1172 | } else { |
| 1173 | memcpy(fmt + strlen(fmt),"\"%s\"", 4); |
| 1174 | } |
| 1175 | |
| 1176 | if ((strstr(params->params_array[indx].param_value," ") == NULL) && |
| 1177 | (strstr(params->params_array[indx].param_value,",") == NULL) && |
| 1178 | (strstr(params->params_array[indx].param_value,"=") == NULL)) { |
| 1179 | memcpy(fmt + strlen(fmt),"=%s", 3); |
| 1180 | } else { |
| 1181 | memcpy(fmt + strlen(fmt),"=\"%s\"", 5); |
| 1182 | } |
| 1183 | |
| 1184 | /*Create the new line */ |
| 1185 | if (indx > 0) { |
| 1186 | retcd = snprintf(newline, PATH_MAX , fmt, cpyline |
| 1187 | , params->params_array[indx].param_name |
| 1188 | , params->params_array[indx].param_value); |
| 1189 | } else { |
| 1190 | retcd = snprintf(newline, PATH_MAX , fmt |
| 1191 | , params->params_array[indx].param_name |
| 1192 | , params->params_array[indx].param_value); |
| 1193 | } |
| 1194 | if ((retcd < 0) || (retcd > PATH_MAX)) { |
| 1195 | MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO,_("Error: %s"), newline); |
| 1196 | } |
| 1197 | /* Create a copy of our new line for use in next iteration of loop*/ |
| 1198 | retcd = snprintf(cpyline, PATH_MAX, "%s", newline); |
| 1199 | if ((retcd < 0) || (retcd > PATH_MAX)) { |
| 1200 | MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO,_("Error: %s"), newline); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | /* Assign finished new parameter line to the config item */ |
| 1205 | if (mystreq(cfgitm, "netcam_params")) { |
| 1206 | free(cnt->conf.netcam_params); |
| 1207 | cnt->conf.netcam_params = mymalloc(strlen(newline)+1); |
no test coverage detected