int str_to_attr( const char *name, /* I */ char *val, /* I */ pbs_attribute *attr, /* O */ struct attribute_def *padef, /* I */ int limit) /* I */ { int index; char buf[MAXLINE<<5]; char log_buf[LOCAL_LOG_BUF_SIZE]; if ((name == NULL) || (val == NULL) || (attr == NULL)) { return(-10); } index = find_attr(padef,name,limit); if (index < 0) return(ATTR_NOT_FOUND); switch (padef[index].at_type) { case ATR_TYPE_LONG: attr[index].at_val.at_long = strtol(val, NULL, 10); break; case ATR_TYPE_CHAR: attr[index].at_val.at_char = *val; break; case ATR_TYPE_STR: unescape_xml(val,buf,sizeof(buf)); attr[index].at_val.at_str = strdup(buf); if (attr[index].at_val.at_str == NULL) { log_err(PBSE_SYSTEM, __func__, "Cannot allocate memory\n"); return(PBSE_SYSTEM); } break; case ATR_TYPE_ARST: case ATR_TYPE_ACL: { int rc; unescape_xml(val,buf,sizeof(buf)); if ((rc = decode_arst(attr + index,name,NULL,buf,0))) return(rc); } break; case ATR_TYPE_SIZE: { unsigned long number; char *unit; number = strtol(val, NULL, 10); attr[index].at_val.at_size.atsv_units = ATR_SV_BYTESZ; attr[index].at_val.at_size.atsv_num = number; attr[index].at_val.at_size.atsv_shift = 0; /* the string always ends with kb,mb if it has units */ unit = val + strlen(val) - 2; if (unit < val) break; else if (isdigit(*val)) break; switch (*unit) { case 'k': attr[index].at_val.at_size.atsv_shift = 10; break; case 'm': attr[index].at_val.at_size.atsv_shift = 20; break; case 'g': attr[index].at_val.at_size.atsv_shift = 30; break; case 't': attr[index].at_val.at_size.atsv_shift = 40; break; case 'p': attr[index].at_val.at_size.atsv_shift = 50; break; } } break; case ATR_TYPE_RESC: { char *resc_parent; char *resc_child; char *resc_ptr = val; int len = strlen(resc_ptr); int rc; int errFlg = 0; while (resc_ptr - val < len) { if (get_parent_and_child(resc_ptr,&resc_parent,&resc_child, &resc_ptr)) { errFlg = TRUE; break; } if ((rc = decode_resc(&(attr[index]),name,resc_parent,resc_child,ATR_DFLAG_ACCESS))) { snprintf(log_buf,sizeof(log_buf), "Error decoding resource %s, %s = %s\n", name, resc_parent, resc_child); errFlg = TRUE; log_err(rc, __func__, log_buf); } } if (errFlg == TRUE) return(-1); } break; /* NYI */ case ATR_TYPE_LIST: case ATR_TYPE_LL: case ATR_TYPE_SHORT: case ATR_TYPE_JINFOP: break; } /* END switch (pbs_attribute type) */ attr[index].at_flags |= ATR_VFLAG_SET; return(PBSE_NONE); } /* END str_to_attr */
int str_to_attr( char *name, char *val, struct attribute *attr) { int index; char *id = "str_to_attr"; char buf[MAXLINE<<5]; if ((name == NULL) || (val == NULL) || (attr == NULL)) { log_err(-1,id,"Illegal NULL pointer argument"); return(-10); } index = find_attr(svr_attr_def,name,SRV_ATR_LAST); if (index < 0) { /* couldn't find attribute */ snprintf(log_buffer,sizeof(log_buffer), "Couldn't find attribute %s\n", name); log_err(-1,id,log_buffer); return(ATTR_NOT_FOUND); } switch (svr_attr_def[index].at_type) { case ATR_TYPE_LONG: attr[index].at_val.at_long = atol(val); break; case ATR_TYPE_CHAR: attr[index].at_val.at_char = *val; break; case ATR_TYPE_STR: unescape_xml(val,buf,sizeof(buf)); attr[index].at_val.at_str = (char *)malloc(strlen(buf)+1); if (attr[index].at_val.at_str == NULL) { log_err(PBSE_SYSTEM,id,"Cannot allocate memory\n"); return(PBSE_SYSTEM); } strcpy(attr[index].at_val.at_str,buf); break; case ATR_TYPE_ARST: case ATR_TYPE_ACL: { int rc; unescape_xml(val,buf,sizeof(buf)); if ((rc = decode_arst(attr + index,name,NULL,buf))) return(rc); } break; case ATR_TYPE_SIZE: { unsigned long number; char *unit; number = atol(val); attr[index].at_val.at_size.atsv_units = ATR_SV_BYTESZ; attr[index].at_val.at_size.atsv_num = number; attr[index].at_val.at_size.atsv_shift = 0; /* the string always ends with kb,mb if it has units */ unit = val + strlen(val) - 2; if (unit < val) break; else if (isdigit(*val)) break; switch (*unit) { case 'k': attr[index].at_val.at_size.atsv_shift = 10; break; case 'm': attr[index].at_val.at_size.atsv_shift = 20; break; case 'g': attr[index].at_val.at_size.atsv_shift = 30; break; case 't': attr[index].at_val.at_size.atsv_shift = 40; break; case 'p': attr[index].at_val.at_size.atsv_shift = 50; break; } } break; case ATR_TYPE_RESC: { char *resc_parent; char *resc_child; char *resc_ptr = val; int len = strlen(resc_ptr); int rc; int errFlg = 0; while (resc_ptr - val < len) { if (get_parent_and_child(resc_ptr,&resc_parent,&resc_child, &resc_ptr)) { errFlg = TRUE; break; } if ((rc = decode_resc(&(server.sv_attr[index]),name,resc_parent,resc_child))) { snprintf(log_buffer,sizeof(log_buffer), "Error decoding resource %s, %s = %s\n", name, resc_parent, resc_child); errFlg = TRUE; log_err(rc,id,log_buffer); } } if (errFlg == TRUE) return(-1); } break; /* NYI */ case ATR_TYPE_LIST: case ATR_TYPE_LL: case ATR_TYPE_SHORT: case ATR_TYPE_JINFOP: break; } /* END switch (attribute type) */ attr[index].at_flags |= ATR_VFLAG_SET; return(0); } /* END str_to_attr */